固定元素的百分比宽度? [英] Percentage width for fixed elements?

查看:101
本文介绍了固定元素的百分比宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的html:

<div id='content'>
    <div id='first'>...</div>
    <div id='second'>...</div>
</div>

#content
{
    width:100%;
    position:relative;
    padding:20px;
}

#first
{
    width:70%;
    position:relative;
}

#second
{
    width:70%;
    position:fixed;
}

这会导致第二个div有点宽比第一个div,因为第一个div的70%是相对于内容的宽度(这是100%减去每边20px的填充)。

this causes the second div to be a bit wider (40px to be exact) than the first div, because the first div's 70% is with respect to the content's width (which is 100% minus the padding of 20px on each side).

什么是第二个div的70%是指?

What does the second div's 70% refer to? How could I make it so that the two divs are the same width?

推荐答案

我设置了一个绝对宽度使用javascript来检测计算宽度#first。

I set an absolute width using javascript to detect the computed width of #first.

这篇关于固定元素的百分比宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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