Web前端-css7--透明 居中

透明度

  透明的使用方式:
           通过背景色的透明:background-color  rgba
                             只是设置元素的背景 但是内容能够展示
           元素的透明  : opacity   0~1
                           让当前的标签连带内部所有都透明
                           css 中的 .5  === 0.5

    <style>
        div {
            width: 400px;
            height: 350px;
            border: 1px solid #000;
            margin-bottom: 10px;
            background-image: url("image1/qq.jpg");
        }

        div > span {
            font-size: 40px;
            font-weight: bold;
            background-color: #f00;
        }

        div.a > span {
            background-color: rgba(0, 0, 0, 0);
        }

        /*div.b > span {*/
            /*opacity: 0;*/
        /*}*/

        div.b{
            /*opacity: 0.5;*/
            opacity: .5;
        }

    </style>

绝对居中

 让子元素在父元素中绝对居中 展示

 <style>
        .box{
            width: 800px;
            height: 600px;
            border: 1px solid #000;
            background-color: #ccc;
            margin: 20px auto;
            position: relative;
        }
        .tag{
            width: 200px;
            height: 200px;
            background-color: #0ff;
            border: 1px solid #000;
            position: absolute;
            top: 0;
            bottom: 0;
            right: 0;
            left: 0;
            margin: auto;
        }
        
        
    </style>

1 让内容在 元素中  居中

<style>
#t1{
border: 1px solid #000;
background-color: #ccc;
height: 200px;

text-align: center;
line-height: 200px;
}

</style>
<div id="t1">我是div</div>

2 让行内 与行内块  在父元素中居中   text-align


    img 可以通过 text-align 设置左右居中  但是没有上下居中 若想让img 在与元素中绝对居中  外包裹一个块 position
    img 的水平居中不能使用margin : auto 因为margin 是块元素的使用方式

<style>
    .t1, .t2 {
        height: 300px;
        border: 1px solid #000;
        background-color: #ccc;
        text-align: center;
        line-height: 300px;
    }

</style>
<div class="t1">
    <img src="200.jpg" alt="">
</div>
<div class="t2">
    <span>我是 div 中的span 中的内容</span>
</div>

3 块元素的居中

<style>
     .t1{
         height: 300px;
         background-color: #ccc;
         border: 1px solid #000;
         position: relative;
     }
    .t2{
        width: 200px;
        height: 200px;
        border: 1px solid #000;
        background-color: #0ff;
        margin:  auto;

        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
    }

</style>
<div class="t1">
     <div class="t2"></div>
</div>
发布了26 篇原创文章 · 获赞 4 · 访问量 426

猜你喜欢

转载自blog.csdn.net/yanghainan0318/article/details/103439278