在下面的代码中,当页面大小减小时,右侧的元素堆叠在左侧的元素上。我使用了overflow:scroll属性,但似乎不起作用。如何在页面中添加滚动条?
#login-link,
#signup-link {
color: white;
margin-right: 10px;
align-self: center;
}
#top-level-container {
margin-left: 10px;
margin-right: 10px;
}
.three-row-grid-container {
display: grid;
grid-template-rows: [nav-row-start]auto [nav-row-end logo-nav-row-start] auto [logo-nav-row-end content-row-start] auto [content-row-end];
}
.logo-nav-grid-container {
display: grid;
grid-template-columns: 50fr 50fr;
}
.nav-style {
height: 5vh;
/*make nav div take 5% of space of viewport*/
background-color: #222426;
}
.logo-nav-style {
height: 20vh;
/*make logo-nav div take 20% of space of viewport*/
/*background-color:#BCBBBB;*/
}
.nav-flexbox-container {
display: flex;
flex-direction: row-reverse;
align-items: center;
}
.generic-flexbox-container {
display: flex;
align-items: center;
}
.logo-nav-left-flexbox-container {
display: flex;
align-items: flex-end;
}
.logo-nav-right-flexbox-container {
display: flex;
align-items: flex-end;
flex-direction: row-reverse;
}
#logo-nav-left {
grid-column: 1/2;
}
#logo-nav-right {
grid-column: 2/3;
}
.content-style {
height: 75vh;
/*make content div take 75% of space of viewport*/
background-color: white;
margin-top: 50px;
}
.selected-button {
background-color: #F48024;
/* Orange */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-left: 10px;
}
.unselected-button {
background-color: #BCBBBB;
/* gray */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-left: 10px;
}
#nav {
grid-row: nav-row-start/nav-row-end;
margin: 0px;
}
#logo-nav {
grid-row: logo-nav-row-start/logo-nav-row-end;
margin: 0px;
}
#content {
grid-row: body-row-start/body-row-end;
margin: 50px;
}
#profile-pic {
margin: 5px;
}
#mail-icon-pic {
margin: 5px;
}
#stats-icon-pic {
margin: 5px;
}
#logo-image {
/*the max width and max height rule will make the image fit inside the div. If the image is bigger than div, the image will
contract, if the image is smaller than the div, the image will expand*/
max-width: 100%;
max-height: 100%;
}
#welcome-header {
color: gray;
}
a {
text-decoration: none;
}
#about-header-div,
#how-works-header-div {
background-color: #BCBBBB;
}
#about-header,
#how-works-header {
color: white;
/*background-color:#BCBBBB;
height:50px;
margin:0px;*/
}
body {
margin: 0px;
overflow: scroll;
}<!DOCTYPE html>
<html>
<head>
<!-- add list of tags here in meta data -->
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" type="text/css" href="index.css">
<title>some title</title>
</head>
<body>
<div id="top-level-container" class="three-row-grid-container">
<div id="nav" class="nav-style nav-flexbox-container">
<!--a href="javascript:void(0)"> <img id="stats-icon-pic" src="stats_icon.png"></a>
<a href="javascript:void(0)"><img id="mail-icon-pic" src="mail_icon.png"> </a>
<a href="javascript:void(0)"><img id="profile-pic" src="example_profile_pic.png"> </a-->
<span><a id="login-link" href="javascript:void(0)">Login</a></span>
<span><a id="signup-link" href="javascript:void(0)">Sign Up</a></span>
</div>
<div id="logo-nav-div" class="logo-nav-style logo-nav-grid-container">
<div id="logo-nav-left" class="logo-nav-left-flexbox-container">
<img id="logo-image" src="example_logo.png">
<button type="button" class="selected-button">ABCDE</button>
<button type="button" class="unselected-button">PQRS</button>
<button type="button" class="unselected-button">Profile</button>
</div>
<div id="logo-nav-right" class="logo-nav-right-flexbox-container">
<button type="button" class="unselected-button">PQRS NEW</button>
</div>
</div>
<div id="content" class="content-style">
some content
</div>
</div>
</body>
</html>
由isherwood复制
我想我要做的就是让页面不响应。由于我使用的是css-grid和flexbox,它们似乎在默认情况下会使页面响应。我想使用它们,因为它们对布局有很大的帮助。

发布于 2020-01-09 02:40:53
你应该使用一个容器,并为overflow:scroll放入所有的overs div,因为你不能在body tag中使用它。你也可以在你的css中使用html {overflow:auto;}。
发布于 2020-01-09 02:47:27
您可以对body css进行一些更改,如下所示。
body { margin: 0px; overflow-x: scroll; min-width:556px; width:100%; }最小宽度,您可以根据需要进行定义。
发布于 2020-01-09 14:43:03
我想我要做的就是让页面不响应。由于我使用的是css-grid和flexbox,它们似乎在默认情况下使页面具有响应性。我想使用它们,因为它们对布局有很大的帮助。我将整个代码封装在div中,并给出了1300px的正文宽度,这似乎起到了作用。我很乐意接受其他答案。
<div id="non-responsive-div">
<div id="top-level-container" class="three-row-grid-container">
...
</div>
</div>css
body{
width:1300px;
}https://stackoverflow.com/questions/59651857
复制相似问题