【问题标题】:opacity background at bottom of div not attaching properlydiv底部的不透明背景未正确附加
【发布时间】:2014-02-27 19:23:54
【问题描述】:

我正在尝试创建一个可点击的图像,该图像的底部有文本,文本后面的背景设置为半透明度。在很多网站上都很常见。除了在文本背景下方伸出的图像长度的下唇之外,我还有这个工作。它似乎来自包含图像和锚点的li。我在网上搜索并尝试了几种方法来删除它,但都没有成功。

我怎样才能让我的文本的背景颜色整齐地适合我的图像底部?

<ul id='main-aside-buddhaImgs'>
    <li>
        <div class='titleCont'>
            <a href='#'><img src='images/squarebuddha.jpg' alt='budda' height='120' width='120'/>
                <span>title</span>
            </a>
        </div>
    </li> 


ul#main-aside-buddhaImgs {
    float:left;
}

ul#main-aside-buddhaImgs li {
    float:left;
    padding:12px 15px;
}

ul#main-aside-buddhaImgs li div.titleCont {
    position:relative;
}

ul#main-aside-buddhaImgs li a {
    display:block;
}

ul#main-aside-buddhaImgs li a span{
    display:block;
    position: absolute;
    bottom: 0;
    left:0;
    width:100%;
    color:#fc6;
    text-align: center;
    line-height: 30px;
    background: #300;
    background: rgba(51,0,0,.5);
} 

【问题讨论】:

    标签: html css opacity


    【解决方案1】:

    将 ul#main-aside-buddhaImgs li a span 的底部属性更改为 4px

    ul#main-aside-buddhaImgs li a span{
        display:block;
        position: absolute;
        bottom: 4px;
        left:0;
        width:100%;
        color:#fc6;
        text-align: center;
        line-height: 30px;
        background: #300;
        background: rgba(51,0,0,.5);
    } 
    

    http://jsfiddle.net/Kr5QP/

    【讨论】:

    • 哦,太好了!那里发生了什么,4px 是从哪里来的?
    • 你的a比你的图片高4px,绝对定位基于锚元素
    • 啊,我明白了,干杯。不想继续。为什么锚元素比图片高4px?
    • 不是 100% 肯定,但它外面的 div 和 li 元素也太
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2018-02-12
    • 1970-01-01
    • 2011-07-06
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    相关资源
    最近更新 更多