Jump to content

First-child selector problem


Anzeo

Recommended Posts

Hey all,

 

 

 

I'm currently working on a website completely made out of div's (so no more tables) and I want to add some extra's too ofcourse. The thing is is, I want the first paragraph to be bold (or another style etc.). It works fine like this:

...
<div class="site pagecontainer">
<p>Lorem ipsum dolor sit amet</p>

<p>Curabitur diam. Ves...

 

But it dosn't when I add an image before the first <p> as follows:

...
<div class="site pagecontainer">
<img src="http://www.veer.com/images/merch/VPR0001210_P3.jpg" />
<p>Lorem ipsum dolor sit amet</p>

<p>Curabitur diam. Ves...

 

Does anyone know why it's not "working" anymore when I add the image?

 

 

 

TIA,

Anzeo

Link to comment
Share on other sites

I'd be more helpful if you post the CSS code... ;)

Anyway, I suppose you used the pseudo-class :first-child, like

1) div p:first-child

or

2) div > p:first-child

 

In general, the rule

p:first-child

selects the <p> that is a first child (of some element). So if you put <img> or any other tags before your <p> (at the same heiracy level), <p> is not first child anymore.

See specs http://www.w3.org/TR/CSS21/selector.html#first-child; there's an example that fits your case.

 

Be careful that the two line I wrote are different:

1) div p:first-child

select the <p> that is a first child (of some element) and descendant of any <div>.

2) div > p:first-child

select the <p> that is a first child (of some element) and child (=decendant of first "generation") of any <div>; i.e. the <p> written immediately after any <div>.

 

I suggest to simply use a class for your first paragraphs.

Hope it helps.

 

joanna

Link to comment
Share on other sites

Thanks for the help, but it dosn't seem to be working, I also thought about the class, but before using a class I want to find out if it's possible using only CSS.

 

CSS is as follows:

 

div.pagecontainer p:first-child:first-letter
{
font-weight:bold;
color:#FFFFFF;
font-size:100px;
padding:5px;
float:left;
} 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.