Anzeo Posted February 12, 2008 Share Posted February 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/90656-first-child-selector-problem/ Share on other sites More sharing options...
joannaFloyd Posted February 12, 2008 Share Posted February 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/90656-first-child-selector-problem/#findComment-465068 Share on other sites More sharing options...
Anzeo Posted February 12, 2008 Author Share Posted February 12, 2008 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; } Quote Link to comment https://forums.phpfreaks.com/topic/90656-first-child-selector-problem/#findComment-465168 Share on other sites More sharing options...
Anzeo Posted February 13, 2008 Author Share Posted February 13, 2008 Hmm I can make it work, putting the img tag in the first paragraph, behind the first letter... looks ugly (code) though Quote Link to comment https://forums.phpfreaks.com/topic/90656-first-child-selector-problem/#findComment-465721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.