CSS implements a single line of text justification for an example

Source: Internet
Author: User
In our daily web front-end development, will often encounter single-line text implementation of the two-way alignment, not only to align, but also compatible with all browsers, then how to achieve two-pronged CSS? Today, we will introduce you to the following CSS implementation of single-line text justification of the example!

p{    text-align:justify;    Text-align-last:justify;}

The above two lines of code are very familiar to everyone, for multi-line text, the basic can be compatible with all the browser, to achieve the justification. In multiline text, the style is not processed for the last paragraph of text.

So for single-line Chinese text , we need to patch

p:after{    Display:inline-block;    Content: ";    Overflow:hidden;    width:100%;    height:0;}

We used the after selector to add content at the end of a single line of text, but this would cause p to be stretched, so we also need to set the height, the complete code is as follows:

p{    text-align:justify;    text-align-last:justify;    height:24px;} p:after{    Display:inline-block;    Content: ";    Overflow:hidden;    width:100%;    height:0;}

This approach is compatible with all major viewers, at least I'm not having a bad time. For a browser that does not support the after selector, use the selectivize script, referring to one of my other blogs

<style>p{    text-align:justify;    text-align-last:justify;    height:24px;    font-size:20px;    width:500px;} p:after{    Display:inline-block;    Content: ";    Overflow:hidden;    width:100%;    height:0;} </style><p> text should have a space, or no use </P>

Summarize:

This article uses the example in detail for you to introduce the CSS implementation of the text at both ends of the example, I believe that the small partners have a further understanding of this, I hope that your work has helped! ~

Related recommendations:

CSS3 to achieve two-aligned graphical code sharing in the

Example of how CSS styles implement paragraph text justification

How CSS implements justification for both ends

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.