一个href样式继承

时间:2016-01-24 15:26:00

标签: html css

我遇到的问题是我的导航aa href .content发生冲突 - 我过去几个小时都试图解决这个问题而且没有运气,谢谢。



ul.nav {
    list-style-type: none;
    margin: 0;
    min-width: 360px;
}
ul.nav li {
    display: table-cell;
    text-align: center;
}
a.active {
    background-color: #cc293f;
    font-weight: 700;
}
.nav-container {
    font-family: 'Catamaran', sans-serif;
    background-color: #505050;
    margin: 5px 0 0;
}
.table {
    display: table;
    margin: 5px auto;
}
a {
    font-family: 'Catamaran', sans-serif;
    background-color: #505050;
    border-right: 1px solid #fff;
    color: #fff;
    float: left;
    padding: .2em .6em;
    text-decoration: none;
    width: 10em;
}
a:hover {
    background-color: #cc293f;
}
.content {
    border-radius: 10px 10px 10px 10px;
    border: 2px solid #cc293f;
    margin-top: 10px;
    min-width: 360px;
    min-height: 650px;
}
.content h1 {
    font-size: 26px;
    color: #fff;
    text-align: center;
    margin-top: 5px;
}
.content h2 {
    font-size: 22px;
    text-align: center;
    margin-top: -35px;
}
.content p {
    font-size: 18px;
    margin-top: -5px;
    margin-left: 10px;
}
.content #p2 {
    font-size: 19px;
    margin-left: 50px;
    margin-top: -5px;
}

<html>
<body>
<div class="nav-container">
<div class="table">
<ul class="nav">
<li style="border-left:1px solid white;"><a class="active" href=
    "index.html">Home</a></li>
<li><a href="faq.html">FAQs</a></li>

<li><a href="support.html">Resolution Center</a></li>
<li><a href="upload.html">Upload</a></li></ul>
</div>
  </div>

<div class="content">

<p>example</p>
<a href="google.com" target="_blank"><img src="http://cumbrianrun.co.uk/wp-content/uploads/2014/02/default-placeholder.png" height="75" width="75"></a>

</body>
</html>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

您为全局<a> tag声明了样式,因此所有<a tags都将使用该样式。 <a tags from .content class的特殊样式可以通过添加到您的css文件来实现:.content a { your instructions }

此外,使用ul nav li a指定所需的菜单选项。如果项目中有多个ul列表,请为每个列表使用特定的类。

答案 1 :(得分:0)

现在看到这一点在默认和悬停时具有非常不同的属性。

&#13;
&#13;
ul.nav {
    list-style-type: none;
    margin: 0;
    min-width: 360px;
}
ul.nav li {
    display: table-cell;
    text-align: center;
}
a.active {
    background-color: #cc293f;
    font-weight: 700;
}
.nav-container {
    font-family: 'Catamaran', sans-serif;
    background-color: #505050;
    margin: 5px 0 0;
}
.table {
    display: table;
    margin: 5px auto;
}
a {
    font-family: 'Catamaran', sans-serif;
    background-color: #505050;
    border-right: 1px solid #fff;
    color: #fff;
    float: left;
    padding: .2em .6em;
    text-decoration: none;
    width: 10em;
}
a:hover {
    background-color: #cc293f;
}
.content {
    border-radius: 10px 10px 10px 10px;
    border: 2px solid #cc293f;
    margin-top: 10px;
    min-width: 360px;
    min-height: 650px;
}
.content h1 {
    font-size: 26px;
    color: #fff;
    text-align: center;
    margin-top: 5px;
}
.content h2 {
    font-size: 22px;
    text-align: center;
    margin-top: -35px;
}
.content p {
    font-size: 18px;
    margin-top: -5px;
    margin-left: 10px;
}
.content #p2 {
    font-size: 19px;
    margin-left: 50px;
    margin-top: -5px;
}
.content a {
 background:blue;
 transition:1s;
 }
 .content a:hover {
 transform:translateX(500px);background:red;
 }
&#13;
<html>
<body>
<div class="nav-container">
<div class="table">
<ul class="nav">
<li style="border-left:1px solid white;"><a class="active" href=
    "index.html">Home</a></li>
<li><a href="faq.html">FAQs</a></li>

<li><a href="support.html">Resolution Center</a></li>
<li><a href="upload.html">Upload</a></li></ul>
</div>
  </div>

<div class="content">

<p>example</p>
<a href="google.com" target="_blank"><img src="http://cumbrianrun.co.uk/wp-content/uploads/2014/02/default-placeholder.png" height="75" width="75"></a>

</body>
</html>
&#13;
&#13;
&#13;