gpt4 book ai didi

css - float 右侧的 Div 导致水平滚动

转载 作者:太空宇宙 更新时间:2023-11-04 14:16:52 24 4
gpt4 key购买 nike

我有一个 float 到左侧的 div,里面有一个菜单,另一个 div 向右浮动,它填充了剩余的空间,问题是,右侧的 div 设置为 100%,但是正在关闭页面右侧并创建不需要的滚动。我认为原因是我在其上设置了左边距以允许左侧 float div。有没有办法让右边的 div 填充其余空间而不创建水平滚动,但这样我也可以将内容左对齐:0px 靠在 float 的边缘。
我已将该页面放到我的其他域之一上,这样您就可以看到:
http://aspiresupportandhousing.com/cleanserve/

HTML:

<body>
<div id="lp_bt">
<div id="logo_container_s">
</div>
<div id="menu_container_s">
<nav id="secondary_nav">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Our Services</a></li>
<li><a href="#">Cleaning</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
<div id="left_panel">
<div id="logo_container">
</div>
<div id="menu_container">
<nav id="primary_nav">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Our Services</a></li>
<li><a href="#">Cleaning</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
<div id="right_panel">
<div id="main_container">
<div id="title">
</div>
</div>
</div>
</body>

CSS:

html {
height: 100%;
min-width: 1000px;
}

* {
margin: 0px;
padding: 0px;
}

body {
height: 100%;
min-width: 1000px;
color: #000000;
}

/* Hidden */
#lb_bt {
height: 30px;
width: 30px;
left: 30px;
}

#logo_container_s {
left: -150px;
width: 150px;
height: 42px;
position: absolute;
background: url(logo.jpg);
z-index: 3000;
}

#menu_container_s {
left: -150px;
height: 400px;
width: 150px;
position: absolute;
z-index: 3000;
}
/* End Hidden */

/* Left Panel */
#left_panel {
height: 100%;
width: 150px;
float: left;
background-color: #26609E;
z-index: 2000;
}

#logo_container {
width: 150px;
height: 42px;
left: 0px;
top: 0px;
position: relative;
background: url(logo.jpg);
z-index: 3000;
}

#menu_container {
height: 400px;
width: 150px;
top: 0px;
left: 0px;
position: relative;
}

ul {
list-style: none;
text-align: left;
border-top: solid 1px #002954;
}

ul li {
display: list-item;
}

ul li a:link, ul li a:visited {
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
font-weight: normal;
width: 800;
color: #FFFFFF;
line-height: 38px;
margin: 0px 10px;
padding: 0px 5px 8px 0px;
text-align: left;
text-decoration: none;
}

ul li a:hover, ul li a:active {
color: #2593C1;
}

@media only screen and (min-width: 280px) and (max-width: 800px) {
body {
background: none rgba(161, 220, 254, 0.4);
}

#left_panel {
left: -150px;
position: absolute;
}

#lp_bt {
top: 0px;
left: 0px;
background: url(menu.jpg);
width: 30px;
height: 30px;
}

#lp_bt:hover {
width: 150px;
height: 100%;
background: none #26609E;
}

#lp_bt:hover #secondary_nav {
display: list-item;
}

#lp_bt:hover #logo_container_s {
left: 0px;
top: 0px;
position: relative;
}

#lp_bt:hover #menu_container_s {
top: 0px;
left: 0px;
position: relative;
}
}
/* End Left Panel */

/* Right Panel */
#right_panel {
height: 100%;
width: 100%;
margin-left: 150px;
background: url(bg.jpg) no-repeat top left fixed;
background-size: cover;
position: absolute;
z-index: 1;
}

#main_container {
width: 700px;
height: 50%;
margin-left: auto;
margin-right: auto;
margin-top: auto;
background: rgba(255, 255, 255, 0.8);
border-radius: 30px 30px 30px 30px;
}

#title {
width: 600px;
height: 104px;
margin-left: auto;
margin-right: auto;
top: 30px;
background: url(title.png) no-repeat center center;
position: relative;
}

@media only screen and (min-width: 280px) and (max-width: 800px) {
#right_panel {
background: none;
}
}

最佳答案

你的 Scroll 是因为你有一个 margin-left 给你的

#right_panel

您有三种解决方案,包括对 #right_panel

的 CSS 进行一些更改
  • 一个使用方法calc()设置宽度:

    #right_panel {
    width: calc( 100% - 150px);
    }
  • 两个更改您的 z-index 值并删除 margin-left:

    #right_panel {
    width:100%;
    margin-left:0;
    z-index:-1;
    }
  • 三个使用 box-sizingpadding 而不是 margin:

    #right_panel {
    box-sizing:border-box;
    padding-left:150px;
    width:100%;
    margin:0;
    }

关于css - float 右侧的 Div 导致水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20288132/

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