I've seen answers suggesting using first child pseudo selector using the following formats:
/* Type */
P:first-child {
margin:0px;
}
/* Class */
.myClass:first-child {
margin:0px;
}
/* ID */
#myDiv:first-child {
margin:0px;
}
In my case I'm selecting by ID. I've seen only a few using an ID. In my code I can't get it to work unless I put a space in between the ID and pseudo-class like so:
#myDiv :first-child {
margin:0px;
}
Is this correct?
Here is the code I'm working with:
<div id="richText59">
<UL>
<LI>
<FONT FACE="Verdana" COLOR="#000000" LETTERSPACING="0" KERNING="1" style="font-size:12px">Bullet List</FONT>
</LI>
</UL>
</div>
<div id="RichText808">
<P ALIGN="left">
<FONT FACE="Verdana" COLOR="#000000" LETTERSPACING="0" KERNING="1" style="font-size:12px">
<B>
<I>Rich Text</I>
</B>
</FONT>
</P>
<P ALIGN="left">
<FONT FACE="Verdana" COLOR="#000000" LETTERSPACING="0" KERNING="1" style="font-size:12px">
<B>
<I>paragraph two</I>
</B>
</FONT>
</P>
</div>
CSS:
#RichText808 {
position:absolute;
top:107px;
left:35px;
width:240px;
display:inline-block;
height:166px;
display:inline-block;
margin-top:-0.2em;
margin-top:0;
}
#richText59 {
position:absolute;
top:107px;
left:335px;
width:240px;
display:inline-block;
height:166px;
display:inline-block;
margin-top:-0.2em;
}
In the HTML markup above, the contents of the div
will change. I don't control the contents. The problem is that the content of the div is pushed down by around 10px.
By using the first-child selector I am able to remove the margin that pushes the content down. So yes, I do have the ID of the container element but no control over the contents of that element.