gpt4 book ai didi

html - 子 div 重叠,不尊重父 div 宽度

转载 作者:行者123 更新时间:2023-12-05 02:18:37 24 4
gpt4 key购买 nike

我正在为 Web 应用程序构建原型(prototype),但我遇到了 div 重叠的问题。

我有一个名为 #menu 的 div , 与 width: 15%; ,在里面,我有一个名为 #list 的子 div与 width: 100%; .

enter image description here

乍一看,似乎child div 没有遵守parent div 的限制,记得child div有position: absolute; .

关于这个主题有一些问题,但我没有找到适合我的问题。一些问题谈到申请 clear: both在所有 div 上或应用 display: inline-block; , 但没有任何效果。

如有任何帮助,我们将不胜感激。

<html>

<head>

<title> PROTOTYPE - opcion.html</title>

<style type="text/css">

body {
margin: 0;
}

#menu {
display: block;
height: 100%;
width: 15%;
background-color:#ff0000;
}

#list {
width: 100%;
top: 180px;
position: absolute;
}

ul {
background-color: aqua;
display: block;
padding: 0;
list-style: none;
}

li {
margin: auto;
width: 100%;
padding: 10px 0px 10px 10px;
border-bottom: 1px solid rgba(0,0,0,.6);
}

li a {
color: #ffffff;
font-size: 25px;
font-family: "Trebuchet MS", Helvetica, sans-serif;
text-decoration: none;
}

</style>

</head>

<body>

<div id="menu">
<div id="list">
<ul>
<li> <a href="#">Customers</a> </li>
<li> <a href="#">Students</a> </li>
<li> <a href="#">Teachers</a> </li>
<li> <a href="#">Android App</a> </li>
</ul>
</div>
</div>

</body>

</html>

最佳答案

只需添加 position:relative 到#menu。您的绝对容器将尊重具有相对位置的父属性。

了解更多职位信息 https://developer.mozilla.org/en-US/docs/Web/CSS/position https://css-tricks.com/almanac/properties/p/position/

'clear ' 仅在 float 元素时才需要。

关于html - 子 div 重叠,不尊重父 div 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44812644/

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