开发者

For text-align:right; in TD, why does "style" work and "class" not?

开发者 https://www.devze.com 2022-12-29 00:43 出处:网络
If I include this in a table cell: <td style=\"text-align: right; font-style: italic; color: maroon;\">开发者_如何学编程...

If I include this in a table cell:

<td style="text-align: right; font-style: italic; color: maroon;">开发者_如何学编程...

the contents of the cell are aligned as I expect.

If I include the following CSS:

.right-notice { text-align: right; font-style: italic; color: maroon; }

and this cell:

<td class=".right-notice">...

the contents of the cell are not right aligned.

Why is this? What don't I know?

If I change the CSS to replace text-align with float, that works.

Thanks.


You have a class selector that matches right-align but your class name is .right-align

While it is possible to match a class name that includes a . character, it would make more sense to change the name of the class.

While you are at it you should change the class name to describe meaning instead of presentation.


change <td class=".right-notice"> to <td class="right-notice"> (there mustn't be a dot).


Yes, it's right aligned regardless if you set the style using the style attribute or a class name. I tried your code (with the correction of the class name in the tag), and the text is right aligned just fine.

If you have a page where it doesn't work, you have to look for the reason somewhere else. Make sure that the style sheet is actually working. Look for other settings in the style sheet that may override the class, either because they have higher specificity or because they have the same specificity and comes later in the style sheet.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号