gpt4 book ai didi

html - 元素不适合 CSS

转载 作者:行者123 更新时间:2023-11-28 16:08:04 25 4
gpt4 key购买 nike

所以我正在使用纯 html 和 CSS 制作一个小搜索菜单。我正在使用百分比将我的元素组合在一起,但它们似乎重叠,而在我看来,我会认为它们会很好地组合在一起。我做错了什么吗?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<link rel="stylesheet" href="normalize.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style media="screen">
body {
font-family: sans-serif;
padding: 5px
}
.search-menu {
height: 600px;
background: #00003b;
width: 500px;
border: 1px solid black;
padding: 5px
}
.search-menu-list {
height: 100%;
width: 100%;
}
.search-menu-list input {
width: 100%;
height: 30px;
font-size: 16px;
margin-bottom: 5px;
padding: 0 4px 0 4px;
}
.search-menu-list ul {
list-style: none;
margin: 0; border: 0; padding: 0;
overflow: hidden;
overflow-y: scroll;
background: white;
width: 100%; height: 100%;
border: 1px solid black;
}
.search-menu-list li {
padding: 10px 5px 10px 5px;
margin: -1px -1px 0 -1px;
border-top: 1px solid black;
-ms-user-select: none;
cursor: default;
}
.search-menu-list li:hover {
background: #f2f2f2;
}
</style>
</head>
<body>
<div class="search-menu">
<div class="search-menu-list">
<input placeholder="Start typing to search...">
<ul>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
</ul>
<div>
</div>
</body>
</html>

最佳答案

这里的罪魁祸首是 padding.search-menu-list input 上:

.search-menu-list input {
padding: 0 4px 0 4px;
}

通过用另一个 <div class="input-wrap"> 包装它可以更好地制作这种方式并提供以下样式:

.search-menu-list .input-wrap {
padding: 0 4px 0 4px;
}

.search-menu-list .input-wrap input {
padding: 0;
}

对于 height工作不正常,您已经为容器使用了固定高度( 600px ),并且您给出了 height: 100%到列表中。所以给:

.search-menu-list {
height: 550px;
width: 100%;
}

将来,添加这个有效:

* {box-sizing: border-box;}

这主要是因为加入了width: 100% , borderpadding在一起。

你有<div> , 应该是 </div> , 就在最后 </div> .

是因为盒子模型。检查输出:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<link rel="stylesheet" href="normalize.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style media="screen">
* {box-sizing: border-box;}
body {
font-family: sans-serif;
padding: 5px
}
.search-menu {
height: 600px;
background: #00003b;
width: 500px;
border: 1px solid black;
padding: 5px
}
.search-menu-list {
height: 550px;
width: 100%;
}
.search-menu-list input {
width: 100%;
height: 30px;
font-size: 16px;
margin-bottom: 5px;
padding: 0 4px 0 4px;
}
.search-menu-list ul {
list-style: none;
margin: 0; border: 0; padding: 0;
overflow: hidden;
overflow-y: scroll;
background: white;
width: 100%; height: 100%;
border: 1px solid black;
}
.search-menu-list li {
padding: 10px 5px 10px 5px;
margin: -1px -1px 0 -1px;
border-top: 1px solid black;
-ms-user-select: none;
cursor: default;
}
.search-menu-list li:hover {
background: #f2f2f2;
}
</style>
</head>
<body>
<div class="search-menu">
<div class="search-menu-list">
<input placeholder="Start typing to search...">
<ul>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
<li>This is a test list item</li>
</ul>
</div>
</div>
</body>
</html>

预览

fiddle :http://output.jsbin.com/wimeqazusi

关于html - 元素不适合 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36061212/

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