简体   繁体   English

从CSS的ul li元素中删除红色边框

[英]Removing red border from the ul li elements in CSS

I have the following html code: 我有以下html代码:

<div class="nav">
      <ul>
        <li class="home"><a href="#">Home</a></li>
        <li class="home2"><a class="active" href="#">Home2</a></li>
        <li class="home3"><a href="#">Home3</a></li>
        <li class="home4"><a href="#">Home4</a></li>
        <li class="home5"><a href="#">Home5</a></li>
      </ul>
    </div>  
<div class="post">
    <div id="borders">
        <ul>
            <li>red border</li>
            <li>red border</li>
            <li>red border</li>
            <li>red border</li>
            <li>red border</li>
        </ul>
    </div>
</div>

and with that I have a css file: 并有一个css文件:

body {
  padding-top: 2rem;
}
* {
  padding: 0; 
  margin: 0;
  box-sizing: border-box;
}
.nav {
    min-width:100% !important;
}
.nav ul {
  list-style: none;
  background-color: rgba(0,0,0,0.6);
  text-align: center;
  position: absolute;
  top: 0;
  padding: 0;
  margin: 0;
  min-width: 100%;
}
.nav li {
  font-size: 20px;
  line-height: 30px;
  height: 30px;
  border-bottom: 1px solid #888;
}

.nav a {
  text-decoration: none;
  color: #fff;
  display: block;
  transition: .3s background-color;
}

.nav a:hover {
  background-color: #919191;
}

.nav a.active {
  background-color: #fff;
  color: #444;
  cursor: default;
}

@media screen and (min-width: 600px) {
  .nav li {
    width: 120px;
    border-bottom: none;
    font-size: 20px;
  line-height: 30px;
  height: 30px;
  }

  .nav li {
    display: inline-block;
    margin-right: -4px;
  }
}

ul li { position: relative; border:1px solid red; display: inline-block; text-align: center;  }
ul { text-align:center; }

And now when I run it in jsfiddle, I see there's a red border around every element. 现在,当我在jsfiddle中运行它时,我看到每个元素周围都有一个红色边框。 What I want to achieve is to remove the border from the top elements and just use it on the elements from div id = borders. 我要实现的是从顶部元素中删除边框,而仅在div id = borders的元素上使用它。 I'm a little bit confused about CSS, because I tried to use the code .borders ui li , but it didn't work well... I thought that's the way how we should call the classes on the webpage? 我对CSS有点困惑,因为我尝试使用代码.borders ui li,但是效果不佳...我认为那是我们应该如何在网页上调用类的方式? Anyway, could you help me with removing the red border from the top links and leave it only on the words containing "red border"? 无论如何,您能帮我从顶部链接中删除红色边框,而仅将其保留在包含“红色边框”的单词上吗?

Here's the jsfiddle for that http://jsfiddle.net/gfkPG/451/ Thanks! 这是该http://jsfiddle.net/gfkPG/451/的jsfiddle!谢谢!

Use #borders ul li (as # is an id selector, not .class selector) instead of ul li . 使用#borders ul li (如#是一个id选择,不是. - class选择器),而不是ul li

JSFiddle 的jsfiddle

Your borders is an ID but you're referring to it as a class in your CSS. 边界是一个ID,但您在CSS中将其称为类。

Try #borders instead of .borders . 尝试使用#borders而不是.borders

You could use a class here also: 您也可以在这里使用一个类:

 .borders ul li { border:1px solid red; } 
  <div class="borders"> <ul> <li>red border</li> </ul> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM