Mode 0

Hi,

Is it possible to use a css attribute as a selector?

something like this?

div[style.color="blue]>span {font-weight:bold}

I am trying to align a table inside a div depending on the alignment of the div. If the text-align in the div is set to be center then center the table etc. Can be done only using css? That is without using align=center in the div?

I would appreciate any help.

Thank you

3 answers

0
points
This was chosen as the best answer

wouldn't you just change the rule for the table then?

e.g.

div.quoted table{margin: 10px 0; width: 80%;}

you probably need to set up different sets of rules for both div and table and choose them by setting the class on the div

e.g.

div.quoted-center{ text-align:center;}
div.quoted-center table{margin: 10px auto; width: 80%;}

div.quoted-right{ text-align:right;}
div.quoted-right table{margin: 10px 0; width: 80%; float: right; display:inline;}

div.quoted-left{ text-align:left;}
div.quoted-left table{margin: 10px 0; width: 80%; float: left; display:inline;}

and then just set the class on the div appropriately.

Answered almost 8 years ago by Tony Crockford
  • Thanks Tony. I think this is the best way too. Mode almost 8 years ago
0
points

How are you setting the text-align on the div? I'll assume a class on the div?

if so all you need to do is use the Cascade part of CSS:

if the class you're using to set text-align center is

<div class="quoted">centered text <table>etc</table></div>

and your css looks like:

div.quoted{ text-align:center;}

then you just add:

div.quoted table{margin: 10px auto; width: 80%;}

and any tables inside a div with that class will be 80% of the divs width and centered

(in good browsers)

of course I may have misunderstood the question completely!

Answered almost 8 years ago by Tony Crockford
Mode 0
0
points

Hi Tony,

Thanks for the comment. That worked partly. I would like the table inside the div to align left right or center depending on the text-align value in the css rule for the div.

So from your example if I set the text-align to "left" for div.quoted, I would like the table inside to be aligned left as well.

Thanks

Answered almost 8 years ago by Mode