search
HomeWeb Front-endCSS TutorialHow to use display in css
How to use display in cssNov 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>//行级元素

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>

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>

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>

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
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
比较:Apple Studio Display vs Samsung Smart Monitor M8比较:Apple Studio Display vs Samsung Smart Monitor M8May 11, 2023 pm 10:46 PM

三星智能显示器M8与AppleStudio显示器:设计和尺寸自推出以来,AppleStudioDisplay就被比作iMac,由相对简单的L形支架上的相对薄的面板组成。这是一种众所周知且深受喜爱的美学,三星似乎借用了它的展示。三星SmartMonitorM8采用了与外观非常相似的支架上的薄屏幕的相同想法。一些次要元素有所不同,例如左下角的小部分有点突出,三星的下巴很薄,但它们在基本设计方面似乎很接近。三星似乎从24英寸iMac中获得了很多灵感。苹果的显示器比三星的要小

Apple Studio Display 的电源线是可拆卸的,但需要特殊工具Apple Studio Display 的电源线是可拆卸的,但需要特殊工具May 17, 2023 pm 03:05 PM

AppleStudioDisplay现已在商店正式发售,全球已有多家客户购买了该产品。与ProDisplayXDR不同,StudioDisplay有一个独特的电源连接器,似乎是不可拆卸的。事实证明,电缆是可拆卸的,但您需要使用特殊工具才能将其卸下。苹果在其网站上表示,StudioDisplay的电源线是不可拆卸的——而且很多用户都这么认为。那是因为用你的双手移除电缆似乎是不可能的,但幸运的是,电缆可以从显示器上分离。,Apple有一个特殊的工具,用于从其新的StudioDispl

对比:Apple Studio Display vs LG UltraFine 5K Display 哪个好?对比:Apple Studio Display vs LG UltraFine 5K Display 哪个好?Apr 16, 2023 pm 08:25 PM

StudioDisplay和LGUltraFine5KDisplay在市场上占有相似的位置,但苹果的显示器要贵300美元。以下是您需要了解的有关这些显示器如何比较的所有信息。六年在科技领域是一段很长的时间,而这也是苹果出售一款价格不超过5,000美元的品牌显示器以来的时间。在此期间,Apple与LG合作销售专门迎合Mac用户的LGUltraFine系列。2019年,Apple停止销售这些LG显示器,转而支持ProDisplayXDR,这在价格适中的Mac友好显

display是什么意思display是什么意思Oct 26, 2023 am 11:50 AM

display通常指的是将数据、信息或结果以某种方式展示给用户或输出到屏幕或其他设备上的操作或功能。具体含义:1、在命令行界面(CLI)中,display可能指的是将文本、表格或其他格式的数据输出到终端窗口,供用户查看或分析;2、在图形用户界面(GUI)中,display可能指的是将图像、文本、图表等内容显示在应用程序的窗口或界面上,以供用户交互或浏览等等。

Boot Camp 更新以支持 Apple Studio DisplayBoot Camp 更新以支持 Apple Studio DisplayMay 20, 2023 pm 11:34 PM

在Mac上运行Windows的IntelMac用户现在可以更新BootCamp中的驱动程序,以支持Apple的StudioDisplay。Apple会定期更新BootCamp,以引入对新硬件的支持,以及典型的兼容性和性能改进。在3月份的软件更新中,Apple已启用BootCamp以与新的StudioDisplay配合使用。将BootCamp带到6.1.17版的更新引入了两个关键支持元素。首先,它增加了对StudioDisplay的兼容性,确

display有哪些取值display有哪些取值Nov 20, 2023 pm 05:28 PM

display的取值有block、inline、none、inline-block、flex、grid、table、inline-table和list-item等。详细介绍:1、block,将元素渲染为块级元素,块级元素在页面上形成一个块,并且独占一行;2、inline,将元素渲染为内联元素。内联元素不会独占一行,可以与其他元素并排;3、none,此值指定元素不会在页面上等等。

Apple Studio Display 适用于 Windows,但有一些限制Apple Studio Display 适用于 Windows,但有一些限制Apr 14, 2023 pm 03:49 PM

Apple本周发布了StudioDisplay,它采用27英寸5K面板,结合了摄像头、麦克风和扬声器,当用户将显示器连接到Mac时,它们可以协同工作。窗户呢?如果出于某种原因您需要在WindowsPC上使用Apple的1599美元显示器,您可以,但有一些限制。当通过Thunderbolt连接(并非每台PC都支持)插入WindowsPC时,StudioDisplay被识别为常规显示器。也就是说,如果您购买了其中一个以将其与Windows一起使用,则需要记

Google Pixel 8 display problems: Repair program enables 3 years of free serviceGoogle Pixel 8 display problems: Repair program enables 3 years of free serviceJun 15, 2024 pm 06:50 PM

SincethelaunchoftheGooglePixel8(approx.513eurosatAmazon,limited-timedeal),therehavebeenanincreasingnumberofreportsfromuserscomplainingaboutaverticallineonthedisplay.Thiscanmanifestitselfindifferentways-thecolorand

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment