1px解決方案--集錦

沒有廢話,直接上代碼react

匯聚各類版本,持續更新中。。。。web

1.sasssass

 1 @charset "utf-8";  2 /**  3  * @module 背景與邊框  4  * @description 爲元素添加邊框(包括1px邊框)  5  * @method border  6  * @version 2.0.0  7  * @param {String} $border-width 指定邊框厚度(單位爲px),默認值:1px,取值與`border-width`屬性一致,不一樣方向表明邊框位置 <2.0.0>  8  * @param {String} $border-color 指定邊框顏色 <2.0.0>  9  * @param {String} $border-style 指定邊框樣式 <2.0.0> 10  * @param {String} $radius 指定邊框圓角半徑,默認值:null <2.0.0> 11  */
12 @mixin border($border-width: 1px, $border-color: map-get($base, border-color), $border-style: solid, $radius: null) {
13  // 爲邊框位置提供定位參考 14  position: relative;
15  @if $border-width == null { 16  $border-width: 0;
17     }
18  border-radius: $radius; 19  &::after {
20  // 用以解決邊框layer遮蓋內容 21  pointer-events: none;
22  position: absolute;
23  z-index: 999;
24  top: 0;
25  left: 0;
26  // fix當元素寬度出現小數時,邊框可能顯示不全的問題 27  // overflow: hidden;
28  content: "\0020";
29  border-color: $border-color;
30  border-style: $border-style;
31  border-width: $border-width;
32  // 適配dpr進行縮放 33  @include responsive(retina1x) { 34  width: 100%;
35  height: 100%;
36  @if $radius != null { 37  border-radius: $radius;
38             }
39  } 40  @include responsive(retina2x) {
41  width: 200%;
42  height: 200%;
43  @include transform(scale(.5)); 44  @if $radius != null { 45  border-radius: $radius * 2;
46             }
47  } 48  @include responsive(retina3x) {
49  width: 300%;
50  height: 300%;
51  @include transform(scale(.33333)); 52  @if $radius != null { 53  border-radius: $radius * 3;
54             }
55  } 56  @include transform-origin(0 0); 57  } 58 }

2.stylusspa

border($border-width = 1px, $border-color = #ccc, $border-style = solid, $radius = 0) // 爲邊框位置提供定位參考 position: relative; if $border-width == null $border-width: 0; border-radius: $radius; &::after // 用以解決邊框layer遮蓋內容 pointer-events: none; position: absolute; z-index: 999; top: 0; left: 0; // fix當元素寬度出現小數時,邊框可能顯示不全的問題 // overflow: hidden; content: "\0020"; border-color: $border-color; border-style: $border-style; border-width: $border-width; // 適配dpr進行縮放 @media (max--moz-device-pixel-ratio: 1.49), (-webkit-max-device-pixel-ratio: 1.49), (max-device-pixel-ratio: 1.49), (max-resolution: 143dpi), (max-resolution: 1.49dppx) width: 100%; height: 100%; if $radius != null { border-radius: $radius;
      } @media (min--moz-device-pixel-ratio: 1.5) and (max--moz-device-pixel-ratio: 2.49), (-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 2.49),(min-device-pixel-ratio: 1.5) and (max-device-pixel-ratio: 2.49),(min-resolution: 144dpi) and (max-resolution: 239dpi),(min-resolution: 1.5dppx) and (max-resolution: 2.49dppx) width: 200%; height: 200%; transform: scale(.5) if $radius != null { border-radius: $radius * 2;
      } @media (min--moz-device-pixel-ratio: 2.5), (-webkit-min-device-pixel-ratio: 2.5),(min-device-pixel-ratio: 2.5), (min-resolution: 240dpi),(min-resolution: 2.5dppx) width: 300%; height: 300%; transform: scale(.33333) if $radius != null { border-radius: $radius * 3;
      } transform-origin: 0 0;

 3.react組件中3d

import styled from 'styled-components' const border = ({ component=null, width='1px', style='solid', color='#ccc', radius=0 }) => { return styled(component) ` position: relative; border-width: ${ width }; border-radius: ${ radius + 'px' }; &::after { pointer-events: none; position: absolute; z-index: 999; top: 0; left: 0; content: ""; border-color: ${ color }; border-style: ${ style }; border-width: ${ width }; @media (max--moz-device-pixel-ratio: 1.49), (-webkit-max-device-pixel-ratio: 1.49), (max-device-pixel-ratio: 1.49), (max-resolution: 143dpi), (max-resolution: 1.49dppx) { width: 100%; height: 100%; border-radius: ${ radius + 'px' }; }; @media (min--moz-device-pixel-ratio: 1.5) and (max--moz-device-pixel-ratio: 2.49), (-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 2.49), (min-device-pixel-ratio: 1.5) and (max-device-pixel-ratio: 2.49), (min-resolution: 144dpi) and (max-resolution: 239dpi), (min-resolution: 1.5dppx) and (max-resolution: 2.49dppx) { width: 200%; height: 200%; transform: scale(.5); border-radius: ${ radius * 2 + 'px'}; }; @media (min--moz-device-pixel-ratio: 2.5), (-webkit-min-device-pixel-ratio: 2.5), (min-device-pixel-ratio: 2.5), (min-resolution: 240dpi), (min-resolution: 2.5dppx) { width: 300%; height: 300%; transform: scale(.33333); border-radius: ${ radius * 3 + 'px' } }; transform-origin: 0 0; }; ` } export default border
相關文章
相關標籤/搜索