列表溢出問(wèn)題,以及項(xiàng)目圖片和文字不在一水平線
<!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=gb2312" />
<title>3.10新聞中心制作評(píng)測(cè)題</title>
<style type="text/css">
/*在此定義相關(guān)CSS樣式*/
.topList{
? ? width:300px;
? ? height:180px;
? ? border:1px solid #e8e8e8;
? ? margin:0 auto;
}
ul{
? ? list-style-type:none;
? ? padding:5px;
? ? font-size:12px;
? ? margin-top:-15px;
}
em{
? ? width:20px;
? ? height:16px;
? ? text-align:center;
? ? line-height:16px;
? ? font-style:normal;
? ? color:#333;
? ? background-image:url(http://img1.sycdn.imooc.com//53cf0fa20001d3dc00200032.jpg);
? ? background-position:bottom;
? ? display:block;
? ? float:left;
}
.top em{
? ? background-image:url(http://img1.sycdn.imooc.com//53cf0fa20001d3dc00200032.jpg);
? ? background-position:top;
? ? color:#fff;
}
a:link,a:visited{
? ? text-decoration:none;
? ? color:#888;
}
a:hover,a:active{
? ? color:#f00;
}
p{
? ? line-height:20px;
}
</style>
</head>
<body>
<div class="topList">
<ul>
<li class="top"><em>01</em>
<p><a href="http://idcbgp.cn/" >【慕客訪談?dòng)脩羝俊坝袨閷沤z”在路上</a></p>
</li>
<li class="top"><em>02</em>
<p><a href="http://idcbgp.cn/">【有獎(jiǎng)活動(dòng)】給父親的三行書信</a></p>
</li>
<li class="top"><em>03</em>
<p><a href="http://idcbgp.cn/">《程序猿,請(qǐng)曬出你的童年》活動(dòng)獲獎(jiǎng)公告</a></p>
</li>
<li><em>04</em>
<p><a href="http://idcbgp.cn/">【慕課訪談】破繭成蝶——美女程序員的蛻變史</a></p>
</li>
<li><em>05</em>
<p><a href="http://idcbgp.cn/">【獲獎(jiǎng)公告】追“球”巔峰,爭(zhēng)當(dāng)“預(yù)言帝”</a></p>
</li>
<li><em>06</em>
<p><a href="http://idcbgp.cn/">【問(wèn)卷調(diào)查】慕課網(wǎng)用戶學(xué)習(xí)情況大調(diào)查</a></p>
</li>
</ul>
</div>
</body>
上圖為例子
上圖為我寫的代碼成像。
寫完代碼后,發(fā)現(xiàn)p標(biāo)簽中的文字和左邊的項(xiàng)目符號(hào)背景圖不在一水平線上,使用line-height來(lái)保持一水平線,但是列表就溢出topList
于是,使用margin的負(fù)值。
但總覺(jué)得這樣的方法不好,求指教
2016-08-15
將p設(shè)置左浮動(dòng)
2016-03-28
*{
? ? padding:0;
? ? margin:0;
? ? }
.topList{
? ? width:300px;
? ? height:180px;
? ? border:1px solid #e8e8e8;
? ? margin:5px auto;
}
ul{
? ? list-style:none;
? ? padding:5px;
}
ul li{
? ?height:30px;?
}
a{
? ? text-decoration:none;
? ? font-size:12px;
}
a:link,a:visited{
? ? color:#333;
}
a:hover,a:active{
? ? color:red;
}
em{ ??
? ? width:20px;
? ? height:16px;
? ? text-align:center;
? ? font-style:normal;
? ? color:#000;
? ? background:url(http://img.imooc.com/53cf0fa20001d3dc00200032.jpg);
? ? background-position:0 16px;
? ? float:left;
? ? line-height:16px;
? ? display:block;?
? ? font-size:12px;
}
.top em{
? ? background:url(http://img.imooc.com/53cf0fa20001d3dc00200032.jpg);
? ? background-position:16px 0;
? ? color:#fff;
}
完美的答案?。?!
2016-03-01
<!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=gb2312" />
<title>3.10新聞中心制作評(píng)測(cè)題</title>
<style type="text/css">
/*在此定義相關(guān)CSS樣式*/
.topList{
??? width:300px;
??? height:180px;
??? border:1px solid #E8E8E8;
}? ?
.topList ul{
??? list-style:none;
??? padding:5px;
??? font-size:12px;
}
.topList em{
??? width:20px;
??? height:16px;
??? font-style:normal;
??? color:#333;
??? background:url("http://img1.sycdn.imooc.com//53cf0fa20001d3dc00200032.jpg");
??? background-position:0 16px;
??? float:left;
??? text-align:center;
}
.topList .top em{
???? background:url("http://img1.sycdn.imooc.com//53cf0fa20001d3dc00200032.jpg");
??? background-position:16px 0;
??? color:#fff;?? ?
}
.topList a:link,.topList a:visited{
??? text-decoration:none;
??? color: #000;
}
.topList a:hover,.topList a:actiove{
??? text-decoration:none;
??? color: #f00;
}
</style>
</head>
<body>
<div class="topList">
<ul>
<li class="top"><em>01</em>
<p><a href="http://idcbgp.cn/" >【慕客訪談?dòng)脩羝俊坝袨閷沤z”在路上</a></p>
</li>
<li class="top"><em>02</em>
<p><a href="http://idcbgp.cn/">【有獎(jiǎng)活動(dòng)】給父親的三行書信</a></p>
</li>
<li class="top"><em>03</em>
<p><a href="http://idcbgp.cn/">《程序猿,請(qǐng)曬出你的童年》活動(dòng)獲獎(jiǎng)公告</a></p>
</li>
<li><em>04</em>
<p><a href="http://idcbgp.cn/">【慕課訪談】破繭成蝶——美女程序員的蛻變史</a></p>
</li>
<li><em>05</em>
<p><a href="http://idcbgp.cn/">【獲獎(jiǎng)公告】追“球”巔峰,爭(zhēng)當(dāng)“預(yù)言帝”</a></p>
</li>
<li><em>06</em>
<p><a href="http://idcbgp.cn/">【問(wèn)卷調(diào)查】慕課網(wǎng)用戶學(xué)習(xí)情況大調(diào)查</a></p>
</li>
</ul>
</div>
</body>