[英]Difference between HTML block elements and CSS display block property
May I know if there is any difference between HTML block elements (Eg. <p>
, <div>
,...) and CSS property display: block
? 我可以知道HTML块元素(例如<p>
, <div>
,...)和CSS属性display: block
之间是否有任何区别?
Since from what I have read they are the same, but why we still need to use display: block
for some block level element. 因为从我所看到的它们是相同的,但为什么我们仍然需要使用display: block
来获得一些块级元素。
What you call "HTML block elements" are elements who have their display property set to block
so there is no difference between a <div>
and a <span>
with display:block;
你所谓的“HTML块元素”是将其display属性设置为block
元素,因此<div>
和<span>
与display:block;
之间没有区别display:block;
. 。
This display property is set by the user agent stylesheet (ie your browser). 此显示属性由用户代理样式表(即您的浏览器)设置。 You can view these properties in chrome dev tool under "user agent stylesheet". 您可以在“用户代理样式表”下的chrome dev工具中查看这些属性。
The only reason I see of using display:block;
我看到使用display:block;
的唯一原因display:block;
for a div
element is : 对于div
元素是:
display:none;
你需要覆盖以前的CSS声明,如display:none;
There is no difference between... because block elements already have default css property display: block
. ...之间没有区别,因为块元素已经具有默认的css属性display: block
。
But we use display: block
to show them again, when we hide/remove them from page using display: none
. 但是当我们使用display: none
从页面隐藏/删除它们时,我们使用display: block
再次显示它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.