Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

求教诸位一个关于css的小问题,详见描述?

小弟不才,偶然间浏览菜鸟驿站的CSS 图像拼合技术,下面代码都看的懂。但是有一点不明,望诸位指教

网址是https://www.runoob.com/try/tr...
==========
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title>  
<style>
#navlist{position:relative;}
#navlist li{margin:0;padding:0;list-style:none;position:absolute;top:0;}
#navlist li, #navlist a{height:44px;display:block;}

#home{left:0px;width:46px;}
#home{background:url('/images/img_navsprites.gif') 0 0;}

#prev{left:63px;width:43px;}
#prev{background:url('/images/img_navsprites.gif') -47px 0;}

#next{left:129px;width:43px;}
#next{background:url('/images/img_navsprites.gif') -91px 0;}
</style>
</head>

<body>
<ul id="navlist">
  <li id="home"><a href="/"></a></li>
  <li id="prev"><a href="/css/"></a></li>
  <li id="next"><a href="/css/"></a></li>
</ul>
</body>
</html>

这个

#navlist li, #navlist a{height:44px;display:block;} 

中的

display:block;

令小弟百思不得其解,当然 a标签和img都是内联元素,li本身就是块状元素。当去除display:block;之后,链接就打不开了。求指教


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

当去除display:block;之后a标签变成了inline元素,给它指定的高度#navlist a{height:44px;}变成无效的,因为本身没有子元素,所以标签a的宽高都是0。此时根本点不到a标签,所以“链接就打不开了”。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...