How to set the span tag to a fixed width in CSS

Source: Internet
Author: User

one, the shape such as <span>ABC</span> independent line set span to fixed width method as follows:

span {width:60px; text-align:center; display:block;}

Actual verification results: IE6 OK, FIREFOX 3 OK.

one, such as <SPAN>ABC</SPAN>DEF format line set span to fixed width method is as follows:

span {width:60px; text-align:center; Display:block; Float:left;}

Actual verification results: IE6 OK, FIREFOX 3 OK.

two, shape as Abc<span>def</span>gh format line to set span to fixed width method is as follows:

span {width:60px; text-align:center; Display:inline-block;}

Actual verification results: IE6 OK, FIREFOX 3 OK.

Tip: The perfect compatibility is to set the display property to Inline-block, which is compatible with the first two cases.

the difference between Block,inline,inline-block:

display:block;--attributes such as the width and height margin of a div tag can be customized;

display:inline;--features that are not customizable for the wide and advanced properties of <a>, <strong> tags;

display:inline-block;--"All" customizable attribute element characteristics;

Add:

1, how to let the BBB in <li>AAA<span>BBB</span></li> in the right alignment and do not change line.

A: If you use the Float property with span, it always causes the span to wrap to the next line. You can use the following method to achieve your peers and right-aligned.

Li {position:relative;}

Li span{position:absolute;right:0px;}

can be achieved.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.