我有一个 <ul>
在我的网站上,结构与此几乎相同:http://jsfiddle.net/tRzPH/1/
链接是带有蓝色边框的部分。我想让它做的是一直延伸到左右的绿色边框,以及顶部和底部的橙色边框。但当然,保持实际文本内容的位置。
我不确定该怎么做,尤其是因为 anchor 不应该是列表项的父元素。
有什么建议吗?
最佳答案
如果我没理解错的话,这就是您想要完成的,对吧?你需要一点 jQuery http://jsfiddle.net/elclanrs/tJ3kv/
html:
<ul>
<li><a href="#">
<h2>item1</h2>
<p>Lorem Ipsum Dolor Sit Amet</p>
</a></li>
<li><a href="#">
<h2>item2</h2>
<p>Lorem Ipsum Dolor Sit Amet</p>
</a></li>
<li><a href="#">
<h2>item3</h2>
<p>Lorem Ipsum Dolor Sit Amet</p>
</a></li>
</ul>
CSS:
body { margin: 50px; }
ul {
border: 1px solid orange;
overflow: hidden;
display: inline-block;
}
h2 {
font-size: 24px;
font-weight: bold;
}
li {
float: left;
width: 150px;
border-right: 1px solid green;
}
li:last-child { border: 0; }
a {
display: block;
border: 1px solid blue;
margin: 4px;
padding: 1em;
color: black;
text-decoration: none;
}
jQ:
var getMaxHeight = function ($elms) {
var maxheight = 0;
$elms.each(function () {
if ($(this).height() > maxheight) {
maxheight = $(this).height();
}
});
return maxheight;
};
var $elms = $('ul li a');
$elms.height(getMaxHeight($elms));
关于html - 让 anchor 击区域覆盖父元素填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9746093/