【发布时间】:2014-02-23 02:54:05
【问题描述】:
我有一个位于屏幕顶部的导航栏。我必须首先说,我知道像这样的导航栏在移动设备上可能会很尴尬,我刚刚从我的代码中删除了媒体查询,因为它不会影响它们。
我的问题是,如果用户的屏幕对于移动版来说太大,但又太小而无法容纳整个导航栏,那么公司徽标就会缩进导航栏下方以及下方元素下方。我希望徽标自动调整大小,但我还不能做到这一点。我尝试为徽标链接设置自动宽度,并且还弄乱了其他标签,但仍然没有运气。菜单栏上的链接数量也可以变化,所以目前有 5 个元素,但最多可以有 7 个。我需要这种大小变化来影响徽标。
有人告诉我,徽标需要与包装器相关,但 NavBar div 的大小会随着窗口一起缩小。
直播链接:http://rental.joshblease.co.uk/stack.php
小提琴 http://jsfiddle.net/dZVyZ/
截图:
在屏幕上 > 900px 宽
在
必填结果
最后一张图片有一个较小的标志,当宽度太小时会缩小
HTML:
<div id="MainWrapper">
<div id="NavBar">
<ul>
<li class="Down DownBlue"><a href="/index/">Home</a></li>
<li class="Green"><a href="/Property/">View</a></li>
<li class="Pink"><a href="/About/">About Us</a></li>
<li class="Purple"><a href="/Josh/">Josh Blease</a></li>
<li class="Orange"><a href="/Contact/">Contact</a></li>
</ul>
<a href="/index/"><img id="NavLogo" src="/Images/Logo.png" /></a>
</div>
<div class="Clear"></div>
</div>
CSS:
#MainWrapper {
max-width: 900px;
width: 100%;
margin: 0 auto 0 auto;
}
.Clear{
clear: both;
}
#NavBar{
overflow: hidden;
display: block;
position: fixed;
width: inherit;
max-width: 900px;
z-index: 999;
height:70px;
background: url(../Images/NavBg.png);
padding-left: 10px;
}
#NavBar ul{
list-style: none;
}
#NavBar li{
float: left;
padding: 20px 0 10px;
margin-right: 10px;
}
#NavBar li a{
padding: 30px 10px 10px;
background-color: #CBCBCB;
color: #000;
font-size: 17px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottom-right: 5px;
-moz-border-radius-bottom-left: 5px;
transition: background 300ms ease-in-out;
-webkit-transition: background 300ms ease-in-out;
-moz-transition: background 300ms ease-in-out;
-ms-transition: background 300ms ease-in-out;
-o-transition: background 300ms ease-in-out;
}
#NavBar .Down, .JavaOff #NavBar li:hover{
padding-top: 30px;
}
#NavLogo{
float: right;
height: 60px;
padding: 5px 15px;
}
【问题讨论】:
-
您是否在徽标上使用了相对宽度?尝试例如宽度:15%;和高度:自动;。你有一个小提琴或真实的网页来查看你的问题吗?
-
既然你已经在使用媒体查询了,是不是不能再为这个尺寸添加一个?
-
@MichaB - 看看这里rental.joshblease.co.uk/stack.php我现在就做一个小提琴
-
@badAdviceGuy 我会,但列表的宽度可以改变的事实可能会使它变得无用。它由像 wordpress 这样的管理面板控制,但自定义构建,因此客户端可能有更多导航项。
-
标识应该相对于其容器的宽度,并用
min-width来限制它。容器的宽度应该相对于导航栏的宽度,可能是“最大宽度”,具体取决于您的需要。
标签: html css responsive-design width