第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

如何讓導(dǎo)航條居中?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>導(dǎo)航菜單</title>

<style type="text/css">

*{margin:0 ; padding:0; font-size:14px;}

.a{margin:0 auto;width:100%;}

ul{ list-style:none;}

a{color:#333;text-decoration:none}

.nav{margin:0 auto;width:800px;}

.nav li{ float:left;}

.nav li a{ display:block; text-align:center; height:30px; line-height:30px; width:100px; background-color:#efefef; margin-left:1px;}

.nav li a:hover{ background-color:#F60; color:#fff}

</style>


</head>

<body>


<ul class="nav">

? ? <li><a href="#">首  頁</a></li>

? ? <li><a href="#">新聞快訊</a></li>

? ? <li><a href="#">產(chǎn)品展示</a></li>

? ? <li><a href="#">售后服務(wù)</a></li>

? ? <li><a href="#">聯(lián)系我們</a></li>

? </ul>


</body>

</html>


正在回答

4 回答

兩種方法,定寬:

<style?type="text/css">
*{margin:0?;?padding:0;?font-size:14px;}
a{color:#333;text-decoration:none}
ul.nav?{
????list-style:?none;
????width:?500px;
????margin:?0?auto;
????}
.nav?li{?
????float:left;
????}
.nav?li?a{?display:block;?text-align:center;?height:30px;?line-height:30px;?width:100px;?background-color:#efefef;}
.nav?li?a:hover{?background-color:#F60;?color:#fff}
</style>

不定寬:

<style?type="text/css">
*{margin:0?;?padding:0;?font-size:14px;}
a{color:#333;text-decoration:none}
ul.nav?{
????list-style:?none;
????float:?left;
????position:?relative;
????left:?50%;
}
.nav?li{?
????float:left;
????position:?relative;
????left:?-50%;
}
.nav?li?a{?display:block;?text-align:center;?height:30px;?line-height:30px;?width:100px;?background-color:#efefef;}
.nav?li?a:hover{?background-color:#F60;?color:#fff}
</style>

你的代碼里?.a{margin:0 auto;width:100%;} 這一行沒作用,雖然 a 設(shè)置為 block 了,但 a 的父元素是 li ,這樣設(shè)置最多讓 a 在 li 中居中,而不是 ul 整體居中。

至于你問為什么 800px 不行,其實(shí) 800px 是可以的,你的代碼其實(shí)是有居中效果的,只是 ul 的寬度為 800px,而 li 總共寬度只有 505px,所以最右邊的 295px 是透明的,看不見,你可以給 ul 設(shè)置一個(gè)高度,再設(shè)置一個(gè)背景色,你就能看出來,ul 其實(shí)已經(jīng)居中了。


3 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕先生8224389 提問者

謝謝謝謝
2016-09-27 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慕粉3951534 回復(fù) 慕先生8224389 提問者

求采納~~
2016-09-27 回復(fù) 有任何疑惑可以回復(fù)我~
#3

慕先生8224389 提問者

非常感謝!
2016-09-27 回復(fù) 有任何疑惑可以回復(fù)我~
#4

慕粉3951534 回復(fù) 慕先生8224389 提問者

共勉,哈哈
2016-09-27 回復(fù) 有任何疑惑可以回復(fù)我~
#5

慕仰0608257

謝謝謝謝謝謝
2017-02-13 回復(fù) 有任何疑惑可以回復(fù)我~
查看2條回復(fù)

先將ul設(shè)置成塊狀元素,定寬;然后用margin:auto進(jìn)行居中

0 回復(fù) 有任何疑惑可以回復(fù)我~

實(shí)現(xiàn)網(wǎng)頁自動(dòng)居中一列布局的關(guān)鍵代碼是margin:0 auto;width:XXpx;

width自己看著設(shè)計(jì)

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕先生8224389 提問者

。。。
2016-09-19 回復(fù) 有任何疑惑可以回復(fù)我~

.nav ?其實(shí)已經(jīng)居中了的。 ?只是 li 從左往右 排列,排列完 右邊還有多余而已,你要是強(qiáng)迫癥牛逼。

你可以設(shè)置 ?.nav{margin:0 auto;width:505px;} ?這樣就居中了

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕先生8224389 提問者

800px為什么不行啊
2016-09-19 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
導(dǎo)航條菜單的制作
  • 參與學(xué)習(xí)       123855    人
  • 解答問題       838    個(gè)

水平、垂直、圓角導(dǎo)航條菜單,讓您的技術(shù)探索之路更高效

進(jìn)入課程

如何讓導(dǎo)航條居中?

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)