有锚点击区域覆盖父元素填充

时间:2012-03-17 00:15:51

标签: html css html5 css3 css-float

我的网站上有<ul>,其结构与此非常相似:http://jsfiddle.net/tRzPH/1/

链接是带有蓝色边框的部分。我试图让它做的是一直延伸到左右绿色边框,以及顶部和底部的橙色边框。但当然,保持实际文本内容的位置。

我不知道该怎么做,特别是因为锚点不应该是列表项的父元素。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

如果我理解正确,这就是你想要完成的事情,对吧?你需要一些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));