微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

以条纹虚线作为背景

如何解决以条纹虚线作为背景

是否可以仅使用 CSS 获得这种条纹和虚线背景?

enter image description here

背景是 Chrome 在检查 flex 元素时创建的,我觉得它真的很酷。

解决方法

您可以像这样使用 repeating-linear-gradient

body {
  padding: 0;
  margin: 0;
  height: 100vh;
  width: 100w;
  background: repeating-linear-gradient(
    45deg,tomato 0px,tomato 2px,transparent 2px,transparent 9px
  );
}
div {
  height: 100vh;
  width: 100vw;
  background: repeating-linear-gradient(
    -45deg,white 0px,white 4px,transparent 4px,transparent 12px
  );
}
<div></div>

Tweak with the code

这几行确实产生了一些相似的图案,但在低 DPI 屏幕上看起来不太好。因此,在我看来,最好使用 SVG 模式而不是纯 CSS。

,

你可以使用repeating-linear-gradient,但我不能让它变成虚线:

//Example
body,html {
  background: repeating-linear-gradient(
      -55deg,#606dbc,#606dbc 5px,#465298 5px,#465298 10px
   );
}

,

这是我的问题的 SVG 解决方案。 CSS 看起来不太好。

<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
    
  <!-- Let's define the pattern -->
  <!-- The width and height should be double the size of a single checker -->
  <pattern id="pattern-checkers" x="0" y="0" width="100%" height="15" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
    <!-- Two instances of the same checker,only positioned apart on the `x` and `y` axis -->
    <!-- We will define the `fill` in the CSS for flexible use -->
  <line x1="0" y1="7" x2="100%" y2="7" stroke="#F3817F"
          stroke-dasharray="8 4" />
  </pattern>
  
  <!-- Define the shape that will contain our pattern as the fill -->
  <rect x="0%" y="0" width="100%" height="100%" fill="url(#pattern-checkers)"></rect>
  
</svg>
,

我建议使用图案来创造美妙的背景:http://projects.verou.me/css3patterns/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?