Forum Moderators: not2easy

Message Too Old, No Replies

first-letter problems (may be specificity)

         

Dabrowski

11:44 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok, all the links on my page are grey. The hover colour is white (the site is a black base).

I added

A:first-letter { color: white; }
and sometimes it works and sometimes not.

I only define these colours once, overriding some things, font styles mainly in some places, but no other first-letter or colours anywhere.

Now, this works in some places, but not others. The code I have relating to links in these sections...

A { color: silver; font-weight: bold; text-decoration: none; }
A:first-letter{color: white;}
A:hover { color: white; }

#topnav A {
margin-left: 20px;
font-family: "Verdana", sans-serif;
font-size: 13px;
line-height: 22px;
}

#catlist #links A {
display: block;
margin-bottom: 5px;
width: 130px; height: 20px;
font-family: "Verdana", sans-serif;
font-size: 12px; line-height: 20px;
font-variant: small-caps;
text-align: center;
}

#help A { display: block; font-size: 1.5em;}
#help .pop_in A { margin-top: 7px;font-size: 0.7em; }

It's working here:

<body>
<div id='mainwrapper'>
...<div id='catlist'>
......<div id='back'></div>
.........<div id='links'>
.........<a ...>Text</a>
.........<a ...>Text</a>

<body>
<div id='mainwrapper'>
...<div id='help' class='pagewrapper'>
......<div class='content'></div>
......<a ...>Text</a>
......<a ...>Text</a>
......<div class='pop_in'>
.........<a ...>Text</a>
.........<a ...>Text</a>

But it does not work here:

<body>
<div id='topnav'>
...<a ...>home</a>
...<a ...>home</a>

<body>
<div id='mainwrapper'>
...<div id='home' class='pagewrapper'>
......<div class='content'>
......<h1><a ...>Text</a></h1>

<body>
<div id='mainwrapper'>
...<div id='contact' class='pagewrapper'>
......<div class='content'>
......<p class='bigcaption'><a ...>Text</a></p>

Even if I add:

#topnav A:first-letter { color: white; }

My links in that section still don't have any white!
I'm very frustrated with this one. I'm assuming some elements override the first-letter selector, and some don't.

Dabrowski

12:10 am on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just tested in IE6, have to specify the hover colour all over the place too.

Robin_reala

12:31 am on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can’t see anything wrong with your code. The only two places you seem to be setting a colour are on ‘a’ and ‘a::first-letter’, so the ::first-letter should always apply. Are you sure you’re not setting other colours?

Dabrowski

11:21 am on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nope. Lets concentrate on the #topnav section. Here's the whole code for that bit:

A { color: silver; font-weight: bold; text-decoration: none; }
A:first-letter { color: white; }
A:hover { color: white; }

#topnav {
height: 22px;
background: black;
}

#topnav A {
margin-left: 20px;
font-family: "Verdana", sans-serif;
font-size: 13px;
line-height: 22px;
}
#topnav A:hover { color: white; } /* IE6 */

<div id='topnav'>
<a href='/home.shtml'>home</a>
<a href='/about.shtml'>about</a>
<a href='/shop/shop.shtml'>online shop</a>
<a href='/checkout.shtml'>checkout</a>
<a href='/help.shtml'>help</a>
<a href='/contact.shtml'>contact us</a>
</div>

I had to add the

#topnav A:hover
so IE6 would even do that.

You said 'a::first-letter', double colon? Is that what's wrong? I am setting a font colour only in 1 other place:

#mainwrapper .pagewrapper { color: white; }

If not I'll have to try to replicate it offline.

Dabrowski

3:21 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok, I have solved this, and will post the answer for the good of the populous.

The :first-letter thing only applies to block level elements. Some of my links, left have nav bar for eg, use block level <a> tags, while others (top nav bar) are just inline.

Xapti

6:25 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why only block-level?

Robin_reala

6:27 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because that’s what the spec says [w3.org]?

The :first-letter pseudo-element must select the first letter of the first line of a block

Looks like it’s designed to work on generated line boxes, not inline elements.

Fotiman

6:37 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@Robin_reala
All of your single quote's are coming through as a weird question mark in a diamond. Are you somehow pasting in some rich text that's using some font not available to everyone?

SuzyUK

6:51 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fotiman, it's possibly your browser or its default character encoding?

this has been appearing from time to time on WebmasterWorld, if there is no charset defined, which I think WebmasterWorld doesn't have, then the browser will try to choose a default and sometimes it's not the best one.

at the minute in FF, I'm not seeing the "diamonds" and it's showing as rendering with ISO-8859-1

encyclo is the master with Character encoding.. perhaps he'll come along and point us to the thread which explains this better than I can..

[edited by: SuzyUK at 6:53 pm (utc) on May 8, 2007]

Robin_reala

7:16 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh, sorry, I’m totally used to adding them with Alt+Shift+] on my Mac. If it’s causing people problems I can force myself to stop :)

sifredi

7:20 pm on May 8, 2007 (gmt 0)

10+ Year Member



regarding the :hover issue in IE, try switching the anchor pseudo-class order from:

A:first-letter { color: white; }
A:hover { color: white; }

to:

A:hover { color: white; }
A:first-letter { color: white;

and IE will get it right. Couldn't find anything about this in the specs though so I assume IE is just being picky. In any case, it makes sense right?

Robin_reala

7:24 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To be picky ::first-letter is a pseudoelement, not pseudoclass, but yeah, there doesn’t seem to be anything in the specs requiring a specific order.

(CSS3 makes it more obvious by reserving ‘:’ for pseudoclasses and ‘::’ for pseudoelements)

Fotiman

7:49 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Fotiman, it's possibly your browser or its default character encoding?

this has been appearing from time to time on WebmasterWorld, if there is no charset defined, which I think WebmasterWorld doesn't have, then the browser will try to choose a default and sometimes it's not the best one.

at the minute in FF, I'm not seeing the "diamonds" and it's showing as rendering with ISO-8859-1


I'm using FF. According to my HTML Tidy extension:

The document contains characters that do not exist to the specified charset. The document can not be checked.

This is only on the pages with those question marks.

Dabrowski

9:30 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because that’s what the spec says?

Still why? Don't inline elements have letters? And yes I read the spec page, hence my last post and saw the <p><span> example. But still why? Stupid W3C strikes again.

Robin, I'm kinda disappointed you didn't spot this the first time round!

Fotiman,
Single quotes are fine on IE7, and FF2 on WinXP. Although they are a bit drunk looking. There's no charset <meta> defined. Anyone snoop the headers?

Oh, sorry, I’m totally used to adding them with Alt+Shift+] on my Mac

Don't fruit computers come with an apostrophe key? I thought they were supposed to be advanced? ;)

Robin_reala

9:56 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, should have spotted that. It's bitten me a few times before :/ Why it only applies to block level elements I really don't know. Another one of those spec idiosyncrasies.

As for curly quotes, an apostrophe is meant to be curly :) Or at least when I was at school it was. But hey, if it's causing people problems I'll bow to popular will.

Setek

1:46 am on May 9, 2007 (gmt 0)

10+ Year Member



I believe the reasoning behind only applying
:first-letter
to block-level elements was that, in the traditional report-writing/document-writing days (which is what all the structural elements are based on,) an enlarged first-letter was only ever applied to the start of a block of text: the first letter of the first block of each chapter.

Post script: yes, apostrophes and quotation marks are meant to be curly, like filled-in 6s, 9s, 66s and 99s. What you are referring to is a prime and a double-prime, correctly used as feet and inches (5'9" = five feet, nine inches,) and abundantly incorrectly used as apostrophes and quotation marks.

There are many articles on the web if you are interested, just search for typography, and maybe more relevant to you, typography on the web.

penders

7:45 am on May 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Digressing...

@Robin_reala
All of your single quote's are coming through as a weird question mark in a diamond. Are you somehow pasting in some rich text that's using some font not available to everyone?

Those single quote's/apostrophe's look like &lsquo; and &rsquo; to me (?) - and if you display this page using a Unicode (UTF-8) character encoding you get?-marks where the characters should be(?)

Post script: yes, apostrophes and quotation marks are meant to be curly, like filled-in 6s, 9s, 66s and 99s. What you are referring to is a prime and a double-prime, correctly used as feet and inches (5'9" = five feet, nine inches,) and abundantly incorrectly used as apostrophes and quotation marks.

May be if you were to write an apostrophe it would be curly, often in print it would be curly, and indeed in other fonts (Bangle, Bart, Bimini to name but three) it IS curly, but I guess generally on screen, for the sake of clarity, it isn't in Verdana, Arial... etc. (?) Although the apostrophe is looking like the prime character in Verdana/Arial, it is an entirely different character (U+2032) and in Verdana is angled.

Dabrowski

12:19 pm on May 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe the reasoning behind only applying :first-letter to block-level elements was that, in the traditional report-writing/document-writing days (which is what all the structural elements are based on,) an enlarged first-letter was only ever applied to the start of a block of text: the first letter of the first block of each chapter.

I'm inclined to agree, however don't you think it's short sighted of them to assume that nobody would want to use them for anything else, and that they actually had to go out of their way to specify that it would only apply to block level!

Infact, the example on the official spec page is a newspaper type paragraph. They have something line:

<p><span>The first few</span>words are caps</p>

The <span> uses text-transform caps, but p:first-letter still applies to the first 'T'.

Anyway, discussions about tyopgraphy and curly apotrophies (sp?) aside, thanks for that btw Setek, quite interesting, I've fixed my problem.

I added

float: left;
to #topnav A. As I have no other content in that section, just a row of links it made no difference to layout, but did make the first-letter work.

As for having to re-specify hover for IE6, as it's consistent, I can only assume that adding a further style for A, makes it ignore any previous A:hover. It does seem to inherit A:first-letter though.

Anyone care to give this a test?

SuzyUK

10:48 am on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



tested ;)

I added float: left; to #topnav A. As I have no other content in that section, just a row of links it made no difference to layout, but did make the first-letter work.

That's because a floated element automatically becomes a block element and it works on blocks.

As for having to re-specify hover for IE6, as it's consistent, I can only assume that adding a further style for A, makes it ignore any previous A:hover. It does seem to inherit A:first-letter though.

I'd say whatever works, IT IS a Specificity problem, but the problem is IE6's only (a bug) I found some research by Ingo Chao on the matter:

The presence of the pseudo-element manipulates the specificity – debugger's horror. In general, a workaround by using !important just to bring IE6 back to order cannot be recommended, as !important itself is buggy in IE6.

so respecifying as you have done is one way, or getting more specific with the first letter rule does it too as far as I can see:

#topnav a:first-letter {color: white;}

either way giving IE6 a helpful nudge seems to be the answer ;)

Suzy

Dabrowski

11:35 am on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was aware of the result of 'float: left', that's why I put it in after I read about the block element thing.

The strange thing is that IE6 still maintains the A:first-letter, and I only have to respecify A:hover.