我用带有两个超链接的position:fixed头创建了一个简单的标记。接下来,我希望这个div动态匹配页面内容的宽度。
这里的问题是页面内容的尺寸是由以像素为单位设置的主体元素的填充来控制的。
下面是描述情况的小提琴:http://jsfiddle.net/jn7z1wke/2/
谷歌表示,固定元素的宽度可以按百分比动态控制(就像小提琴width: 95%;中显示的那样),但这并不能解决我的问题--我需要以像素为单位动态调整固定div的宽度。
我非常清楚如何在JS/JQuery上做到这一点,但最终我想在普通的CSS上做到这一点。
发布于 2014-08-31 19:47:58
发布于 2014-08-31 19:51:30
将padding: 0px 2.5%;设置为body - 演示
.fixedheader{
position: fixed;
background: none repeat scroll red;
width: 95%; /* this has to be changed and match the width of the .content on window resize */
}
.content{
background: none repeat scroll 0% 0% #A0A2A7;
padding-top: 20px;
}
body
{
margin: 0;
padding: 0 2.5%;
background: none repeat scroll 0% 0% #C2BAC1;
}https://stackoverflow.com/questions/25595644
复制相似问题