如何控制CSS邊框長度的範例程式碼分享

來源:互聯網
上載者:User

CSS邊框長度控制

CSS邊框長度控制。以前需要邊框長度比容器小一些時,我用p嵌套。後來發現偽類在實現這個效果時很方便,只需要一個p就夠了,另外調整padding和margin都不會很麻煩。

border top

border left

border right

border bottom

.box-container {    position: relative;    width: 90%;    color: #777;}.border-top {    background: #b4bcbf;    padding: 15px;}    .border-top:before {        content: '';        position: absolute;        left: 42%;        top: 0;        bottom: auto;        right: auto;        height: 7px;        width: 50%;        background-color: #8796a9;    }.border-left {    background: #dfdad6;    padding: 15px;}    .border-left:before {        content: '';        position: absolute;        left: 0;        top: 6%;        bottom: auto;        right: auto;        height: 52%;        width: 5px;        background-color: #a89d9e;    }.border-right {    background: #eee9c4;    padding: 15px;}    .border-right:after {        content: '';        position: absolute;        left: auto;        top: auto;        bottom: 5px;        right: 0;        height: 52%;        width: 5px;        background-color: #f39c81;    }.border-bottom {    background: #bcdc9d;    padding: 15px;}    .border-bottom:after {        content: '';        position: absolute;        left: 18px;        top: auto;        bottom: 0;        right: auto;        height: 6px;        width: 105px;        background-color: #32b66b;    }

效果如:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.