css3 斜切角/斜邊的實現方式來自BAT大神的出品


設計圖含有斜切角的效果時,我們一般想到的方法是切出四個角為背景,然后用border連起來,這樣就能顯示出該效果了,那么直接使用css呢?下面就整理css做斜邊的效果。

 

1、方案一:利用linear-gradient

.chamfer{
    background: #3b3; 
    background: linear-gradient(135deg, transparent 15px, #3b3 0) top left, 
			linear-gradient(-135deg, transparent 15px, #3b3 0) top right, 
			linear-gradient(-45deg, transparent 15px, #3b3 0) bottom right, 
			linear-gradient(45deg, transparent 15px, #3b3 0) bottom left; 	
    background-size: 50% 50%; 
    background-repeat: no-repeat;
}
</style>
<div class="chamfer" ></div>

資源網站搜索大全https://55wd.com

2、方案二:利用clip-path

<style>
.base{
	width: 300px;height: 300px;
}	
.chamfer{
	background: #009EEB; 
       clip-path: polygon( 20px 0, calc(100% - 20px) 0, 100% 20px, 
			100% calc(100% - 20px), calc(100% - 20px) 100%, 
			20px 100%, 
			0 calc(100% - 20px), 
			0 20px
   		);
}
</style>
<div class="chamfer"></div>

  

css曲線切口角的實現 

上面實現的2種切口是直線的,如何實現曲線切口角呢?下面就介紹利用radial-gradient實現曲線切口角:

<style>
.chamfer{
	background: #e72; 
        background: radial-gradient(circle at top left, transparent 15px, #e72 0) top left, 
			    radial-gradient(circle at top right, transparent 15px, #e72 0) top right, 
			    radial-gradient(circle at bottom right, transparent 15px,#e72 0) bottom right,
			    radial-gradient(circle at bottom left, transparent 15px, #e72 0) bottom left;
	background-size: 50% 50%; 
	background-repeat: no-repeat;
}
</style>
<div class="chamfer"></div>

  

使用Corner-shape

除了上面寫的方法外,我們還可以使用插件Corner-shape來實現,Corner-shape這個插件很有意思,能夠生成元素的角形狀,比如圓角、反向圓角、矩形、直角的邊角,使用SVG技術生成,使用上只需要設置預設的自定義屬性,然后設置圓角邊框的大小即可。 Corner-shape的使用鏈接:http://wenjiangs.com/wp-content/uploads/2017/06/corner-shape/

 例如:

corner-shape:bevel;
border-radius:10% / 30px;
width:400px;
height: 300px;

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM