国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

css實現各種0.5px的線(小結)

2024-07-11 08:25:19
字體:
來源:轉載
供稿:網友

在PC端用1px的邊框線,看起來還好,但在手機端看起來就很難看了,而0.5px的分割線會有種精致的感覺。用普通寫法border:solid 0.5px red;iPhone可以正常顯示,android下幾乎所有的瀏覽器都會把0.5識別為0,即無邊框狀態.

原理

原理就是給需要加邊框的元素插入一個偽類,偽類采用絕對定位,然后對偽類添加1px邊框,最后進行0.5倍縮放。

transform的縮放和旋轉默認都是按照元素的中心點來操作的

outline元素在縮放0.5之前尺寸就是紅框元素,縮放后,位置到了紅框中心,為了使之依然在左上角,縮放之前我們需進行left:-50%;top:-50%的位移。

0.5px邊框

<div class="first"> <div class="first-div"> HELLO WORLD </div></div><style>.first{ position: relative; font-size: 16px;}.first .first-div:before{ content: ""; position: absolute; top: -50%; bottom: -50%; left: -50%; right: -50%; width: 200%; height: 200%; -webkit-transform: scale(0.5); transform: scale(0.5); border: solid 1px red; box-sizing:border-box;}</style>

副作用

當用偽類的絕對定位來實現了邊框后,我們在first類和first-div類上的點擊事件會失效,因為此時的偽類是絕對定位,而且長寬等于父類元素的長寬,是脫離了文檔流覆蓋在父類上的,偽類不是真實的DOM元素,沒有js點擊事件

解決方案

再寫一個絕對定位元素,覆蓋在父元素上,層級優先級要高一點

<div class="first"> <div class="first-div"> HELLO WORLD </div> <div class="click-able" onclick="alert('click')"></div></div><style>.first{ position: relative; font-size: 16px;}.first .first-div:before{ content: ""; position: absolute; top: -50%; bottom: -50%; left: -50%; right: -50%; width: 200%; height: 200%; -webkit-transform: scale(0.5); transform: scale(0.5); border: solid 1px red; box-sizing:border-box;}.click-able{ position: absolute; top: 0; bottom: 0; left: 0; right: 0; z-index: 10;} </style>

0.5px圓角邊框

<div class="round"> <div class="round-div"> HELLO WORLD </div></div><style>.round{ position: relative; font-size: 16px; }.round .round-div:before{ content: ""; position: absolute; top: -50%; bottom: -50%; left: -50%; right: -50%; width: 200%; height: 200%; -webkit-transform: scale(0.5); transform: scale(0.5); border: solid 1px red; border-radius: 22px; box-sizing:border-box;}</style>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 连南| 余庆县| 米林县| 无锡市| 岚皋县| 南雄市| 灵丘县| 南郑县| 陈巴尔虎旗| 昌宁县| 乌什县| 桦甸市| 兴国县| 监利县| 内黄县| 阿拉善盟| 留坝县| 诏安县| 如皋市| 江口县| 定襄县| 连州市| 大石桥市| 汽车| 资兴市| 托克逊县| 开远市| 葵青区| 乐山市| 大余县| 青冈县| 威海市| 广汉市| 乌恰县| 乐昌市| 新宾| 高淳县| 天台县| 荔浦县| 荔浦县| 图木舒克市|