CSS text alignment implementation code

CSS text alignment implementation code

When making forms, we often encounter the situation of aligning two fields, such as name, mobile phone number, and place of birth. In this way, we need to use text-align and text-justify styles.

Just set text-align to justify. The situation of text-justify is complicated, and some people may not be familiar with it. The values ​​of IE are as follows:

  • auto : Allows the browser user agent to determine the justification to use
  • inter-word : Justify text by adding spaces between words. This behavior is the fastest way to align all lines of text. Its justification behavior does not work on the last line of a paragraph.
  • newspaper : Justify text by increasing or decreasing the space between words or letters. Is the most precise format for justifying the Latin alphabet
  • distribute : handles spaces like newspaper
  • distribute-all-lines: Justifies lines in the same way as distribute, but also excludes the last line of two aligned paragraphs. Applicable to ideographic documents
  • inter-ideograph : Provides full justification for ideographic text. He increases or decreases the space between ideograms and words

But it was originally implemented as a private feature of IE, like text-overflow, overflow-x, etc., and was not implemented until very late in FF. In other words, there are strict compatibility issues. In addition, FF and Chrome require manual insertion of spaces or soft line breaks between Chinese characters for this to take effect, and the resistance encountered in Chrome is even greater. p>

plan:

.test1 {
          text-align:justify;
          text-justify:distribute-all-lines;/*ie6-8*/
          text-align-last:justify;/* ie9*/
          -moz-text-align-last:justify;/*ff*/
          -webkit-text-align-last:justify;/*chrome 20+*/
      }
      @media screen and (-webkit-min-device-pixel-ratio:0){/* chrome*/
          .test1:after{
              content:".";
              display: inline-block;
              width:100%;
              overflow:hidden;
              height:0;
          }
      }

Run the code:

<!DOCTYPE HTML>
    <html>
        <head>
            <title>Text Alignment</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <style>
                .box1{
                    background:red;
                    width:30%;
                }
                .test1 {
                    text-align:justify;
                    text-justify:distribute-all-lines;/*ie6-8*/
                    text-align-last:justify;/* ie9*/
                    -moz-text-align-last:justify;/*ff*/
                    -webkit-text-align-last:justify;/*chrome 20+*/
                }
                @media screen and (-webkit-min-device-pixel-ratio:0){/* chrome*/
                    .test1:after{
                        content:".";
                        display: inline-block;
                        width:100%;
                        overflow:hidden;
                        height:0;
                    }
                }
            </style>
        </head>
        <body>
            <div class="box1">
                <div class="test1">Name</div>
                <div class="test1">Name Name</div>
                <div class="test1">Name</div>
                <div class="test1">Location</div>
                <div class="test1">Workplace</div>
            </div>
        </body>
    </html>

Summarize

The above is the implementation code of CSS text alignment introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Disable IE Image Toolbar

>>:  How to install OpenSuse on virtualbox

Recommend

How to use squid to build a proxy server for http and https

When we introduced nginx, we also used nginx to s...

About MySQL 8.0.13 zip package installation method

MySQL 8.0.13 has a data folder by default. This f...

The meaning and calculation method of QPS and TPS of MySQL database

When doing DB benchmark testing, qps and tps are ...

JS deep and shallow copy details

Table of contents 1. What does shallow copy mean?...

VPS builds offline download server (post-network disk era)

motivation Due to learning needs, I purchased a v...

MySQL 5.7 installation and configuration tutorial under CentOS7 64 bit

Installation environment: CentOS7 64-bit MINI ver...

js implements single click to modify the table

Pure js implements a single-click editable table ...

Graphic tutorial on configuring nginx file server in windows 10 system

Download the Windows version of Nginx from the Ng...

Discussion on the Issues of Image Button Submission and Form Repeated Submission

In many cases, in order to beautify the form, the ...

HTML scroll bar textarea attribute setting

1. Overflow content overflow settings (set whether...

How to implement the King of Glory matching personnel loading page with CSS3

Those who have played King of Glory should be fam...

mysql5.7.21.zip installation tutorial

The detailed installation process of mysql5.7.21 ...

What are the attributes of the JSscript tag

What are the attributes of the JS script tag: cha...