SVG图像为:边框没有固定高度?

时间:2014-12-06 01:59:24

标签: html css svg height nav

好的,我当前项目中导航的here is a jsfiddle。我不确定我是否会以最好的方式解决这个问题,但我希望徽标在导航中间居中,并且三个链接以徽标为中心。

但是,我需要网站响应:能够顺畅处理各种屏幕宽度。有什么建议吗?

此外,我希望能够将.png用作div上的边框,而无需设置固定高度。但是,当我将其设置为height:auto时,背景色完全消失。

HTML:

<div id="header-wrap" class="group">
<nav>   
    <a href="index.html"><img class="logo" src="http://i60.tinypic.com/1zxqqm1.png" alt="Cat Town Cafe & Adoption" /></a>

    <ul>
        <li><a href="index.html">ABOUT</a>

        </li>
        <li><a href="index.html">OUR CATS</a>

        </li>
        <li><a href="index.html">RESERVATIONS</a>

        </li>
        <li><a href="index.html">DONATE</a>

        </li>
        <li><a href="index.html">HELP OUT</a>

        </li>
        <li><a href="index.html">CONTACT</a>

        </li>
    </ul>
</nav>
</div>

CSS:

#header-wrap {
width: 100%;
height: auto;
position: relative;
background-color: #E6D7B8;
z-index: 5;
}
#header-wrap:after {
width: 100%;
height: 4px;
background: url("http://i57.tinypic.com/30uxn47.png") repeat-x;
-webkit-transform: rotate(-180deg);
-moz-transform: rotate(-180deg);
-ms-transform: rotate(-180deg);
-o-transform: rotate(-180deg);
transform: rotate(-180deg);
position: absolute;
bottom: -4px;
left: 0;
display: block;
content:"";
z-index: 5;
}
nav {
background: #E6D7B8;
height: 60px;
position: relative;
}
nav ul {
margin: 0 auto;
padding: 0;
list-style: none;
}
nav li a {
display: block;
float: left;
padding: 0 18px;
height: 60px;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
position: relative;
font: 400 14px'Bitter';
letter-spacing: 0.05em;
color: #893B4E;
text-transform: uppercase;
text-decoration: none;
}
nav li a:hover {
box-shadow: inset 0px 4px 0px #4C264B;
}
nav li a:hover:before {
width: 100%;
height: 100px;
background: linear-gradient(#4C264B, transparent);
display: block;
content:"";
position: absolute;
left: 0;
z-index: -1;
}
nav ul li {
float: left;
}
nav ul li:nth-of-type(4) {
margin-left: 277px;
}
.logo {
position: absolute;
left: 50%;
margin: 0 0 0 -135px;
max-width: 270px;
z-index: 100;
}

1 个答案:

答案 0 :(得分:0)

.logo放在ul内,您需要对CSS进行一些更改。

Fiddle

HTML:

<div id="header-wrap" class="group">
  <nav>
    <ul>
      <li><a href="index.html">ABOUT</a>

      </li>
      <li><a href="index.html">OUR CATS</a>

      </li>
      <li><a href="index.html">RESERVATIONS</a>

      </li>
      <li class="logo">
        <a href="index.html"></a>
      </li>
      <li><a href="index.html">DONATE</a>

      </li>
      <li><a href="index.html">HELP OUT</a>

      </li>
      <li><a href="index.html">CONTACT</a>

      </li>
    </ul>
  </nav>
</div>

CSS:

#header-wrap {
    width: 100%;
    height: auto;
    position: relative;
    background-color: #E6D7B8;
    z-index: 5;
}
#header-wrap:after {
    width: 100%;
    height: 4px;
    background: url("http://i57.tinypic.com/30uxn47.png") repeat-x;
    -webkit-transform: rotate(-180deg);
    -moz-transform: rotate(-180deg);
    -ms-transform: rotate(-180deg);
    -o-transform: rotate(-180deg);
    transform: rotate(-180deg);
    position: absolute;
    bottom: -4px;
    left: 0;
    display: block;
    content:"";
    z-index: 5;
}
nav {
    background: #E6D7B8;
    height: 60px;
    position: relative;
    width: 100%;
    margin: 0 auto;
}
nav ul {
    margin: 0 auto;
    width: 870px;
    padding: 0;
    list-style: none;
}
nav li a {
    display: block;
    float: left;
    padding: 0 18px;
    height: 60px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    font: 400 14px'Bitter';
    letter-spacing: 0.05em;
    color: #893B4E;
    text-transform: uppercase;
    text-decoration: none;
}
nav li:not(.logo) a:hover {
    box-shadow: inset 0px 4px 0px #4C264B;
}
nav li:not(.logo) a:hover:before{
    width: 100%;
    height: 100px;
    background: linear-gradient(#4C264B, transparent);
    display: block;
    content:"";
    position: absolute;
    left: 0;
    z-index: -1;
}
nav ul li {
    float: left;
}
.logo a {
    width: 200px;
    height: 130px;
    position: relative;
    background: url(http://i60.tinypic.com/1zxqqm1.png) no-repeat;
    background-size: 100% 100%;
    background-position: 0% 0%;
    z-index: 10;
}