视网膜上 1px 实现
使用到的技术
- background-image
- scale
// 1px on Retina
// -----------------------------------------------------------------------------
.retina(@top: transparent, @right: transparent, @bottom: transparent, @left: transparent, @w: 1px) {
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
border: none;
background-image:
-webkit-linear-gradient(270deg, @top, @top 50%, transparent 50%),
-webkit-linear-gradient(180deg, @right, @right 50%, transparent 50%),
-webkit-linear-gradient(90deg, @bottom, @bottom 50%, transparent 50%),
-webkit-linear-gradient(0, @left, @left 50%, transparent 50%);
background-image:
-moz-linear-gradient(270deg, @top, @top 50%, transparent 50%),
-moz-linear-gradient(180deg, @right, @right 50%, transparent 50%),
-moz-linear-gradient(90deg, @bottom, @bottom 50%, transparent 50%),
-moz-linear-gradient(0, @left, @left 50%, transparent 50%);
background-image:
-o-linear-gradient(270deg, @top, @top 50%, transparent 50%),
-o-linear-gradient(180deg, @right, @right 50%, transparent 50%),
-o-linear-gradient(90deg, @bottom, @bottom 50%, transparent 50%),
-o-linear-gradient(0, @left, @left 50%, transparent 50%);
background-image:
linear-gradient(180deg, @top, @top 50%, transparent 50%),
linear-gradient(270deg, @right, @right 50%, transparent 50%),
linear-gradient(0deg, @bottom, @bottom 50%, transparent 50%),
linear-gradient(90deg, @left, @left 50%, transparent 50%);
background-size: 100% @w, @w 100%, 100% @w, @w 100%;
background-repeat: no-repeat;
background-position: top, right top, bottom, left top;
}
}
.top-1px(@color: transparent, @w: 1px) {
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
border: none;
background-image: -webkit-linear-gradient(270deg, @color, @color 50%, transparent 50%);
background-image: -moz-linear-gradient(270deg, @color, @color 50%, transparent 50%);
background-image: -o-linear-gradient(270deg, @color, @color 50%, transparent 50%);
background-image: linear-gradient(180deg, @color, @color 50%, transparent 50%);
background-size: 100% @w;
background-repeat: no-repeat;
background-position: top;
}
}
.right-1px(@color: transparent, @w: 1px) {
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
border: none;
background-image: -webkit-linear-gradient(180deg, @color, @color 50%, transparent 50%);
background-image: -moz-linear-gradient(180deg, @color, @color 50%, transparent 50%);
background-image: -o-linear-gradient(180deg, @color, @color 50%, transparent 50%);
background-image: linear-gradient(90deg, @color, @color 50%, transparent 50%);
background-size: @w 100%;
background-repeat: no-repeat;
background-position: right;
}
}
.bottom-1px(@color: transparent, @w: 1px) {
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
border: none;
background-image: -webkit-linear-gradient(90deg, @color, @color 50%, transparent 50%);
background-image: -moz-linear-gradient(90deg, @color, @color 50%, transparent 50%);
background-image: -o-linear-gradient(90deg, @color, @color 50%, transparent 50%);
background-image: linear-gradient(0, @color, @color 50%, transparent 50%);
background-size: 100% @w;
background-repeat: no-repeat;
background-position: bottom;
}
}
.left-1px(@color: transparent, @w: 1px) {
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
border: none;
background-image: -webkit-linear-gradient(0deg, @color, @color 50%, transparent 50%);
background-image: -moz-linear-gradient(0deg, @color, @color 50%, transparent 50%);
background-image: -o-linear-gradient(0deg, @color, @color 50%, transparent 50%);
background-image: linear-gradient(270deg, @color, @color 50%, transparent 50%);
background-size: @w 100%;
background-repeat: no-repeat;
background-position: left;
}
}
.border-1px(@ratio: 2, @color, @radius: 0) {
position: relative;
border: none !important;
&::after {
content: '';
position: absolute;
left: 0;
top: 0;
right: (1 - @ratio) * 100%;
bottom: (1 - @ratio) * 100%;
border: 1px solid @color;
border-radius: @radius;
.transform(scale(1 / @ratio));
.transform-origin(0 0);
pointer-events: none;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: GitHub Git 备忘单
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论