【发布时间】:2017-03-30 22:38:36
【问题描述】:
我的问题是:为什么.main-index a:nth-child(4) 在我的第一个a 链接上工作,而不是.main-index a:nth-child(1)?
我似乎找不到问题或我做错了什么。
它有效,但我知道这不是选择第一个的正确方法。
有谁知道如何正确选择.main-index中的第一个a
.main-index h2 {
height: 60px;
text-align: center;
line-height: 60px;
background-color: #3b3b3b;
color: white;
font-size: 25px;
letter-spacing: 1px;
margin: 0;
font-family: "LemonMilk";
}
/********************************************
3.0 feedback
*********************************************/
.main-index p:nth-of-type(1) {
margin: 15px 0 0 10px;
text-transform: uppercase;
font-size: 14px;
float: left;
font-family: "NeueHaasGrotesk Light";
}
.main-index p:nth-of-type(2) {
clear: both;
margin-top: 10px;
display: inline-block;
}
.main-index img {
margin: 10px 0 0 5px;
height: 25px;
float: left;
}
.main-index a:nth-child(4) {
float: right;
margin: 7px 10px 0 0;
padding: 10px;
background-color: #0e8f9c;
color: white;
border: none;
font-size: 13px;
text-transform: capitalize;
letter-spacing: 1px;
font-family: "NeueHaasGrotesk medium";
}
/********************************************
5.0 Ticket Info International Student
*********************************************/
.main-index p:nth-of-type(2) {
margin: 10px;
font-size: 18px;
}
.main-index a:nth-child(6) {
background-color: #d3464e;
padding: 10px;
margin: 15px;
display: block;
text-align: center;
}
/********************************************
6.0 main content
*********************************************/
.background-home {
background-image: url(../img/goingoutparadiso.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: 80%;
padding: 20px 0;
}
.background-home li {
text-align: center;
line-height: 90px;
font-size: 50px;
border-bottom: 5px solid white;
border-top: 5px solid white;
box-shadow: 1px 1px 2px #3b3b3b;
text-transform: uppercase;
padding-top: 10px;
padding-bottom: 10px;
width: 100%;
}
.background-home a {
display: block;
}
.background-home h3 {
margin: 0;
font-family: "NeueHaasGrotesk bold";
text-shadow: 2px 2px #3b3b3b;
border: 3px solid white;
padding: 5px;
display: inline;
}
.background-home li:nth-child(1) {
border-top: 0;
}
.background-home li:nth-child(2) {
margin-top: 20px;
margin-bottom: 20px;
}
.background-home li:nth-child(3) {
margin-top: 20px;
margin-bottom: 20px;
}
.background-home li:nth-child(4) {
border-bottom: 0;
}
<main class="main-index">
<h2>different spots</h2>
<p>your feedback matters</p>
<img alt="feedback page indicator" src="img/more-info-arrow-black.svg">
<a href="feedback.html">feedback</a>
<p>Just like every student, you as an international student can get discount in several clubs and bars in Amsterdam. This ticket will save you time and money!</p>
<a href="https://www.tiqets.com/en/amsterdam-c75061/amsterdam-nightlife-clubs-free-drinks-p973786" target="_blank">Tickets for Amsterdam Nightlife & Clubs + Free Drinks</a>
<nav>
<ul class="background-home">
<li>
<a href="clubs.html"><h3>clubs</h3></a>
</li>
<li>
<a href="bars.html"><h3>bars</h3></a>
</li>
<li>
<a href=""><h3>music</h3></a>
</li>
<li>
<a href=""><h3>festivals</h3></a>
</li>
</ul>
</nav>
</main>
【问题讨论】:
-
感谢您的信息! .main-index > a:nth-of-type(1) 完成了这项工作。现在我对选择器及其工作原理有了更多了解。再次感谢!
标签: html css css-selectors pseudo-class