开发者

Text alignment in html

how to align text to right or left without using paragraph tag in HTML

Is there any oth开发者_如何学运维er tag to do alignment?


You can use any block level element (div for instance) (or force a inline element to behave like a block element with display: block). Then style that element with the appropriate CSS styles.


Any block container with style="text-align: left" will do.


Any block tag will do the job as long as you have its style attribute set to style="text-align:left"; or respectively style="text-align:right";

Think about putting this in a stylesheet instead of inline like this.

Lots of people still don't realise that HTML is meant to be semantic and not control how elements are displayed - thats a job for CSS.

Hence your statement:

Is there any other tag to do alignment?

Is technically incorrect.


Use CSS to align the text in any (block-level) element. Specifically, you want the text-align property.


If you surround the text with a <div> tag, you can give the <div> an attribute, for example style="text-align:left" or style="text-align:right to position your text.

Example:

<div style="text-align:left">
    Your text comes here...
</div>

You can read a little more about the text-align, but also the style attribute here: https://www.w3schools.com/html/html_styles.asp


Use <span class="right">Text here</span> in your html and add this .right{text-align:right} to your css

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜