如何获取边框属性以填充具有n个填充的div的100%宽度

问题描述 投票:0回答:1

我将父div填充为25px。在该div中,我创建了另一个带边框顶部的li标记,宽度为100%,但没有填满父div。它在25px的填充处停止。

尝试过边框,但也可以使用。

The Issue

当我将li元素的宽度更改为115%width 115%

* {
  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>

Required Output

html css
1个回答
0
投票

这是填充的正常行为。您可以从父元素中删除填充,然后将其添加到子元素中:

* {
  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>
© www.soinside.com 2019 - 2024. All rights reserved.