我正在处理一个带有垂直导航栏的页面的作业,其中每个链接都包含在一个框中。分配要求将当前链接的框更改为红色。我尝试了几种不同的方法,但似乎没有一种方法可行。这就是我所拥有的:
/* the styles for the elements */
* {
margin: 0;
padding: 0;
}
html {
background-color: white;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
width: 850px;
margin: 0 auto;
border: 3px solid #931420;
background-color: #fffded;
}
a:focus, a:hover {
font-style: italic;
}
/* the styles for the header */
header {
padding: 1.5em 0 2em 0;
border-bottom: 3px solid #931420;
background-image: -moz-linear-gradient(
30deg, #f6bb73 0%, #f6bb73 30%, white 50%, #f6bb73 80%, #f6bb73 100%);
background-image: -webkit-linear-gradient(
30deg, #f6bb73 0%, #fffded 30%, white 50%, #fffded 80%, #f6bb73 100%);
background-image: -o-linear-gradient(
30deg, #f6bb73 0%, #fffded 30%, white 50%, #fffded 80%, #f6bb73 100%);
background-image: linear-gradient(
30deg, #f6bb73 0%, #fffded 30%, white 50%, #fffded 80%, #f6bb73 100%);
}
header h2 {
font-size: 175%;
color: #800000;
}
header h3 {
font-size: 130%;
font-style: italic;
}
header img {
float: left;
padding: 0 30px;
}
.shadow {
text-shadow: 2px 2px 2px #800000;
}
/* the styles for the main content */
main {
clear: left;
}
/* the styles for the section */
section {
width: 575px;
float: right;
padding: 0 20px 20px 20px;
}
section h1 {
color: #800000;
font-size: 150%;
padding-top: .5em;
margin: 0;
}
section p {
padding-bottom: .5em;
}
#boldp{
font-weight: bold;
}
#navlist .current{
background-color: #800000;
}
#navlist ul li{
margin: 5px;
background-image: url("../images/right.jpg");
background-repeat: no-repeat;
background-position: 95%;
border: 2px solid black;
border-radius:25px;
padding: 10px;
width: 175px;
height: 35px;
box-shadow: 5px 5px 2px #800000;
}
#navlist ul{
list-style-type: none;
padding: 10px;
}
/* the styles for the article */
article {
padding: .5em 0;
}
article h2 {
font-size: 115%;
padding: 0 0 .25em 0;
}
article img {
float: right;
margin: .5em 0 1em 1em;
border: 1px solid black;
}
/* the styles for the aside */
aside {
width: 215px;
float: right;
padding: 0 0 20px 20px;
}
aside h2 {
color: #800000;
font-size: 130%;
padding: .6em 0 .25em 0;
}
aside h3 {
font-size: 105%;
padding-bottom: .25em;
}
aside img {
padding-bottom: 1em;
}
/* the styles for the footer */
footer {
background-color: #931420;
clear: both;
}
footer p {
text-align: center;
color: white;
padding: 1em 0;
}
<aside>
<h2>Guest speakers</h2>
<nav id ="navlist">
<ul>
<li><h3><a href="c06x_toobin.html">October<br>Jeffrey Toobin</a></h3></li>
<li><h3><a href="#">November<br>Andrew Ross Sorkin</a></h3></li>
<li><h3><a href="#">January<br>Amy Chua</a></h3></li>
<li class ="current"><h3><a href="c07x_sampson.html">February<br>Scott Sampson</a></h3></li>
</ul>
<h3><a href="../index.html">Return to Home page</a></h3>
</nav>
</aside>
答案 0 :(得分:2)
#navlist .current
将定位.current
类,您可以将background
或其他任何内容应用于该类。
#navlist .current {
background: red;
}
#navlist ul li{
margin: 5px;
background-image: url("../images/right.jpg");
background-repeat: no-repeat;
background-position: 95%;
border: 2px solid black;
border-radius:25px;
padding: 10px;
width: 175px;
height: 35px;
box-shadow: 5px 5px 2px #800000;
}
#navlist ul li.sam {
background-color: #800000;
}
#navlist ul{
list-style-type: none;
padding: 10px;
}
&#13;
<aside>
<h2>Guest speakers</h2>
<nav id ="navlist">
<ul>
<li><h3><a href="c06x_toobin.html">October<br>Jeffrey Toobin</a></h3></li>
<li><h3><a href="#">November<br>Andrew Ross Sorkin</a></h3></li>
<li><h3><a href="#">January<br>Amy Chua</a></h3></li>
<li class ="current"><h3><a href="c07x_sampson.html">February<br>Scott Sampson</a></h3></li>
</ul>
<h3><a href="../index.html">Return to Home page</a></h3>
</nav>
</aside>
&#13;
答案 1 :(得分:0)
嘿,如果我理解你的权利,我认为你只需要为当前的课程添加背景
.current {
background-color:red;
}