為什么nav_left ,nav_mid, nav_right不在一行?
<!DOCTYPE?html> <html> <head> <title></title> <link?rel="stylesheet"?type="text/css"?href="css/main.css"> <script?type="text/javascript"?src="js/setHomeSetFav.js"?charset="gb2312"></script> </head> <body> <div?class="top"> <div?class="top_content"> <ul> <li><a?href="#">聯(lián)系我們</a></li> <li><a?href="#"?onclick="AddFavorite(window.location,document.title)">加入收藏</a></li> <li><a?href="#"?onclick="SetHome(window.location)">設(shè)為首頁(yè)</a></li> </ul> </div> </div>?<!--top結(jié)束--> <div?class="wrap"> <div?class="logo"> <div?class="logo_left"> <img?src="images/logo.jpg"?alt="慕課網(wǎng)"/> </div> <div?class="logo_right"> <img?src="images/tel.jpg"?alt="服務(wù)熱線"/>24小時(shí)服務(wù)熱線:<span?class="tel">?123-456-7890</span> </div> </div><!--logo結(jié)束--> <div?class="nav"> <div?class="nav_left"></div>? <div?class="nav_mid"> <div?class="nav_mid_left"> <ul> <li><a?href="#">首頁(yè)</a></li> <li><a?href="list.html">關(guān)于慕課</a></li> <li><a?href="list.html">新聞動(dòng)態(tài)</a></li> <li><a?href="list.html">課程中心</a></li> <li><a?href="list.html">在線課程</a></li> <li><a?href="list.html">人才招聘</a></li> </ul> </div> <div?class="nav_mid_right"> <form?action=""?method="post"> <input?type="text"?/> </form> </div> </div>? <div?class="nav_right"></div>? </div><!--nav結(jié)束--> </div><!--wrap結(jié)束--> </body> </html>
*{
margin: 0;
padding: 0;
font-size: 12px;
}
body{
background-color: #f5f5f5;?
}
.top{
width: 100%;
height: 27px;
background: url(../images/top_bg.jpg) repeat-x;
}
.top_content{
width: 1000px;
margin: 0 auto;
}
.top_content li{
list-style-image: url(../images/li_bg.gif);
float: right;
width: 70px;
line-height: 27px;
}
.top_content li:link, .top_content li:visited{
color: #8e8e8e;
text-decoration: none;
}
.top_content li:hover, .top_content li:active{
color:#900;
text-decoration: none;
}
.wrap{
width: 1000px;
margin: 0 auto;
}
.logo{
height: 80px;
background-color: #fff;
}
.logo_left{
width: 200px;
float: left;
}
.logo_right{
width: 300px;
float: right;
height: 28px;
margin-top: 30px;
color: #8e8e8e;
}
.logo_right img{
vertical-align: middle;
margin-right: 10px;
}
.tel{
font-family: "微軟雅黑";
font-size: 16px
color: #c00;
}
.nav{
height: 40px;
}
.nav_left{
width: 10px;
background: url(../images/nav_left.jpg) no-repeat;
}
.nav_mid{
width: 980px;
background: url(../images/nav_bg.jpg) repeat-x;
}
.nav_right{
width: 10px;
background: url(../images/nav_right.jpg) no-repeat;
}
.nav_left,.nav_mid,.nav_right{
float: left;
height: 40px;
}
2016-12-13
這可能是因?yàn)橛羞吙虻拇嬖?,input默認(rèn)有邊框的,總寬度超過1000了,你把nav_mid改小一點(diǎn),另外建議你把float:left放在上面。
2017-03-05
由于 img (也就是慕課網(wǎng)那個(gè) img )把父塊 div 撐大了 3px ,而父塊 div 又是向左浮動(dòng) ,所以后面的元素繼續(xù) 向左浮動(dòng)的時(shí)候,就頂?shù)搅? img的父塊div,所以沒有向左頂
到最左邊,而后面的導(dǎo)航條div因?yàn)殚L(zhǎng)度太長(zhǎng),自然就跳到了下一行,
解決方法:
1、給 父塊div?設(shè)置和 img 一樣的高度,這里就是? height: 80px;如圖,就可以了
2、給 img 設(shè)置 display: block;
3、給 img 設(shè)置 vertical-align: middle;
4、這個(gè)案例里具有特殊性,所以還有其他辦法,比如,給后面的元素 加 clear:left;? 原理就是后面元素往左浮動(dòng)的時(shí)候直接放在 img 父塊 div 的下面了,認(rèn)為這個(gè) img 把 div 撐大的幾 px 是存在的
(這是和其他四種方法不一樣的地方);
5、給包含慕課網(wǎng) img 父塊 div 的整個(gè)大盒子 div 加上 overflow: hidden; 原理:就是隱藏 img 父塊 div 溢出大盒子的部分;
當(dāng)然我是推薦 前3種方法的,動(dòng)的是元素本身,不大會(huì)對(duì)后續(xù)存在可能的影響;
2017-02-23
.logo{ height:80px; background-color:#FFF; overflow:hidden; } ?我的在這里加就不行,在下面加? clear:both;才解決的。為什么源碼下下來是運(yùn)行正常顯示。
.nav_left {
? ? clear:both;
width: 10px;
background: url(../images/nav_left.jpg) no-repeat;
}
2016-12-27
不太明白 我把mid改小了也還是不行咋辦吖?
2016-12-22
啥意思
2016-12-21
該課程中,慕課網(wǎng)首頁(yè)案例,把html4改為html5(就是文檔聲明修改了),為什么修改后布局就出錯(cuò)呢?