使用CSS在列表中垂直覆盖一半的单词

时间:2016-03-08 18:01:47

标签: html css html5 css3

我被要求创建一个简单的unordered list

困难的部分是该列表中的每个单词必须垂直覆盖50%,如下图所示:

enter image description here

显然,我必须用CSS代替统治者。我不知道该怎么做。有任何想法吗 ?

2 个答案:

答案 0 :(得分:4)

li{
  position: relative;
}
li:after{
 background: #FFF;
 content: "";
 display: block;
 position: absolute;
 left: 0;
 top: 0;
 right: 0;
 bottom: 50%;
}
<ul>
  <li>Sample link</li>
  <li>Sample link</li>
  <li>Sample link</li>
  <li>Sample link</li>
</ul>

答案 1 :(得分:0)

希望这会对你有所帮助:

<!DOCTYPE html>
<html>
   <head>
  <style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;

}

li {
    float: left;
}

li a {
    display: inline-block;
    color: #000;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

.cover_div{    height: 20px;
    position: absolute;

    width: 300px;
    opacity: 1;
    top: 10px;
    background-color: #fff;}


</style>
   </head>



    <body>

    <div class="cover_div"></div>

 <div class="menu">
   <ul>
  <li><a class="active" href="#home">Home</a></li>
  <li><a href="#news">News</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a href="#about">About</a></li>
</ul>
</div>

   </body>
</html>