Home Web Front-end CSS Tutorial What does the display attribute in css do?

What does the display attribute in css do?

Nov 13, 2020 am 09:41 AM
css display

The display attribute in css is used to specify the type of box that the element should generate. The display attribute is a commonly used attribute in front-end development. Commonly used attribute values ​​include block, none, inline, and inline-block.

What does the display attribute in css do?

#Every element on the web page is a rectangular box. The display attribute specifies the type of box the element should generate. The display attribute is an attribute we often use in front-end development.

(Learning video recommendation: css video tutorial)

Introduction to common attribute values:

block The default value of the block object. Add a new line after the object with this value

none to hide the object. Unlike the hidden value of the visibility attribute, it does not retain its physical space for the hidden object

inline The default value of the inline object. Use this value to remove the line

inline-block inline block element from the object. This attribute value combines the characteristics of inline and block, that is, it is both an inline element and can set width and height.

1. display:block

1. block: The element will be displayed as a block-level element, with line breaks before and after the element. It is usually used to convert inline elements into block-level elements. use. So what are block-level elements? What are inline elements?

2. Block-level elements:

are always displayed in the form of a block, occupying an entire line. Several sibling block elements will be arranged from top to bottom (except when using the float attribute).

You can set the height, width, outer patch (margin) in each direction, and inner patch (padding) in each direction.

When the element width (width) is not set, its width is 100% of its container, unless we set a fixed width for it.

Block-level elements can be nested within other block-level elements or inline elements.

The display attribute value of block-level elements defaults to block.

3. Inline elements

It will not occupy a whole line alone, but only occupy the space where its own width and height are. That is, the width and height of the element are determined by its text. Open the content. Several sibling inline elements will be arranged from left to right (that is, an inline element can be on the same line as other inline elements), and from top to bottom.

The height and width of inline elements cannot be set. The height is generally determined by the size of its font, and its width is controlled by the length of the content.

Inline elements can only set left and right margin values ​​and left and right padding values, but cannot set upper and lower margin values ​​and upper and lower padding values. Therefore, we can change the width of inline elements by setting the left and right padding values.

Inline elements generally cannot contain block-level elements.

The display attribute value of block-level elements defaults to inline.

2. display:none

The value of display:none indicates that the element is not displayed. When you want an element to be hidden, you can set this attribute for an element and it will disappear from the web page. However, the element is not deleted from the document. It is just hidden in the web page structure and not displayed on the web page. But if you want the element to be displayed, you can set display:block to the element, and the element can be displayed on the web page.

3. display:inline

The function of display:inline can convert a block-level element into an inline element. Then this block-level element will no longer be able to set the width, height, and up and down margins. and padding. The actual width and height of this block-level element are auto, not the values ​​we set.

4. display:inline-block

Judging from the name, we can get that it combines inline and block and retains their characteristics. Therefore, the element with the inline-block attribute set not only has the feature that the block element can set the width and height attributes, but also maintains the feature that the inline element does not wrap.

Related recommendations: CSS tutorial

The above is the detailed content of What does the display attribute in css do?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

See all articles