在块元素上添加position:absolute是否会使它的行为像内联吗? [英] Does adding a position: absolute to a block element make it behave like an inline?

查看:199
本文介绍了在块元素上添加position:absolute是否会使它的行为像内联吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参考- https://jsfiddle.net/6nyh5p40/

position: absolute;

在div上,它的行为类似于内联元素.删除该属性,我们将看到div的行为像它应该的那样,是一个块元素.

On the div is making it behave like an inline element. Remove the property and we see that the div behaves like it should, a block element.

我的问题-仅向块元素添加位置:绝对值会使它的行为像内联吗?

My question - Does just adding a position: absolute to a block element make it behave like an inline?

推荐答案

是的,当绝对放置元素时,具有父元素内容区域的整个宽度的块元素功能将不被采用.

Yes, the block element feature of having the full width of the parent's content area will not be honored when an element is absolutely positioned.

如果要保留块元素的宽度(容器的100%),则将postion: relative;添加到绝对元素的父元素,然后将绝对元素的宽度设置为100%.

If you want to retain the width (100% of the container) of a block element, then add postion: relative; to the parent of the absolute element, then set the width of the absolute element to 100%.

这篇关于在块元素上添加position:absolute是否会使它的行为像内联吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆