在html图片上方叠加一个半透明颜色层,并在半透明颜色层上叠加文字

话不多说,直接看代码,效果

效果图:

html代码

<div class="bg_img">
    <!--图片-->
    <img src="../photo/8_cont1_6.jpg" height="152" width="225"/>
    <!--span标签 半透明背景层-->
    <span class="ms">span标签</span>
    <!--div标签 半透明背景层-->
    <div class="toumingzi">div标签</div>
</div>

Css代码

.bg_img {
    /*相对位置*/
    position: relative;
    width: 225px;
    height: 152px;
}

.ms {
    /*绝对位置*/
    position: absolute;
    background: #a82327;
    /*透明度*/
    opacity: 0.8;
    /*span标签的大小*/
    width: 225px;
    height: 20px;
    /*偏移到div上*/
    left: 0;
    /*span标签下移*/
    bottom: 0.1px;
    text-align: center;
    color: white;

    /*copy的别人的代码,我没用到,我没深究其意 */
    /*filter:alpha(opacity=60);*/
    /*-moz-opacity:0.6;*/
}

.toumingzi {
    position: absolute;
    background: cornflowerblue;
    /*透明度*/
    opacity: 0.8;
    /*字体居中*/
    text-align: center;
    /*div标签上移*/
    top: 0.1px;
    width: 225px;
    height: 20px;
}

 

  • 7
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值