Log in

View Full Version : p and table



d-machine
03-13-2010, 08:57 AM
HTML:


<p id="sab">
Hello!
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>
</p>


CSS:


p#sab{background: #ff0;}
#sab table{background: #000; width:450px;}


Why does'nt the CSS affect on the table?

Thanks!

traq
03-13-2010, 03:02 PM
because tables are stupid - they don't follow the rules the same way everyone else does. Try giving it its own id
#sabtable{ background: #000; width: 450px; }

stringcugu
03-13-2010, 10:24 PM
<style>
p#sab{background: #ff0;}
#sab table{background: #000; width:450px;}
#gg{background: red;}
#hh{background:silver;}
#gg1{background:green;}
#hh1{background:blue;}
#gg2{background:yellow;}
#hh2{background:pink;}
</style><p id="sab">
Hello!
<table>
<tr>
<td id=gg>1</td>
<td id=hh>2</td>
</tr><tr>
<td id=gg1>1</td>

<td id=hh1>2</td>
</tr><tr>
<td id=gg2>1</td>
<td id=hh2>2</td>
</tr>
</table>
</p>

simcomedia
03-14-2010, 03:58 AM
First off, you shouldn't put a table inside of a paragraph tag. Secondly, style the table specifically. You can't style the <p> tag and expect everything in it to be that way. Switch to a <div> tag and style the items inside of it like this:

#sab p {
background-color: #ff0;
}

#sab th {
blah bblah;
}

#sab tr {
blah blah;
}

Then wrap it all up:

<div id="sab">
<p>Here's some text about the table below</p>
<table>
<tr><td></td>
</tr>
</table>
</div>