>  기사  >  웹 프론트엔드  >  CSS에서 테두리 길이 제어 기능을 구현하는 방법

CSS에서 테두리 길이 제어 기능을 구현하는 방법

王林
王林앞으로
2020-04-10 09:17:553816검색

CSS에서 테두리 길이 제어 기능을 구현하는 방법

과거에는 테두리 길이가 컨테이너보다 작아야 할 때 div 중첩을 사용했습니다. 나중에 나는 이 효과를 달성하는 데 의사 클래스가 매우 편리하다는 것을 알았습니다. 하나의 div만으로도 충분하며 패딩과 여백을 조정하는 것은 그다지 번거롭지 않습니다.

(추천 튜토리얼: CSS 입문 튜토리얼)

<div class="content-block">
<div class="box-container">
<div class="border-top">border top</div>
</div>
<div class="box-container">
<div class="border-left">border left</div>
</div>
<div class="box-container">
<div class="border-right">border right</div>
</div>
<div class="box-container">
<div class="border-bottom">border bottom</div>
</div>
</div>
.box-container {
    position: relative;
    width: 90%;
    color: #777;
}
.border-top {
    background: #b4bcbf;
    padding: 15px;
}
    .border-top:before {
        content: &#39;&#39;;
        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: &#39;&#39;;
        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: &#39;&#39;;
        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: &#39;&#39;;
        position: absolute;
        left: 18px;
        top: auto;
        bottom: 0;
        right: auto;
        height: 6px;
        width: 105px;
        background-color: #32b66b;
    }

효과는 다음과 같습니다:

CSS에서 테두리 길이 제어 기능을 구현하는 방법

추천 관련 비디오 튜토리얼: css 비디오 튜토리얼

위 내용은 CSS에서 테두리 길이 제어 기능을 구현하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 jb51.net에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제