填充底部相对于元素的宽度吗? [英] Is padding-bottom relative to element's width?
问题描述
填充底部必须相对于元素的宽度,但是我在最新版本的Chrome和Firefox中进行了测试,填充底部相对于父元素的宽度.
Padding-bottom must be relative to element's width but i tested in last version of Chrome and Firefox and padding-bottom is relative to parent's width.
我需要一个相对于元素宽度的元素,但它不起作用:
I need a element relative to element's width but it doesn't work:
width: 200px;
padding-bottom: 50%; /* must be 100px */
height: 0;
请参阅示例: http://dabblet.com/gist/6898263
我该怎么办?
推荐答案
否,在 padding
属性,百分比相对于包含块,这里可能是body
元素或未设置宽度的div
元素,因此它占用了可用宽度.
No, in the padding
properties, percentages are relative to the width of the containing block, which is here probably the body
element or a div
element with no width set, so it occupies the available width.
如果将元素包装在div
容器中并在容器上设置所需的宽度,则可以按预期使用百分比.
If you wrap the element in a div
container and set the desired width on the container, then you can use a percentage as intended.
这篇关于填充底部相对于元素的宽度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!