我正在尝试制作一个框,使其右下边框必须为对角线,如下图所示:



有谁知道我不使用背景图片怎么办?

最佳答案

示例1-link



* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    padding: 20px 60px;
}

.btn,
.btn span{
    width: 300px;
    height: 100px;
    display: inline-block;
    position: relative;
    color: #e74c3c;
    font: bold 18px/100px'segoe ui';
    text-transform: uppercase;
    text-align: center;
    text-decoration: none;
    overflow: hidden;
    padding: 2px;
}
.btn span {
    width: 100%;
    height: 100%;
}
.btn:before,
.btn span:before{
    content:'';
    position: absolute; right: -500%;
    width: 1100%;
    height: 1100%;
    background: #c00;
    z-index: -1;
}

.btn:hover span{
    color: #000;
}
.btn:hover:before{
    background: #000;
}



/* ----- btn-left-top ----- */
.btn-left-top:before,
.btn-left-top span:before{
    top: 20px;
    -webkit-transform-origin: 46% top;
    -ms-transform-origin: 46% top;
    transform-origin: 46% top;
    -webkit-transform: rotate(-45deg);
    -ms-transform: rotate(-45deg);
    transform: rotate(-45deg);
}
.btn-left-top span:before{
    top: 19px;
    background: #fff;
}



/* ----- btn-left-bottom ----- */
.btn-left-bottom:before,
.btn-left-bottom span:before{
    bottom: 20px;
    -webkit-transform-origin: 46% bottom;
    -ms-transform-origin: 46% bottom;
    transform-origin: 46% bottom;
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
}
.btn-left-bottom span:before{
    bottom: 19px;
    background: #fff;
}



/* ----- btn-right-top ----- */
.btn-right-top:before,
.btn-right-top span:before{
    top: 20px;
    -webkit-transform-origin: 54% top;
    -ms-transform-origin: 54% top;
    transform-origin: 54% top;
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
}
.btn-right-top span:before{
    top: 19px;
    background: #fff;
}


/* ----- btn-right-bottom ----- */
.btn-right-bottom:before,
.btn-right-bottom span:before{
    bottom: 20px;
    -webkit-transform-origin: 54% bottom;
    -ms-transform-origin: 54% bottom;
    transform-origin: 54% bottom;
    -webkit-transform: rotate(-45deg);
    -ms-transform: rotate(-45deg);
    transform: rotate(-45deg);
}
.btn-right-bottom span:before{
    bottom: 19px;
    background: #fff;
}

<a href="#" class="btn btn-left-top">
    <span>btn-left-top</span>
</a>

<a href="#" class="btn btn-right-top">
    <span>btn-right-top</span>
</a>

<a href="#" class="btn btn-right-bottom">
    <span>btn-right-bottom</span>
</a>


<a href="#" class="btn btn-left-bottom">
    <span>btn-left-bottom</span>
</a>





示例2-link



* {
  	margin: 0;
  	padding: 0;
}

body {
    padding: 20px 60px;
}

.btn{
    width: 300px;
    height: 100px;
    display: inline-block;
    position: relative;
    border: 4px solid #e74c3c;
    color: #e74c3c;
    font: bold 18px/100px 'segoe ui';
    text-transform: uppercase;
    text-align: center;
    text-decoration: none;
}
.btn > span:before {
    content: '';
    position: absolute; bottom: 12px; right: 9px;
    width: 66px;
    height: 66px;
    transform: rotate(45deg);
    z-index: 1;
    border-right: 4px solid #e74c3c;
}
.btn:before,
.btn:after{
    content: '';
    position: absolute; bottom: -4px; right: -4px;
}
.btn:before{
    width: 47px;
    height: 0;
    border-bottom: 4px solid #fff;
}
.btn:after{
    width: 0;
    height: 47px;
    border-right: 4px solid #fff;
}
.btn:hover{
    border: 4px solid #4169E1;
    color: #4169E1;
}
.btn:hover > span:before{
    border-right: 4px solid #4169E1;
}

<a href="#" class="btn">
    <span>test</span>
</a>





Fiddle

关于css - CSS3对 Angular 边界线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31785198/

10-09 09:59