如何控制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;    }

效果如:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.