html - 创建备用列表元素

标签 html css list

我正在尝试创建如下图所示的列表样式 enter image description here

我尝试添加边框,但它会影响整个结构。

.styled-list {
  list-style: none;
  max-width: 200px;
  padding: 0;
  margin: 0;
}

.styled-list li {
  position: relative;
  padding-left: 10px;
}
.styled-list li:before {
  border-radius: 100%;
  position: absolute;
  content: '';
  height: 5px;
  width: 5px;
  top: 6px;
  left: 0;
}
.styled-list li:nth-child(even) {
  padding-right: 10px;
  text-align: right;
  padding-left: 0;
}
.styled-list li:nth-child(even):before {
  left: auto;
  right: 0;
}
<ul class="styled-list">
  <li>List Item 1</li>
  <li>List Item 2</li>
  <li>List Item 3</li>
  <li>List Item 4</li>
  <li>List Item 5</li>
  <li>List Item 6</li>
  <li>List Item 7</li>
  <li>List Item 8</li>
</ul>

如何将我的列表更改为显示的图像。

最佳答案

通过一些:after伪类,可以做到:

请注意,它需要一些小的调整...

* { margin: 0; padding: 0; box-sizing: border-box; }
.styled-list {
  font-size: 1em;
  list-style: none;
  width: 500px;
  border: 1px solid red;
  position: relative;
}

.styled-list li {
  width: 40%;
  min-height: 3em;
  line-height: 1em;
  border: 1px solid grey;
  padding: 1em;
  position: relative;
  margin-bottom: 1em;
}
/* move the odd items(expept the first) to the right */
.styled-list li:nth-child(2n+3) {
  margin-left: 60%;
}
/* move the first item (head) to the center */
.styled-list li:first-child {
  margin-left: 30%;
  margin-right: 30%;
}
/* create the lines to the middle */
.styled-list li:nth-child(even):after,
.styled-list li:nth-child(2n+3):before {
  content: ' ';
  border-top: 1px solid black;
  position: absolute;
  top: 50%;
}
/* line for the left items */
.styled-list li:nth-child(even):after {
  left:100%;
  right: -25%;
  margin-right: -1px; /* compensate line width */
}
/* line for the right items */
.styled-list li:nth-child(2n+3):before {
  left: -25%;
  right: 100%;
  margin-left: -1px; /* compensate line width */
}
/* horizontal line */
.styled-list:after {
  content: ' ';
  border-left: 1px solid black;
  position: absolute;
  top: 3em;
  bottom: 2.5em;
  left: 50%;
  right: 0;
  margin-bottom: 0; /* compensate line width */
}
<ul class="styled-list">
  <li>Head</li>
  <li>List Item 1</li>
  <li>List Item 2</li>
  <li>List Item 3 with some more text inside it that can also be in three lines</li>
  <li>List Item 4</li>
  <li>List Item 5</li>
  <li>List Item 6</li>
  <li>List Item 7</li>
  <li>List Item 8</li>
</ul>

关于html - 创建备用列表元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46295204/

相关文章:

html - 即使标题很长,如何自动将文本放入框中

java - 如何将 List<int[]> 转换为二维数组?

python - 如何分隔逗号分隔的列表

c - 为什么 BSD 在链表条目中使用双指针?

html - <select> 在 IE 中的宽度与在其他浏览器中的行为不同

html - thead/tbody 跨越打印的 HTML 的多页但不在第一页

HTML/CSS : Div 100% height of page

css - Bootstrap 3 列 100% 高度减去标题

html - 如何让高度真正达到100%

html - 为什么我的高度是: 100% property not working?