Home Web Front-end CSS Tutorial Detailed explanation of display attribute of css layout

Detailed explanation of display attribute of css layout

Nov 03, 2018 am 11:21 AM
css layout display

This article brings you a detailed explanation of the display attribute of css layout, so that you can understand the impact of the display attribute on css layout. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

We need to know that display is the most important attribute in CSS used to control layout. Each element has a default display value, which is related to the element's type. Their default values ​​are usually block or inline for most elements. A block element is usually called a block-level element. An inline element is usually called an inline element. [For more css video learning, please visit: css tutorial]

Let’s take a look at the impact of different display attribute values ​​​​on css control layout.

css block attribute value

The block element will be displayed as a block-level element with line breaks before and after the element.

Features:

1. Each block-level element starts on a new line, and subsequent elements also start on a new line. (Really overbearing, a block-level element occupies one row)

2. The height, width, line height, and top and bottom margins of the element can be set.

3. If the width of an element is not set, it is 100% of its parent container (the same as the width of the parent element), unless a width is set.

Example: div element

<div>div 是一个标准的块级元素。一个块级元素会新开始一行并且尽可能撑满容器。其他常用的块级元素包括 p 、 form 和HTML5中的新元素: header 、 footer 、 section 等等。</div>
<div>div 是一个标准的块级元素。一个块级元素会新开始一行并且尽可能撑满容器。其他常用的块级元素包括 p 、 form 和HTML5中的新元素: header 、 footer 、 section 等等。</div>
Copy after login

Rendering:

Detailed explanation of display attribute of css layout

##css inline attribute value

Inline elements will be displayed as inline elements, with no line breaks before and after the element. An inline element can wrap text within a paragraph without disrupting the paragraph's layout.

Features:

1. All elements are on the same line as other elements;

2. The height, width, top and bottom margins of the element cannot be set;

3. The width of an element is the width of the text or image it contains and cannot be changed.

Example: span is a standard inline element. The a element is the most commonly used inline element and can be used as a link.

<div>测试文字,<span style="background-color: palegreen;">被span元素包围,设置span的背景颜色</span>,<a href="#">a链接</a></div>
Copy after login

Rendering:


Detailed explanation of display attribute of css layout

##css none attribute value Another commonly used display value for css elements is none. This is the default display value of some special elements, such as script. display:none is commonly used by JavaScript to hide or show an element without removing it. (None can also be used together with block. Use display:none to hide elements, and use display:block to display hidden elements; for example: secondary navigation menu)

It is different from the visibility attribute. An element with display set to none will not take up the space it should be displayed, but with visibility: hidden; it will still take up space.


Other display attribute values ​​​​of css


There are many more interesting display values, such as inline-block and flex. We will discuss these two attribute values ​​​​in subsequent articles.

Conversion of display valuesAs discussed before, every element has a default display value. But you can rewrite it anytime, anywhere! Although it may seem confusing to "artificially create" an inline element, you can change an element with specific semantics into an inline element. A common example is: changing the default block value of the li element to an inline value to create a horizontal menu. And the conversion method is also very simple, use the statement:

display: inline;
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning. If you want to learn more about css, we recommend video learning:

css tutorial

!

The above is the detailed content of Detailed explanation of display attribute of css layout. 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)

Fujifilm X-M5 price expectations rise as leaked selfie display adds complexity to the formerly affordable camera line Fujifilm X-M5 price expectations rise as leaked selfie display adds complexity to the formerly affordable camera line Sep 07, 2024 am 09:34 AM

Fujifilm fans were recently very excited at the prospect of the X-T50, since it presented a relaunch of the budget-oriented Fujifilm X-T30 II that had become quite popular in the sub-$1,000 APS-C category. Unfortunately, as the Fujifilm X-T50's launc

Apple Studio Display's power cord is detachable, but requires special tools Apple Studio Display's power cord is detachable, but requires special tools May 17, 2023 pm 03:05 PM

Apple Studio Display is now officially available in stores, and many customers around the world have purchased the product. Unlike the ProDisplayXDR, the StudioDisplay has a unique power connector that appears to be non-removable. It turns out that the cable is removable, but you'll need a special tool to remove it. Apple says on its website that the Studio Display's power cord is not detachable -- and many users think so. That's because removing the cable with your hands seems impossible, but luckily the cable can be detached from the monitor. , Apple has a special tool for extracting information from its new StudioDispl

Comparison: Apple Studio Display vs Samsung Smart Monitor M8 Comparison: Apple Studio Display vs Samsung Smart Monitor M8 May 11, 2023 pm 10:46 PM

Samsung Smart Display M8 vs. Apple Studio Display: Design and Size Since its launch, the Apple Studio Display has been compared to the iMac, consisting of a relatively thin panel on a relatively simple L-shaped stand. It's a well-known and well-loved aesthetic, and Samsung seems to have borrowed it for its presentation. The Samsung SmartMonitor M8 uses the same idea of ​​a thin screen on a stand that looks very similar. Some minor elements are different, such as the small section in the lower left corner that sticks out a bit and the Samsung's chin is very thin, but they seem to be close in terms of basic design. Samsung seems to have taken a lot of inspiration from the 24-inch iMac. Apple's display is smaller than Samsung's

Boot Camp updated to support Apple Studio Display Boot Camp updated to support Apple Studio Display May 20, 2023 pm 11:34 PM

IntelMac users running Windows on a Mac can now update their drivers in BootCamp to support Apple's StudioDisplay. Apple regularly updates BootCamp to introduce support for new hardware, as well as typical compatibility and performance improvements. In the March software update, Apple has enabled BootCamp to work with the new StudioDisplay. The update that brings BootCamp to version 6.1.17 introduces two key support elements. First, it adds compatibility with StudioDisplay, ensuring

Samsung: New, large display based on E Ink technology displays colors and communicates wirelessly Samsung: New, large display based on E Ink technology displays colors and communicates wirelessly Jun 19, 2024 pm 03:37 PM

We frequently report on devices based on displays with electronic ink, such as e-readers. The technology offers a number of advantages: it can be read in bright environments without a backlight, and it only requires power when switching without light

Questions frequently asked by front-end interviewers Questions frequently asked by front-end interviewers Mar 19, 2024 pm 02:24 PM

In front-end development interviews, common questions cover a wide range of topics, including HTML/CSS basics, JavaScript basics, frameworks and libraries, project experience, algorithms and data structures, performance optimization, cross-domain requests, front-end engineering, design patterns, and new technologies and trends. . Interviewer questions are designed to assess the candidate's technical skills, project experience, and understanding of industry trends. Therefore, candidates should be fully prepared in these areas to demonstrate their abilities and expertise.

display what does it mean display what does it mean Oct 26, 2023 am 11:50 AM

Display usually refers to the operation or function of displaying data, information or results to the user in some way or outputting it to a screen or other device. Specific meaning: 1. In the command line interface (CLI), display may refer to outputting data in text, tables or other formats to the terminal window for users to view or analyze; 2. In the graphical user interface (GUI), Display may refer to displaying images, text, charts and other content on the application window or interface for user interaction or browsing, etc.

What values ​​does display have? What values ​​does display have? Nov 20, 2023 pm 05:28 PM

The values ​​of display include block, inline, none, inline-block, flex, grid, table, inline-table and list-item. Detailed introduction: 1. block, which renders elements into block-level elements. Block-level elements form a block on the page and occupy one line alone; 2. inline, which renders elements into inline elements. Inline elements will not occupy a line by themselves and can be side by side with other elements; 3. none, this value specifies that the element will not be on the page, etc.

See all articles