1. 使用 border 属性:
.dashed-border {
border: 1px dashed #000;
}
2. 使用 background-image 属性:
.dashed-background {
background-image: repeating-linear-gradient(0deg, #000, #000 1px, transparent 1px, transparent 2px);
}
3. 使用 ::before 伪元素:
.dashed-before {
position: relative;
}
.dashed-before::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border: 1px dashed #000;
}
CSS 虚线应用实例:
1. 虚线边框:
.dashed-border {
border: 1px dashed #000;
}
2. 虚线背景:
.dashed-background {
background-image: repeating-linear-gradient(0deg, #000, #000 1px, transparent 1px, transparent 2px);
}
3. 虚线分隔线:
.dashed-separator {
border-top: 1px dashed #000;
}
4. 虚线按钮效果:
.dashed-button {
border: 1px dashed #000;
padding: 5px 10px;
text-align: center;
cursor: pointer;
}
5. 虚线框架/容器:
.dashed-container {
position: relative;
}
.dashed-container::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border: 1px dashed #000;
}
请根据具体需求选择适合的方法和样式,这些示例可以在不同场景中用于创建虚线效果。虚线可以用于增强视觉分隔、突出元素等设计效果。
转载请注明出处:http://www.zyzy.cn/article/detail/4046/CSS