简体   繁体   中英

What should I use instead of “align” attribute

I'm studying asp.net mvc 3 (using Razor). One of my *.cshtml views has the following code:

<p align="center">
    <input class="actionButtons" type="submit" value="Complete order" />
</p>

The VS2010 C# compiler shows me a " XHTML1.0 Transitional " check message (not an error, not a warning), saying that align attribute is supposed to be deprecated, and a new construction is recommended.

What is that construction?

I think it means "text-align:center" . Or other way is style="margin-left:auto; margin-right:auto;"

You need to switch using CSS rules (if you want to position text in the center inside of the p)

<p style="text-align: center">

But if you want to position p element itself in the center, its need to be width constrained and margins set to auto:

<p style="width: 50%; margin-left:auto; margin-right:auto;">

More on horizontal aligning here .

Basically, the answer to your question is that the "new" way of aligning things in CSS, whether it be text or other elements, is using Cascading Style Sheets (CSS).

You should take a look at this article: Align content with CSS , which explains different techniques for aligning content with CSS and provides links to detailed explanations too.

In HTML4 and above align attribute of p tag has been deprectaed. You should use

<p style="text-align:center">
    <input class="actionButtons" type="submit" value="Complete order" />
</p>

Some other tags and attributes have been deprecated. You can read about them here

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