简体   繁体   中英

Text alignment - CSS or HTML?

I'm wondering what's the best way to do an alignement ?

Using CSS with the property : text-align or using HTML with align=""

Thanks !

http://www.w3.org/TR/html4/present/graphics.html表示甚至不建议使用align。

I'm of the opinion to do everything for design/layout in CSS. Keep your HTML for structure and let your design stay in the CSS. Both do the same thing but the CSS approach is neater (in my opinion anyway).

As mentioned by Marnix, it's deprecated in HTML4. It's not even supported in HTML5 so if you're structuring your HTML that way, you only have one choice.


As a rule for things I do:

Design: : Keep everything in external CSS files

Client Side Scripts : Keep everything in external JavaScript files

Content/Structure : This is what the HTML is for (I suppose we have to leave something in there)

CSS should be the way you do it really. Using inline styles usually creates more work for you in the long run.

giving it a class and specifying it in the css as text-align: right for instance is the best way according to me. With align="" you know the obvious problem of repeating....hope this helps

Use CSS if you will have several elements of a same kind in your page. Then give them a class and build a rule for that class.

CSS is there for helping you factoring your rules and avoiding assigning a style manually to every single element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM