Home > Web Front-end > HTML Tutorial > What are the attribute values ​​of the display attribute in HTML? How does the display attribute achieve horizontal and vertical centering?

What are the attribute values ​​of the display attribute in HTML? How does the display attribute achieve horizontal and vertical centering?

寻∝梦
Release: 2018-08-15 15:01:23
Original
14463 people have browsed it

What are the attribute values ​​of the display attribute in HTML? What's the meaning? And how does the display attribute in HTML achieve horizontal and vertical centering? Today's article will introduce to you the value of the display attribute in HTML, and how to achieve horizontal and vertical centering of the value of the display attribute in HTML. Two methods are introduced.

displayHere I talk about the four most commonly used attribute values ​​​​inline, block, inlin-block, and none.

First let’s talk about inline (n inline element):

The value of this attribute is the default value. This element will be displayed as an inline element with no line breaks before or after the element. This attribute value is generally not set. From my personal understanding, it is no different from normal inline elements. Block and inline-block are more commonly used.

Then there is the attribute value of block (block-level element):

This attribute value is more interesting. It is set so that the block-level element occupies an exclusive line, as far as line breaks are concerned. The effect is the same as that of the p tag, but after this attribute value is set, as a block-level element, it has width, height, and the distance between it and other block-level elements. The margin attribute setting, and the spacing setting padding, but cannot Set line-height.

There is also the attribute value of inline-block (inline block):

This attribute value is relatively powerful. I basically saw it when I first started learning. This attribute value will be set as long as it is not line-wrapped. On the one hand, it can be used as a block-level element and can have the characteristics of a block. On the other hand, since I am a beginner, it is troublesome to set the center. All using this attribute value can Set the line height so the text is centered for ease of use.

These attributes are very useful for the implementation of this navigation bar. The two attribute values ​​​​of block and inline-block are mainly used. Inline-block is used as the implementation of several elements in the same row, and block is used as Implementation of line breaks between elements. Everyone can try it.

For the last none attribute value:

I personally think it is more convenient to hide elements. When the mouse is floating, change the display attribute value to achieve display. Effect with hidden elements.

What are the commonly used values ​​of display in HTML? Let us take a look at

Display in HTML is relatively easy to use in normal project development. The main values ​​are: