html - 在 li 的中心创建垂直线

标签 html css html-lists

我创建了一个带有 ulli 的 html 页面来显示一些链接并为 li 设置一些背景颜色'秒。现在我想在 li 上添加垂直线。

当我尝试设置图像时,它出现在图 1 中,但我希望它像图 2 中所示。

图1

enter image description here

图2

enter image description here

到目前为止我已经尝试过:

ul#sitemap1 {
  list-style: none;
}

ul#sitemap1 li a {
  background-color: #002163;
  color: white;
  padding: 10px;
  text-decoration: none;
  width: 200px;
  display: block;
  margin: 10px;
  font-weight: bold;
}

#sitemap1 li {
  clear: left !important;
  margin-top: 0px !important;
  padding: 10px !important;
  background: url('/Images/ConnectLine.JPG') no-repeat !important;
  float: inherit;
}

ul#sitemap1 li a:hover {
  background-color: Orange;
}

ul#sitemap2 {
  list-style: none;
}

ul#sitemap2 li a {
  background-color: #002163;
  color: white;
  padding: 10px;
  text-decoration: none;
  width: 200px;
  display: block;
  margin: 10px;
  font-weight: bold;
}

ul#sitemap2 li a:hover {
  background-color: Orange;
}

ul#sitemap3 {
  list-style: none;
}

ul#sitemap3 li a {
  background-color: #002163;
  color: white;
  padding: 10px;
  text-decoration: none;
  width: 200px;
  display: block;
  margin: 10px;
  font-weight: bold;
}

ul#sitemap3 li a:hover {
  background-color: Orange;
}
<h1>Innovations</h1>

<ul id="sitemap1">
  <a href="https://Home.aspx" style="font-weight:bold;text-decoration:none">Home</a>
  <li><a href="https://Services.aspx">Services</a></li>
  <li><a href="https:///OC.aspx">Organizational Change</a></li>
  <li><a href="https://kit.aspx">kit</a></li>
  <li><a href="https://Sheets.aspx">Sheets</a></li>
</ul>

<ul id="sitemap2">
  <a href="https://Engagement.aspx" style="font-weight:bold; text-decoration:none">Engagement</a>
  <li><a href="https://Ideas.aspx">Ideas</a></li>
  <li><a href="https://WS.aspx">WorkSmart</a></li>
</ul>

<ul id="sitemap3">
  <a href="https://Links.aspx" style=" font-weight:bold; text-decoration:none">Related Links</a>
  <li><a href="https://Gotime.aspx">GO-TIME</a></li>
</ul>

最佳答案

  1. 我建议从 CSS 中删除 id,无需复制相同的 CSS,只需引用 ul 标签即可。

  2. 您可以使用 :after 伪元素来创建行。

  3. 使用 :last-child 删除最后一项的行。

ul {
  list-style: none;
}
ul li {
  width: 220px;
  position: relative;
  margin-bottom: 20px;
}
ul li:after {
  content: "";
  position: absolute;
  top: 90%;
  left: 50%;
  height: 25px;
  background: black;
  width: 4px;
  border-radius: 5px;
  border: 2px solid white;
  z-index: 100;
}
ul li:last-child:after {
  display: none;
}
ul li a {
  background-color: #002163;
  color: white;
  padding: 10px;
  text-decoration: none;
  width: 200px;
  display: block;
  margin: 10px;
  font-weight: bold;
}
ul li a:hover {
  background-color: Orange;
}
<h1>Innovations</h1>
<ul id="sitemap1"><a href="https://Home.aspx" style="font-weight:bold;text-decoration:none">Home</a>
  <li><a href="https://Services.aspx">Services</a>
  </li>
  <li><a href="https:///OC.aspx">Organizational Change</a>
  </li>
  <li><a href="https://kit.aspx">kit</a>
  </li>
  <li><a href="https://Sheets.aspx">Sheets</a>
  </li>
</ul>
<ul id="sitemap2"><a href="https://Engagement.aspx" style="font-weight:bold; text-decoration:none">Engagement</a>
  <li><a href="https://Ideas.aspx">Ideas</a>
  </li>
  <li><a href="https://WS.aspx">WorkSmart</a>
  </li>
</ul>
<ul id="sitemap3"><a href="https://Links.aspx" style=" font-weight:bold; text-decoration:none">Related Links</a>
  <li><a href="https://Gotime.aspx">GO-TIME</a>
  </li>
</ul>

关于html - 在 li 的中心创建垂直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37883544/

相关文章:

javascript - 背景图像缩放

jquery - DataTables:更改选择器的框架、字体和对齐方式

html - CSS 输出在 IE11 Windows 7 或 IE11 Windows 10 上不同

html-lists - 如何在 CSS 中使用 inherit on min-width?

html - 在 HTML5 中关闭 void 元素时是否还需要正斜杠?

javascript - 按钮未正确更新输出

jquery - 如何使用 swiper 类在 html 中自动制作图像 slider ?

python - 填充 html 表单时,Html 输入值不显示完整变量

javascript - 如何清除 Canvas 以进行重绘

html - 如何在一行中设置两组 <li> 的样式?