CSS Display

本文深入探讨了HTML元素的隐藏方法及其对页面布局的影响,包括使用display属性和visibility属性的区别,并展示了如何通过display属性改变元素的显示方式,如使元素成为行内元素、块级元素或行内块级元素。此外,文章还介绍了table元素的collapse属性,以及其在表格布局中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Display and Visibility

Hiding an element

两种方法实现元素的隐藏:

h1.hidden {display:none;}
h2.hidden {visibility:hidden;}

区别:

display:none it will not take up any space. The element will be hidden, and the page will be displayed as if the element is not there:

visibility:hidden It will still take up the same space as before. The element will be hidden, but still affect the layout.

前者就好像元素不在那个地方,后者仍然占据着相同的空间,影响页面布局。

Change the way an element displayed

li {display:inline;}
span {display:block;}
div {display:inline-block;}

三个语句分别实现:
1. 使块级元素占满一行宽度显示,直到不得不换行。
2. 使行内级元素强制换行。
3. 使元素成为一个行内级别的封装块级元素的容器。The inside of this block is formatted as block-level box, and the element itself is formatted as an inline-level box


注意:Setting the display property of an element only changes how the element is displayed, NOT what kind of element it is. So, an inline element with display:block is not allowed to have other block elements inside of it.

设置一个元素的display性质,只是改变了元素显示的方式,而不会改变元素的类型。因此,一个 display: block 的行内级元素不允许在它里面放置其他块级元素。


Table Collapse

tr.collapse {visibility:collapse;}

Only for table elements. collapse removes a row or column, but it does not affect the table layout. 

该性质删除了表格里的行或列,但不影响表格的布局。

The space taken up by the row or column will be available for other content.

If collapse is used on other elements, it renders as "hidden"


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值