css给div设置水平垂直居中并且给边框添加图片样式

代码如下:

<style type="text/css">
    .title{
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        width: 300px;
        height: 300px;
        font-size: 28px;
        text-align: center;
        line-height: 300px;
        border:15px solid transparent;
        -moz-border-image:url(./img/border.png) 30 30 round;    /* Old Firefox */
        -webkit-border-image:url(./img/border.png) 30 30 round;    /* Safari and Chrome */
        -o-border-image:url(./img/border.png) 30 30 round;        /* Opera */
        border-image:url(./img/border.png) 30 30 round;
    }
</style>
<div class="title" id="title">居中</div>

效果如图:

 

 注意:使用的图片要做处理,如下

 

posted @ 2021-02-03 10:17  是娜娜呀~  阅读(372)  评论(0)    收藏  举报