Home >Web Front-end >CSS Tutorial >How Can I Control the Spacing of Dots in Dotted CSS Borders?

How Can I Control the Spacing of Dots in Dotted CSS Borders?

DDD
DDDOriginal
2024-12-02 02:49:09636browse

How Can I Control the Spacing of Dots in Dotted CSS Borders?

Controlling Dot Spacing in Dotted Borders

To increase the space between dots in a dotted border, consider using a gradient technique. This method applies to both horizontal and vertical borders.

Horizontal Borders:

  • Set background-image to a linear gradient with a percentage value specifying the proportion of the line occupied by dots, followed by 0% for transparency.
  • Adjust background-size to control the dot size and the background-position to place the gradient at the border's bottom.

Vertical Borders:

  • Use the same linear gradient technique as above, but change the background-position to "right."

Example Code:

/* Horizontal */
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;

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

By adjusting the percentages in the linear gradient, you can control the ratio of dots to spacing. The background-size property determines the dot size.

Note: This technique allows for multiple dotted borders by utilizing multiple background images.

The above is the detailed content of How Can I Control the Spacing of Dots in Dotted CSS Borders?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn