# [CSS]CSS notes ###### tags: `css` ## grid ### tuts https://www.daconote.com/css-gride-fr/ ## transform ### 移除transform ```css! .btn:disabled:active{ transform:none; } ``` ## var ### basics https://www.w3schools.com/css/css3_variables.asp ```css! :root { --blue: #1e90ff; --white: #ffffff; } body { background-color: var(--blue); } h2 { border-bottom: 2px solid var(--blue); } ``` ## 圖片相關 ### 圖片大小與比例調整: objec-fit https://www.w3schools.com/css/css3_object-fit.asp ## rwd相關 ### 根據寬度縮放文字 https://stackoverflow.com/questions/16056591/font-scaling-based-on-width-of-container ![](https://i.imgur.com/fxDxmB5.jpg) ## 尺寸相關 ### px與em的換算 http://www.flycan.com/article/css/css-em-to-px-87.html 網頁文字預設大小為16px 1em = 16px 線上換算 http://pxtoem.com/ ## flexbox相關 對齊flexbox item內的文字 https://stackoverflow.com/questions/25311541/how-to-vertically-align-text-inside-a-flexbox >將該item也設定為display:flex後 >再用align-items跟justify-content去對齊文字 ```css= *{ box-sizing: border-box; margin: 0px; padding: 0px; border: black solid 1px; } body{ border: rebeccapurple 2px solid; height: 300px; } .flex-container{ margin-top: 5%; margin-left: 5%; border: grey 1px solid; display: flex; flex-direction: row; height: 50%; width: 50%; align-items: center; /* justify-content: space-between; */ } .flex-container .flex-item{ border: black 1px solid; /* height: 20%; */ width: 100%; display: flex; align-items: center; justify-content: center; } .item1{ background-color: green; height: 50px; } .item2{ background-color: goldenrod; height: 20%; } .item3{ background-color: wheat; height: 80%; } ``` ```htmlmixed= <div class="flex-container"> <div class="flex-item item1"> <div>item1 txt</div> </div> <div class="flex-item item2">item2</div> <div class="flex-item item3">item3</div> </div> ``` ## 選擇器 ### 僅在按鈕為非disabled時才有hover效果 https://stackoverflow.com/questions/26754497/css-disable-hover-effect css ```css= .btnStart { /* 若按鈕為disabled,hover效果不作用 */ &:not(:disabled):hover{ background-color: rgb(110, 187, 189); color: #000; } ``` ## 對齊 ### 垂直置中 #### 絕對位置垂直置中 ```css! top:50%; transform: translateY(-50%); ``` ### 水平&垂直置中 ```css! position:absolute; transform:translate(-50%,-50%); ``` ### 水平置中 方1 ```css= margin: 20px auto ``` 方2 ```css= display:grid; place-items: center; ``` ### 使文字置中對齊 水平:text-center 垂直:line-height html ```htmlembedded= <div class="block">Click Me</div> ``` css ```css= .block{ width: 400px; height: 400px; line-height: 400px; text-align: center; } ```