This trick works for both horizontal and vertical borders:

background-image: linear-gradient(to right, black 33%, rgba(255,255,255,0) 0%);
background-position: bottom;
background-size: 3px 1px;
background-repeat: repeat-x;

background-image: linear-gradient(black 33%, rgba(255,255,255,0) 0%);
background-position: right;
background-size: 1px 3px;
background-repeat: repeat-y;

You can adjust the size with background-size and the proportion with the linear-gradient percentages. In this example I have a dotted line of 1px dots and 2px spacing. This way you can have multiple dotted borders too using multiple backgrounds.

Try it in this JSFiddle or take a look at the code snippet example:

div {
  padding: 10px 50px;
.dotted {
  border-top: 1px #333 dotted;
.dotted-gradient {
  background-image: linear-gradient(to right, #333 40%, rgba(255, 255, 255, 0) 20%);
  background-position: top;
  background-size: 3px 1px;
  background-repeat: repeat-x;
.dotted-spaced {
  background-image: linear-gradient(to right, #333 10%, rgba(255, 255, 255, 0) 0%);
  background-position: top;
  background-size: 10px 1px;
  background-repeat: repeat-x;
.left {
  float: left;
  padding: 40px 10px;
  background-color: #F0F0DA;
.left.dotted {
  border-left: 1px #333 dotted;
  border-top: none;
.left.dotted-gradient {
  background-image: linear-gradient(to bottom, #333 40%, rgba(255, 255, 255, 0) 20%);
  background-position: left;
  background-size: 1px 3px;
  background-repeat: repeat-y;
.left.dotted-spaced {
  background-image: linear-gradient(to bottom, #333 10%, rgba(255, 255, 255, 0) 0%);
  background-position: left;
  background-size: 1px 10px;
  background-repeat: repeat-y;
<div class='dotted'>dotted
<div class='dotted-gradient'>dotted
  <br>with gradient</div>
<div class='dotted-spaced'>dotted

<div class='left'>no
<div class='dotted left'>dotted
<div class='dotted-gradient left'>dotted
  <br>with gradient</div>
<div class='dotted-spaced left'>dotted

css border设置虚线样式? - html中文网

2019年11月7日 ... 在CSS中,可以通过设置border属性的值为dashed或dotted来设置虚线样式。 border属性可以用于设置边框的宽度、颜色、圆角度、样式(实线、 ...

CSS Borders

The CSS border properties allow you to specify the style, width, and color of an ... dotted - Defines a dotted border; dashed - Defines a dashed border; solid ...

CSS Border(边框) | 菜鸟教程

dashed: 定义一个虚线边框 ... border-color属性用于设置边框的颜色。 ... border- color, 简写属性,设置元素的所有边框中可见部分的颜色,或为4 个边分别设置颜色  ...


为了对html不同标签加边框虚线,我们选择几个常用标签对齐设置边框虚线效果。 1、html常用标签p标签span ul li table tr td 2、实例用到CSS属性单词border width  ...

border-style - CSS: Cascading Style Sheets | MDN

Jan 15, 2021 ... The border-style shorthand CSS property sets the line style for all four sides of an element's border. ... border-style: dashed groove none dotted; ... HTML. <table> < tr> <td class="b1">none</td> <td class="b2">hidden</td> <td ...

html表格虚线边框 - 搜狗搜索

2021年1月6日 ... html表格虚线边框- 约1968个回答- 搜狗知识 ... 在border属性中有很多的属性,第一... 5/10 ... css如何设置虚线边框?css设置虚线边框的方法示例- 知乎 · 1 - 在网页布局中 ,有时候为了 ... table中如何设置内部边框为虚线- CSDN论坛.

HTML中如何将表格最外层边框设置成实线,内单元格边框设置虚线 ...

2020年3月11日 ... 如图中所示,最外层边框为实线,内部单元格边框为虚线 以下为HTML部分的 一部分代码 <body> <form action=""> <table>/*设置表格代码*/ <th> ...

css如何设置虚线边框?css设置虚线边框的方法示例- 知乎

2020年5月6日 ... border中dotted跟dashed都是可以用来设置边框虚线的,只是dashed ... DOCTYPE html> <html> <head> <title></title> <style type="text/css"> ...

CSS border-style property

... table-layout text-align text-align-last text-decoration text-decoration-color text- decoration-line text-decoration-style ... The border-style property sets the style of an element's four borders. ... top border is dotted; right border is solid; bottom border is double; left border is dashed ... HTML DOM reference: borderStyle property.

How to increase space between dotted border dots - Stack Overflow

In this example I have a dotted line of 1px dots and 2px spacing. This way you can have ... And in the following, you create your border (here's an example with dots) hr:after ... The 50% of the background tag is how wide the dash actually is.


2014年7月18日 ... 因此此前的任何border-color 和border-width 设置都会被清除。 在IE5.5+ 中,边框 属性可以直接应用于内联要素。而在此前的版本中,内联要素要 ...

html中加入虚线- Trible.H - 博客园

2011年11月23日 ... 请参阅各参数对应的属性。 默认值为: medium none 。 border-color 的默认值将 采用文本颜色。 说明: 设置对象的边框样式。

How to draw border with dotted line - Microsoft Q&A

Apr 15, 2020 ... As far as I know, it's not possible to do it with <Border>. However, with a Rectangle, where you don't specify the Fill (thus, the Fill remains ...

How to draw a dotted line with css? - Stack Overflow

Using HTML: <div class="horizontal_dotted_line"></div>. and in styles.css: . horizontal_dotted_line{ border-bottom: 1px dotted [color]; width: [put ...

border | CSS-Tricks

Apr 11, 2018 ... dashed : A line that consists of dashes. dotted : A line that consists of dots. double : Two lines are drawn around the element. groove : ...

Set Line Style for Table Borders in PowerPoint 2013 for Windows

Jun 12, 2014 ... And you can also make table borders sport dashed or dotted lines instead of simple thin lines: Change the Line Style of Existing Table Borders:.

Control the dashed border stroke length and distance between ...

Reference: ... We can create the dashed border by using a path or a polygon element and setting ...

CSS Trick – Customized Dashed or Dotted Border

The SVG features give us the ability to change the distance between dashed lines, set custom pattern, add dash offset or even change a line cap. Generated SVG ...