0
我有幾個問題與我的CSS。正如您在fiddle中看到的那樣,我希望圖像能夠完美自動地垂直對齊,正確地對準中間。菜單鏈接也是如此。CSS:圖像和鏈接verticaly對齊(中心)和響應圖像交換
我遇到的另一個問題是,我想在使用小屏幕時將徽標圖像更改爲另一個源。我希望只使用媒體查詢(如果可能的話)。
樣本HTML
<header>
<nav id="menu-main" class="clearfix">
<a id="logo-link" href="#"><img id="logo"
src="http://juvera.me/websites/openwork/beta/_img/logo-291x60.png" title="Open Work" alt="Open Work" /></a>
<ul id="menu-links">
<li class="link-active"><a class="link-active" href="/">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</main>
CSS
body { font-family: Century Gothic, sans-serif; margin: 0em; padding: 0em; }
header, main { display: block; margin: 0em; padding: 0em; }
header {
background-color: #292828;
height: 70px;
max-height: 70px;
/* Overlay */
width: 100%;
position: absolute; left:0; right:0; z-index: 999;
}
header nav {
height: 70px;
}
/* *************************************
Image Menu
************************************* */
#logo {
margin: auto 0em auto 10%;
vertical-align: middle;
}
#logo-link {
height: 70px;
vertical-align: middle;
}
/* *************************************
Links menu
************************************* */
#menu-links {
float: right;
margin: auto 10% auto 0em;
}
#menu-links li {
display: inline-block;
}
#menu-links li a {
color: #fff;
font-size: 0.75em;
text-decoration: none;
text-transform: uppercase;
height: 70px;
padding: 0em 1em 0em 1em;
display: inline-block;
vertical-align:middle;
text-align: center;
}
main { padding-top: 70px; background-color: #cccccc; }
@media (max-width:10em) {
/* smartphones, iPhone, portrait 480x320 phones */
#logo{ src:"http://juvera.me/websites/openwork/beta/_img/logo-150x31.png"; }
main { font-size: 1em; }
}
'vertical-align:middle;'是挑剔的,幸運的是將內聯類型元素的'line-height'設置爲父元素的高度,但請注意,「line-height」將被所有孩子繼承。 – 4castle