【发布时间】:2014-10-29 17:12:01
【问题描述】:
你好很棒的程序员,
一段时间以来,我一直在努力使用 CSS。我在调整窗口大小时遇到问题,我的一些 div 开始在页面下方折叠。 (如图)
之前:
before http://411metrics.com/pics/before.PNG
之后:
before http://411metrics.com/pics/after.PNG
我尝试将各种 div 的最小宽度设置为 100%,还尝试将溢出设置为隐藏。
有人对如何解决这个问题有任何建议吗?
我的 HTML:
<div id="navigation">
<div id="branding-logo"><img src="/Portal/images/sharktek-logo.png" width="35" height="35"></div>
<div id="branding">Sharktek Tracking</div>
<div id="link-wrap">
<div id="active-nav"><a href="/Portal/dashboard">Dashboard</a></div>
<a href="/Portal/statistic">Reports</a>
<a href="/Portal/record">Call Logs</a>
<a href="/Portal/manage">Manage Campaigns</a>';
</div>
<div id="nav-user">
Welcome<br>
<a href="/Portal/account">Account Settings</a>
<a href="/Portal/auth/logout">Logout</a>
</div>
</div>
<div id="nav-accent"></div>
我的 CSS:
#navigation {
z-index:3;
position: fixed;
top: 0;
width: 100%;
min-width:100%;
color: #ffffff;
height: 60px;
text-align: center;
/* Adds the transparent background */
background-color: rgba(22, 29, 37,1);
color: rgba(1, 172, 237, 1);
}
#navigation a {
float:left;
font-size: 14px;
padding: 25px 25px 0 25px;
color: white;
text-decoration: none;
}
#link-wrap {
float: left;
overflow: hidden;
margin-left: 15%;
}
#active-nav{
z-index: 2;
float:left;
color:white;
height: 60px;
background: -webkit-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Firefox 3.6 to 15 */
background: linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* Standard syntax */
}
#active-nav a:hover {
color:white;
}
#navigation a:hover {
color: grey;
}
#branding-logo {
margin-top: 15px;
margin-left: 10px;
float: left;
}
#branding{
margin-top: 20px;
margin-left: 10px;
font-size:1.4em;
color: white;
float: left;
padding: 0px;
}
#nav-accent {
z-index:2;
position: fixed;
top: 60px;
width: 100%;
color: #ffffff;
height: 2px;
padding-top: 1px;
/* Adds shadow to the bottom of the bar */
-webkit-box-shadow: 0px 0px 8px 0px #000000;
-moz-box-shadow: 0px 0px 8px 0px #000000;
box-shadow: 0px 0px 8px 0px #000000;
/* Adds the transparent background */
background-color: rgba(1, 172, 237, 0.95);
color: rgba(1, 172, 237, 1);
}
#nav-user {
color: white;
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 15px 30px 0 0;
font-size: .8em;
float:right;
}
#nav-user a{
margin: 0;
padding: 0 0 0 10px;
font-size:.8em;
}
【问题讨论】:
-
你需要在这里放弃一些东西。如果你想要响应,那么你需要为响应行为编写代码,定义在特定大小下会发生什么。很明显,无论如何,在某些时候元素都不适合。在这种情况下……你想发生什么?基于此,您可能会有不同的答案。现在,您可以使用 position:absolute 的元素,它会起作用....直到您看到该元素在调整大小时与其他所有内容重叠
-
好吧,我没有浏览你的代码,只是看一眼你的问题,我建议你切换到引导网格系统来设计你的布局。我敢肯定,一旦你习惯了它,你就永远不会回头。 getbootstrap.com/css/#grid