css绝对定位后居中显示文字

来源:互联网 发布:ip网络功放 编辑:程序博客网 时间:2024/05/16 01:32

在图片底部居中显示文字,直接上代码:

<style>    .main {        width:300px;        height:200px;        text-align:center;    }    .title {        position:absolute;        width:300px;        height:20px;        left: 0;        right: 0;        bottom: 0;        background-color:rgba(0,0,0,0.5);    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#7f000000,endColorstr=#7f000000);    }    #设置背景半透明并兼容ie浏览器</style><div class="main">    <img src="1.png" />    <p class="title">我要在图片底部居中显示</p>    </div>

效果如图这里写图片描述