Web Hosting Talk







View Full Version : Help with CSS please!


ilyash
02-06-2008, 08:01 PM
So in my css file I specify how a <p> should be aligned

but if i have smthg else (a table or a div) inside the p.. like:

<p>
BLAH 1
<table><tr><td>MEH</td></tr></table>

<div>
MEH 2
</div>
BLAH 2
</p>





The BLAH's will look fine, but the MEH's will not be properly aligned

(at least in FF)

SwiftModders
02-06-2008, 08:34 PM
Hello ilyash,

So you mean that you are having alignment with objects located inside a p tag? Well, for one you cannot have any block-level elements inside a p, so that is not going to work, I suggest putting the tables into a div OUTSIDE of the p for starters if you want valid xHTML. But you can always specify alignment for code in tables, divs, and p...for example:

<table border="0" cellspacing="0" cellpadding="3"><tr><td align="left">Hello</td></tr></table>

Here you can change align to be left, center, or right.

<div align="center">Hello</div>

Once again, you can use left, center, or right here to specify text alignment.

<p align="right">Hello again!</p>

Same scenario...

Also, you can't have a div inside a p...:)

ilyash
02-06-2008, 08:46 PM
well the alignment is a little more complicated than that

theres padding and a whole bunch of other stuff... I specify it in the main css file...

So what changes would i need in my css file?

Thanks again

SwiftModders
02-06-2008, 09:38 PM
ilyash,

So you have CSS attributes, alright here is an example of doing multiple alignments in one DIV (not p as that is not valid xHTML):

#main {
width: 600px;
padding: 10px;
margin: 0 auto;
text-align: center;
}
p.right {
padding: 5px;
margin: 0;
text-align: right;
}
table.left td {
width: 450px;
padding: 3px;
margin: 0 auto;
text-align: left;
}

So that's some made up CSS I put together real quick, for this xHTML code:

<div id="main">This text is going to be centered!<br /><br /><p class="right">This text is going to right align.</p><br /><br /><table class="left" border="0" cellpadding="0" cellspacing="0"><tr><td>This text will be left aligned.</td></tr></table></div>

Hopefully this gives a little more visual interpretation of what needs to be done. Maybe this isn't as complex as you have it, but post your code if you want something more direct and I will try to help :).

ilyash
02-07-2008, 02:59 AM
So there's no way to have the stuff for the p extend to the tables and divs inside of it?

Because I have the same code repeating in multiple spots, but with different formatting and I wanted them to be formatted along with the <p> they are in

Theres no way to say like

p.table.td ? or something like that?

BurakUeda
02-07-2008, 03:48 AM
So there's no way to have the stuff for the p extend to the tables and divs inside of it?

Because I have the same code repeating in multiple spots, but with different formatting and I wanted them to be formatted along with the <p> they are in

Theres no way to say like

p.table.td ? or something like that?
There is this:

p table tr td { text-align:center }
But this way, all the cells in tables wrapped in <p> tags will be centered in whole document.

If you have different formats for each tables, you have to define them individually by giving them ID, or attach them a class definition:

<style type="text/css">
#table1 tr td { text-align:center }
#table2 tr td { text-align:right }
</style>

<p>
<table id="table1">
<tr><td> FOO </td><tr>
</table>
</p>

<p>
<table id="table2">
<tr><td> BAR </td><tr>
</table>
</p>

ilyash
02-07-2008, 03:55 AM
how about if my p is in a div?

so like right now I have


<div class="master_body">
<p>
BLAH
<table>...</table>
</p>
</div>


so my css says:
#master_body p {
margin: 0px 0px 0px 15px;
padding:7px 0px 7px 0px; }

so how can I extend that for all tables inside that div [and p?]


should i close the p before the table and reopen?

like

<div>
<p>
</p>
<table>
</table>
</p>
</div>


?

thanks hope that made my problem more clear

BurakUeda
02-07-2008, 04:17 AM
You can extend styles in a specific class by just putting tags:
.master_body p // styles for <p> inside the master_body div
.master_body p table // styles for table inside <p>
.master_body p table tr // styles for rows of the table
.master_body p table tr td // styles for cells of the table
These will effect only element inside the master_body div.

SwiftModders
02-07-2008, 09:52 AM
Like I said ilyash, you cannot have block-level elements inside a <p> tag. It's not proper HTML, you COULD do it, but why would you ever need to? :/