竹白記事本,學習紀錄,2019/03/15。
CSS SECRETS
css
Ch3 背景和邊框
border-radius
使用絕對數值表示時,需要隨著尺寸改變而修改,如果使用百分比,就會隨著尺寸自動調整。
水平半圓
width: 200px;
height: 100px;
border-radius: 50% / 100% 100% 0 0;
垂直半圓
width: 200px;
height: 100px;
border-radius: 100% 0 0 100% / 50%;
1/4 圓
width: 200px;
height: 100px;
border-radius: 100% 0 0 0;
如果使用 transform: skewX(-45deg)
來變形元素,雖然可以達到所要的效果,但裡面的內容也會變形。
在子元素加入一個反向的 transform: skewX(45deg)
,反轉變形。
.button {
background: #07434C;
transform: skewX(-45deg)
}
.button > div {
transform: skewX(45deg)
}
.button {
position: relative;
}
.button::before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
background: #07434C;
transform: skew(-45deg);
}
菱形圖片有以下兩種處理方式:
<div class="picture">
<img src="photo.jpg" alt="..." />
</div>
.picture {
width: 200px;
transform: rotate(45deg);
overflow: hidden;
}
.picture>img {
max-width: 100%;
transform: rotate(-45deg) scale(1.42);
}
clip-path
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
設計中常用的樣式。
linear-gradient
單一角
background: linear-gradient(-45deg, transparent 15px, #F2F3E9 0);
四角
background:
linear-gradient(135deg, transparent 15px, #F2F3E9 0) top left,
linear-gradient(-135deg, transparent 15px, #F2F3E9 0) top right,
linear-gradient(45deg, transparent 15px, #F2F3E9 0) bottom left,
linear-gradient(-45deg, transparent 15px, #F2F3E9 0) bottom right;
background-size: 50% 50%;
background-repeat: no-repeat;
background:
radial-gradient(circle at top left, transparent 15px, #F5B05E 0) top left,
radial-gradient(circle at top right, transparent 15px, #F5B05E 0) top right,
radial-gradient(circle at bottom left, transparent 15px, #F5B05E 0) bottom left,
radial-gradient(circle at bottom right, transparent 15px, #F5B05E 0) bottom right;
background-size: 50% 50%;
background-repeat: no-repeat;
clip-path
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);
不規則四邊形頁籤設計甚至比平行四邊形還來得常見。
方法與平行四邊形差不多,運用偽元素加上變形效果、圓角:
.tab {
position: relative;
display: inline-block;
padding: .5em 1em .35em;
font-size: 1.6em;
color: #FFF;
}
.tab::before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
border-radius: .5em .5em 0 0;
background: #99B58D;
transform: scaleY(1.3) perspective(.5em) rotateX(5deg);
transform-origin: bottom;
}
計時器、統計圖表都需要用到圓餅圖。