gpt4 book ai didi

html - 溢出:隐藏似乎不起作用

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

我正在创建一个响应式菜单并为此仅使用 html 和 css。

但是当我尝试向站点添加内容时,它会在菜单中启动 div。我已经尝试在整个菜单周围的 div 上使用 overflow:hidden 但由于某种原因这不起作用。

我创建了另一个菜单并在菜单周围的 div 上使用了 overflow:hidden 并且它有效但遗憾的是不能使用它,因为它没有下拉菜单。

我希望我为您提供了足够的信息来帮助我解决刚才问的其他问题!谢谢。

@font-face

{
font-family: 'Gautami';
src: url('gautami.ttf');
}
body {
padding: 0px;
margin: 0px;
}
#menu {
width: 100%;
}
/*Strip the ul of padding and list styling*/

ul {
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
}
/*Create a horizontal list with spacing*/

li {
display: inline-block;
float: left;
}
/*Style for menu links*/

li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: 'Gautami', Arial;
color: #2072ba;
text-decoration: none;
}
/*Hover state for top level links*/

.MenuLink:hover {
background: #e5e6e8;
}
/*Style for dropdown links*/

li:hover ul a {
background: #2072ba;
color: white;
height: 40px;
line-height: 40px;
border-bottom: 1px solid white;
}
/*Hover state for dropdown links*/

li:hover ul a:hover {
background: #e5e6e8;
color: #2072ba;
}
/*Hide dropdown links until they are needed*/

li ul {
display: none;
}
/*Make dropdown links vertical*/

li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/

li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
/*Display the dropdown on hover*/

ul li a:hover + .hidden,
.hidden:hover {
display: block;
}
#right {
float: right;
}
/*Style 'show menu' label button and hide it by default*/

.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #2072ba;
text-align: center;
padding: 25px 0px 25px 0px;
display: none;
width: 100%;
border-bottom: solid 1px #2072ba;
}
/*Hide checkbox*/

input[type=checkbox] {
display: none;
}
/*Show menu when invisible checkbox is checked*/

input[type=checkbox]:checked ~ #menu {
display: block;
}
.content {
background-color: grey;
bottom: 0px;
margin: 0% 10% 0% 10%;
}
/*Responsive Styles*/

@media screen and (min-width: 1201px) {
#MenuDiv {
overflow: hidden;
}
#menu {
border-bottom: 1px solid #2072ba;
}
}
@media screen and (max-width: 1200px)
/*increase your windows size to see my problem or decrease the max width and min width until your can see the large menu*/

{
#MenuLinkImg {
display: none;
}
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
padding: 0px;
overflow: hidden;
}
/*Create vertical spacing*/
li {
border-bottom: solid 1px #2072ba;
}
/*Make all menu links full width*/
ul li,
li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display: block;
}
#right {
float: none;
}
.content {
margin: 0px 5% 0% 5%;
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dropdown menu </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="DD.css">
</head>
<body>
<div id="MenuDiv">
<label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li><a class="MenuLink" href="#">Home</a></li>
<li><a class="MenuLink" href="#">Diensten</a></li>
<li><a class="MenuLink" href="#">Keurmerken</a></li>
<div id="right">
<li>
<a class="MenuLink" href="#">Mijn account ↓</a>
<ul class="hidden">
<li><a class="MenuLinkDD" href="#">Diensten</a></li>
<li><a class="MenuLinkDD" href="#">Account informatie</a></li>
</ul>
</li>
<li><a class="MenuLink" href="#">Inloggen</a></li>
</div>
</ul>
</div>
<div class="content">
<div id="text">
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestttesttest esttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttestte sttesttesttesttesttesttesttestt esttesttesttest testtesttesttesttesttesttestt esttesttest testtesttesttesttesttesttesttesttesttesttesttestte sttesttes ttesttestt esttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte sttesttestte sttesttesttesttesttesttesttesttesttesttesttesttesttest
</div>
</div>
</body>
</html>

最佳答案

你要的与overflow无关.

因为在宽度大于 1201px 的设备上,您的菜单具有 position:absolute,您正在将其从文档的正常流中移除。如果您不希望它呈现为与页面内容重叠,则需要在您的内容上设置顶部填充并将菜单放置在提供的空间中:

@media (min-width: 1201px){
body {
padding-top: 51px;
}
#menu {
top: 0;
}
}

@font-face

{
font-family: 'Gautami';
src: url('gautami.ttf');
}
body {
padding: 0px;
margin: 0px;
}
#menu {
width: 100%;
}
/*Strip the ul of padding and list styling*/

ul {
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
}
/*Create a horizontal list with spacing*/

li {
display: inline-block;
float: left;
}
/*Style for menu links*/

li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: 'Gautami', Arial;
color: #2072ba;
text-decoration: none;
}
/*Hover state for top level links*/

.MenuLink:hover {
background: #e5e6e8;
}
/*Style for dropdown links*/

li:hover ul a {
background: #2072ba;
color: white;
height: 40px;
line-height: 40px;
border-bottom: 1px solid white;
}
/*Hover state for dropdown links*/

li:hover ul a:hover {
background: #e5e6e8;
color: #2072ba;
}
/*Hide dropdown links until they are needed*/

li ul {
display: none;
}
/*Make dropdown links vertical*/

li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/

li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
/*Display the dropdown on hover*/

ul li a:hover + .hidden,
.hidden:hover {
display: block;
}
#right {
float: right;
}
/*Style 'show menu' label button and hide it by default*/

.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #2072ba;
text-align: center;
padding: 25px 0px 25px 0px;
display: none;
width: 100%;
border-bottom: solid 1px #2072ba;
}
/*Hide checkbox*/

input[type=checkbox] {
display: none;
}
/*Show menu when invisible checkbox is checked*/

input[type=checkbox]:checked ~ #menu {
display: block;
}
.content {
background-color: grey;
bottom: 0px;
margin: 0% 10% 0% 10%;
}
/*Responsive Styles*/

@media screen and (min-width: 1201px) {
#MenuDiv {
overflow: hidden;
}
#menu {
border-bottom: 1px solid #2072ba;
top: 0;
}
body {
padding-top: 51px;
}
}
@media screen and (max-width: 1200px)
/*increase your windows size to see my problem or decrease the max width and min width until your can see the large menu*/

{
#MenuLinkImg {
display: none;
}

/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
padding: 0px;
overflow: hidden;
}
/*Create vertical spacing*/
li {
border-bottom: solid 1px #2072ba;
}
/*Make all menu links full width*/
ul li,
li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display: block;
}
#right {
float: none;
}
.content {
margin: 0px 5% 0% 5%;
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dropdown menu </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="DD.css">
</head>
<body>
<div id="MenuDiv">
<label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li><a class="MenuLink" href="#">Home</a></li>
<li><a class="MenuLink" href="#">Diensten</a></li>
<li><a class="MenuLink" href="#">Keurmerken</a></li>
<div id="right">
<li>
<a class="MenuLink" href="#">Mijn account ↓</a>
<ul class="hidden">
<li><a class="MenuLinkDD" href="#">Diensten</a></li>
<li><a class="MenuLinkDD" href="#">Account informatie</a></li>
</ul>
</li>
<li><a class="MenuLink" href="#">Inloggen</a></li>
</div>
</ul>
</div>
<div class="content">
<div id="text">
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestttesttest esttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttestte sttesttesttesttesttesttesttestt esttesttesttest testtesttesttesttesttesttestt esttesttest testtesttesttesttesttesttesttesttesttesttesttestte sttesttes ttesttestt esttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte sttesttestte sttesttesttesttesttesttesttesttesttesttesttesttesttest
</div>
</div>
</body>
</html>

附带说明一下,您的 CSS 太笼统了。对于初学者,您不希望网站中的所有无序列表都具有 position:absolute

关于html - 溢出:隐藏似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41431418/

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