gpt4 book ai didi

html - 如果一个区域卡在包含 block 之外,如何防止滚动条?

转载 作者:太空宇宙 更新时间:2023-11-04 05:08:11 25 4
gpt4 key购买 nike

我必须编写标记和 CSS,以便背景图像不会产生滚动条。仅当视口(viewport)比内部内容包装器更窄时,才会创建滚动条:

http://www.mcm.unisg.ch/

对我不起作用:Absolutely positioned div on right causing scrollbar when the left doesn't

在固定布局中可能徒劳的尝试之一:

#background {
width: auto;
margin-left: -75px;
margin-right: -75px;
}

向左滚动无法到达左侧包含 block 之外的区域(由于负边距)。是的!但是负 margin-right 在窄视口(viewport)的情况。只要 View 部分比包含 block 宽,我怎样才能阻止滚动条?

标记:

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title>&nbsp;</title>
<link rel="stylesheet" type="text/css" href="css/general.css" media="screen, projection"/>
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="css/general-ie.css" media="screen"/>
<![endif]-->
</head>
<body>

<div id="page">
<img id="background" src="images/visual.jpg" alt="" />
<div id="head"><h1>Page title</h1></div><!-- /#head -->
<div id="mainpart">
<ul id="zones">
<li>
<ul>
<li class="module">Modul #1</li><!-- /#module -->
</ul>
</li>
</ul><!-- /#zones -->
<hr />
</div><!-- /#mainpart -->
<div id="foot"><h1>Footer</h1></div><!-- /#foot -->
</div><!-- /#page -->

</body>
</html>

CSS 规则:

body {
background: #000;
color: #000;
}
#page, #mainpart {
background: #fff;
}

#page {
width: 1024px;
margin: 0 auto;
position: relative;
}

#background {
position: absolute;
top: 0;
left: 0;
z-index: -1;
width: auto;
margin-left: -75px;
margin-right: -75px;
}

谁能给我一些好的建议?谢谢。

最佳答案

要防止出现滚动条,请使用:

mySelector
{
overflow: hidden;
}

您可以在这里看到它的所有荣耀:jsFiddle example .

关于html - 如果一个区域卡在包含 block 之外,如何防止滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9941029/

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