Home Web Front-end CSS Tutorial How to use display in css

How to use display in css

Nov 17, 2018 pm 03:46 PM
display

Display commonly used attribute values ​​are block-level block, row-level inline, row-block-level inline-block, none, and row-level or block-level labels can be converted through display

This article will share the display attribute in CSS, which has certain reference value. I hope it will be helpful to everyone

We usually use the values ​​​​block, none, inline, and inline in the display attribute when making CSS layouts. -block So today we will learn how to use them

display attribute

The display attribute can have multiple values, but the commonly used ones are as follows

none: This element will not be displayed.

block: This element will be displayed as a block-level element, with line breaks before and after this element.

inline: This element will be displayed as an inline element, with no line breaks before and after the element.

inline-block: Inline block element, which has both block-level attributes and row-level attributes.

So in this article, I will introduce in detail block, inline, inline-block and none, these commonly used attribute values

display: block

Features: Occupies one line by itself, the width and height can be changed through CSS

Commonly used block-level elements: div, p, ul, li, ol, form, address

display :inline

Features: The content determines the size, and the width and height cannot be changed through CSS

Commonly used row-level elements: span, strong, em, a, del

<style>
	div{
		background-color: pink;
	}
	span{
		background-color: yellow;
	}
	</style>
</head>
<body>		
	<div>123</div>//块级元素
 <p><span class="span">hello</span>world</p>//行级元素
Copy after login

As shown in the picture above, you can see that the block element occupies the full width of the line. If you think of it as width:100%, the following content should start with a new line.

And the row-level element only displays its own part. The content does not occupy a row

Rendering

Image 13.jpg

Row block-level element conversion

(1) Convert block-level elements to row-level elements

Set display: inline for block-level elements

The result is like this

Image 15.jpg

(2) Row level Convert elements to block level

Set display:block for row-level elements

The result is as follows

Image 16.jpg

display:inline-block

Common inline block elements: img, input

Features: The content determines the size, and the width and height can be changed

<style>
	span{
		background-color: yellow;
		display:inline-block;//设置行块级元素
		width:100px;
		height:30px;
	}
	</style>
</head>
<body>		
 <p><span class="span">hello</span>world</p>
Copy after login

Rendering

Image 17.jpg

The difference between display: none and visibility: hidden

display: none is used to hide elements, which is not only invisible but also takes up no space. Size

visibility: hidden can also be used to hide elements, but they still exist even if they are not visible, leaving an empty space

Example

display:none

 .span{
   background-color: aquamarine;
  display:none;}
	</style>
</head>
<body>		
 <p><span class="span">hello</span>world</p>
Copy after login

Rendering

Image 12.jpg

hello is hidden but does not leave any space

visibility: hidden

<style>
 .span{
  background-color: pink;
   visibility: hidden;}
</style>
</head>
<body>
 <p><span class="span">hello</span>world</p>
Copy after login

Effect Picture

Image 11.jpg

hello is hidden but still has a vacant position

Summary: The above is the entire content of this article. I hope it will be useful for everyone to learn display. help


The above is the detailed content of How to use display in css. 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

Comparison: Apple Studio Display vs LG UltraFine 5K Display: Which one is better? Comparison: Apple Studio Display vs LG UltraFine 5K Display: Which one is better? Apr 16, 2023 pm 08:25 PM

StudioDisplay and LG UltraFine5KDisplay occupy similar positions in the market, but Apple's monitor is $300 more expensive. Here's everything you need to know about how these monitors compare. Six years is a long time in the tech world, and it's also the time since Apple has sold a branded monitor that costs less than $5,000. During this time, Apple partnered with LG to sell the LG UltraFine series, which catered specifically to Mac users. In 2019, Apple stopped selling these LG monitors in favor of ProDisplayXDR, an affordable Mac-friendly display

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

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