我将父div填充为25px。在该div中,我创建了另一个带边框顶部的li标记,宽度为100%,但没有填满父div。它在25px的填充处停止。
尝试过边框,但也可以使用。
* {
padding: 0;
margin: 0;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 0;
margin: 0;
overflow: hidden;
font-family: Helvetica;
}
.dark {
background-color: #17202A;
}
section {
background-color: #1C2733;
width: 500px;
height: 300px;
border-radius: 25px;
padding: 20px;
color: white;
}
h1 {
font-size: 23px;
font-weight: 800;
letter-spacing: -0.2px;
}
ul {
margin-top: 20px;
width: 100%;
}
li {
padding-top: 10px;
padding-bottom: 10px;
align-items: center;
list-style: none;
height: 50px;
border-top: 1px solid white;
width: 115%;
margin: auto;
}
<section>
<h1>Who to follow</h1>
<ul>
<li>dsdfd</li>
<li>sdfsdf</li>
<li>sdfsdf</li>
</ul>
</section>
这是填充的正常行为。您可以从父元素中删除填充,然后将其添加到子元素中:
* {
padding: 0;
margin: 0;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 0;
margin: 0;
overflow: hidden;
font-family: Helvetica;
}
.dark {
background-color: #17202A;
}
section {
background-color: #1C2733;
width: 500px;
height: 300px;
border-radius: 25px;
padding: 0;
color: white;
}
h1 {
font-size: 23px;
font-weight: 800;
padding: 20px 20px 0;
letter-spacing: -0.2px;
}
ul {
margin-top: 20px;
width: 100%;
}
li {
padding: 10px 20px;
align-items: center;
list-style: none;
height: 50px;
border-top: 1px solid white;
width: 100%;
margin: auto;
}
<section>
<h1>Who to follow</h1>
<ul>
<li>dsdfd</li>
<li>sdfsdf</li>
<li>sdfsdf</li>
</ul>
</section>