gpt4 book ai didi

jquery - 100% 宽度,固定边距

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:09 26 4
gpt4 key购买 nike

http://jsbin.com/manez/1/

#container {
position:absolute;
top:0;
left:0;
width: 100%;
margin-left: 50px;
background: black;
color:white;
}
#sidebar {
width: 50px;
position: absolute;
top: 0;
left: 0;
background: blue;
color: white;
}

我希望 DIV 的宽度为 width:100%,但左边距为 50px,但不要将 div 推到另一端 50px 并启用水平滚动。

我知道这可以使用 jQuery 实现:

$('#container').width( $(window).width() - 50 );

但如果可能的话,我寻求的是纯 CSS 解决方案。

最佳答案

如果两个 div 都是绝对的,那么不要使用宽度。在容器 div 上使用 left:50px & right:0。 Div 相应地获得宽度。

关于jquery - 100% 宽度,固定边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23335672/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com