Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css] 第95天 当一个元素被设置为浮动后,它的display值变为什么呢? #959

Open
haizhilin2013 opened this issue Jul 19, 2019 · 4 comments
Labels
css css

Comments

@haizhilin2013
Copy link
Collaborator

第95天 当一个元素被设置为浮动后,它的display值变为什么呢?

@haizhilin2013 haizhilin2013 added the css css label Jul 19, 2019
@l8888888
Copy link

l8888888 commented Jul 20, 2019

凡是position:absolute或float:left/right,浏览器自动把元素转化为inline-block;

@xiekailian
Copy link

一个元素被设为绝对定位或者浮动后,其display计算值就变为了block,尽管其表现形式和inline-block类似——包裹内部元素且不超出包含块的特性。按照如下方式在控制台尝试可验证:
var span = document.createElement('span');
document.body.appendChild(span);
console.log('1.' + window.getComputedStyle(span).display);
span.style.float = 'left';
console.log('2.' + window.getComputedStyle(span).display);
输出:
1.inline
2.block

@Konata9
Copy link

Konata9 commented Aug 20, 2019

div 本身 displayblock 的元素在 float 后,disaplay 仍然为 block
span 本身 displayinline 的元素在 float 后,display 也为 block

可以使用 window.getgetComputedStyle 方法来获取元素的样式。
CodePen 地址:https://codepen.io/Konata9/pen/NWKRway

@hou499
Copy link

hou499 commented Sep 17, 2020

[css] 第52天 要是position跟display、overflow、float这些特性相互叠加后会怎么样? #203

如果这个元素本身没有设置display,那么的确是如前面答案所说,但是如果元素原本已经设置了display,那就不一定是block

https://codepen.io/hou499/pen/ZEWMoxq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css css
Projects
None yet
Development

No branches or pull requests

5 participants