填充底部相对于元素的宽度吗? [英] Is padding-bottom relative to element's width?

查看:75
本文介绍了填充底部相对于元素的宽度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

填充底部必须相对于元素的宽度,但是我在最新版本的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屋!

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