How to increase space between dotted border dots
I am using dotted style border in my box like
.box {
width: 300px;
height: 200px;
border: dotted 1px #f00;
float: left;
}
I want to the increase the space between each dot of the border.
html css css3 border
add a comment |
I am using dotted style border in my box like
.box {
width: 300px;
height: 200px;
border: dotted 1px #f00;
float: left;
}
I want to the increase the space between each dot of the border.
html css css3 border
add a comment |
I am using dotted style border in my box like
.box {
width: 300px;
height: 200px;
border: dotted 1px #f00;
float: left;
}
I want to the increase the space between each dot of the border.
html css css3 border
I am using dotted style border in my box like
.box {
width: 300px;
height: 200px;
border: dotted 1px #f00;
float: left;
}
I want to the increase the space between each dot of the border.
html css css3 border
html css css3 border
edited Oct 3 '12 at 8:46
Dejan
459413
459413
asked Jun 6 '11 at 10:00
Kali Charan RajputKali Charan Rajput
4,78682844
4,78682844
add a comment |
add a comment |
15 Answers
15
active
oldest
votes
This trick works for both horizontal and vertical borders:
/*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;
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>no
<br>border</div>
<div class='dotted'>dotted
<br>border</div>
<div class='dotted-gradient'>dotted
<br>with gradient</div>
<div class='dotted-spaced'>dotted
<br>spaced</div>
<div class='left'>no
<br>border</div>
<div class='dotted left'>dotted
<br>border</div>
<div class='dotted-gradient left'>dotted
<br>with gradient</div>
<div class='dotted-spaced left'>dotted
<br>spaced</div>
23
Should be the selected answer.
– Kevin Jurkowski
May 6 '14 at 21:21
18
Used this answer to do the following pen: codepen.io/Elyx0/pen/bLldB
– Elyx0
Aug 27 '14 at 19:00
4
imho it's a hack of n degree.
– Muhammad Umer
Jun 6 '15 at 17:12
5
I want to do the same thing but dotted border width is 3px rather than 1px and now it becomes square rather than dotted.
– Bhojendra Rauniyar
Jun 8 '15 at 6:10
5
I've made a SCSS mixin to implement this and change colors and spacing quickly. Check it out at github.com/florbraz/Dotted-Border-w-custom-spacing-SCSS-Mixin.
– Flor Braz
Aug 31 '15 at 21:13
|
show 9 more comments
Here's a trick I've used on a recent project to achieve nearly anything I want with horizontal borders. I use <hr/>
each time I need an horizontal border. The basic way to add a border to this hr is something like
hr {border-bottom: 1px dotted #000;}
But if you want to take control of the border and, for example increase, the space between dots, you may try something like this:
hr {
height:14px; /* specify a height for this hr */
overflow:hidden;
}
And in the following, you create your border (here's an example with dots)
hr:after {
content:".......................................................................";
letter-spacing: 4px; /* Use letter-spacing to increase space between dots*/
}
This also means that you can add text-shadow to the dots, gradients etc. Anything you want...
Well, it works really great for horizontal borders. If you need vertical ones, you may specify a class for another hr and use the CSS3 rotation
property.
2
Is this cross-browser compatible?
– J82
May 31 '13 at 21:52
48
I can't imagine what a pain in the a** that would be to maintain.
– Kzqai
Sep 4 '13 at 22:24
1
how to get same effect for vertical one?
– Rinku
Nov 25 '13 at 7:47
4
@Rinku with transform:rotate(90deg); display:block;
– Jeroen K
Dec 27 '13 at 9:20
3
so ugly, but so clever :) I also notice that I can have finer control over placement if I set height:0; and use padding to control placement. So I wanted the dotted line on the bottom with a little room below so I used padding: 0 0 10px;
– MatthewLee
Mar 22 '14 at 21:44
|
show 6 more comments
You cannot do it with pure CSS - the CSS3 spec even has a specific quote about this:
Note: There is no control over the spacing of the dots and dashes, nor over the length of the dashes. Implementations are encouraged to choose a spacing that makes the corners symmetrical.
You can, however, use either a border-image or a background image that does the trick.
7
You may use gradients (pure CSS) for a fully customisable border. See answer below
– Eagorajose
Mar 29 '14 at 16:04
2
-1, @Shadikka, What the CSS3 spec says is that it cannot be done usingborder: dotted
, but it is possible to do it using gradients as Eagorajose's answer has shown.
– Pacerier
Sep 18 '14 at 13:58
add a comment |
See the MDN docs for the available values for border-style
:
- none : No border, sets width to 0.
This is the default value.
- hidden : Same as 'none', except in terms of
border conflict resolution for table
elements.
- dashed : Series of short
dashes or line segments.
- dotted :
Series of dots.
- double : Two straight
lines that add up to the pixel amount
defined as border-width.
- groove :
Carved effect.
- inset : Makes the box
appear embedded.
- outset : Opposite of
'inset'. Makes the box appear 3D
(embossed).
- ridge : Opposite of
'groove'. The border appears 3D
(coming out).
- solid : Single,
straight, solid line.
Apart from those choices, there is no way to influence the standard border's style.
If the possibilities there are not to your liking, you could use CSS3's border-image
but note that browser support for this is still very spotty.
thanks pekka, that mean i can't use border property ... so i have to use image for it.
– Kali Charan Rajput
Jun 6 '11 at 10:30
@kc if none of the border styles is to your liking, yes.
– Pekka 웃
Jun 6 '11 at 10:47
add a comment |
This uses the standard CSS border and a pseudo element+overflow:hidden.
In the example you get three different 2px dashed borders: normal, spaced like a 5px, spaced like a 10px. Is actually 10px with only 10-8=2px visible.
div.two{border:2px dashed #FF0000}
div.five:before {
content: "";
position: absolute;
border: 5px dashed #FF0000;
top: -3px;
bottom: -3px;
left: -3px;
right: -3px;
}
div.ten:before {
content: "";
position: absolute;
border: 10px dashed #FF0000;
top: -8px;
bottom: -8px;
left: -8px;
right: -8px;
}
div.odd:before {left:0;right:0;border-radius:60px}
div {
overflow: hidden;
position: relative;
text-align:center;
padding:10px;
margin-bottom:20px;
}
<div class="two">Kupo nuts here</div>
<div class="five">Kupo nuts<br/>here</div>
<div class="ten">Kupo<br/>nuts<br/>here</div>
<div class="ten odd">Kupo<br/>nuts<br/>here</div>
Applied to small elements with big rounded corners may make for some fun effects.
1
Strong work! This is the only one of these answers that really works without being terrible to maintain, IMO. Even the accepted answer only works for one edge of the div. This works for the whole border.
– Ryan Shillington
Jun 13 '18 at 13:52
add a comment |
This is a really old question but it has a high ranking in Google so I'm going to throw in my method which could work depending on your needs.
In my case, I wanted a thick dashed border that had a minimal break in between dashes. I used a CSS pattern generator (like this one: http://www.patternify.com/) to create a 10px wide by 1px tall pattern. 9px of that is solid dash color, 1px is white.
In my CSS, I included that pattern as the background image, and then scaled it up by using the background-size attribute. I ended up with a 20px by 2px repeated dash, 18px of that being solid line and 2px white. You could scale it up even more for a really thick dashed line.
The nice thing is since the image is encoded as data you don't have the additional outside HTTP request, so there's no performance burden. I stored my image as a SASS variable so I could reuse it in my site.
Works for me! thx
– pztrick
Nov 13 '14 at 15:22
add a comment |
So starting with the answer given and applying the fact that CSS3 allows multiple settings - the below code is useful for creating a complete box:
#border {
width: 200px;
height: 100px;
background: yellow;
text-align: center;
line-height: 100px;
background: linear-gradient(to right, orange 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(blue 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(to right, green 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(red 50%, rgba(255, 255, 255, 0) 0%);
background-position: top, right, bottom, left;
background-repeat: repeat-x, repeat-y;
background-size: 10px 1px, 1px 10px;
}
<div id="border">
bordered area
</div>
Its worth noting that the 10px in the background size gives the area that the dash and gap will cover. The 50% of the background tag is how wide the dash actually is. It is therefore possible to have different length dashes on each border side.
add a comment |
Short answer: You can't.
You will have to use border-image
property and a few images.
add a comment |
IF you're only targeting modern browsers, AND you can have your border on a separate element from your content, then you can use the CSS scale transform to get a larger dot or dash:
border: 1px dashed black;
border-radius: 10px;
-webkit-transform: scale(8);
transform: scale(8);
It takes a lot of positional tweaking to get it to line up, but it works. By changing the thickness of the border, the starting size and the scale factor, you can get to just about thickness-length ratio you want. Only thing you can't touch is dash-to-gap ratio.
By doing so content will also gets appliedscale(8)
– Pardeep Jain
Aug 9 '18 at 7:36
add a comment |
So many people are say "You can't". Yes you can. It's true that there is not a css rule to control the gutter space between the dashes but css has other abilities. Don't be so quick to say that a thing can not be done.
.hr {
border-top: 5px dashed #CFCBCC;
margin: 30px 0;
position: relative;
}
.hr:before {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -2px;
width: 100%;
}
.hr:after {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -13px;
width: 100%;
}
Basically the border-top height (5px in this case) is the rule that determines the gutter "width". OIf course you would need to adjust the colors to match your needs. This also is a small example for a horizontal line, use left and right to make the vertical line.
1
To be fair, I think most people are saying you can't do it to the literal question of adjusting the border dotted styling. They're not saying something similar isn't possible using other CSS properties. In my opinion it makes a lot more sense from a semantic point of view to use a background image or border-image as others have shown, than use pseudo elements and a dozen lines of CSS.
– Alex
Mar 3 '14 at 11:49
add a comment |
This is an old, but still very relevant topic. The current top answer works well, but only for very small dots. As Bhojendra Rauniyar already pointed out in the comments, for larger (>2px) dots, the dots appear square, not round. I found this page searching for spaced dots, not spaced squares (or even dashes, as some answers here use).
Building on this, I used radial-gradient
. Also, using the answer from Ukuser32, the dot-properties can easily be repeated for all four borders. Only the corners are not perfect.
div {
padding: 1em;
background-image:
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px);
background-position: top, right, bottom, left;
background-size: 15px 5px, 5px 15px;
background-repeat: repeat-x, repeat-y;
}
<div>Some content with round, spaced dots as border</div>
The radial-gradient
expects:
- the shape and optional position
- two or more stops: a color and radius
Here, I wanted a 5 pixel diameter (2.5px radius) dot, with 2 times the diameter (10px) between the dots, adding up to 15px. The background-size
should match these.
The two stops are defined such that the dot is nice and smooth: solid black for half the radius and than a gradient to the full radius.
add a comment |
AFAIK there isn't a way to do this. You could use a dashed border or perhaps increase the width of the border a bit, but just getting more spaced out dots is impossible with CSS.
add a comment |
You could create a canvas (via javascript) and draw a dotted line within. Within the canvas you can control how long the dash and the space in between shall be.
That is a very convoluted solution. I can't help but feel that this would also cost a tiny bit more in performance and perceived load times, depending on the weight of the rest of the JS on the page.
– Emmett R.
May 24 '16 at 16:48
add a comment |
Building 4 edges solution basing on @Eagorajose's answer with shorthand syntax:
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
#page {
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
width: 100px;
height: 100px;
}
<div id="page"></div>
add a comment |
<div style="width: 100%; height: 100vh; max-height: 20px; max-width: 100%; background: url('https://kajabi-storefronts-production.global.ssl.fastly.net/kajabi-storefronts-production/themes/853636/settings_images/Ei2yf3t7TvyRpFaLQZiX_dot.jpg') #000; background-repeat: repeat;"> </div>
this is what I did - use an image
enter image description here
New contributor
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6250394%2fhow-to-increase-space-between-dotted-border-dots%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
15 Answers
15
active
oldest
votes
15 Answers
15
active
oldest
votes
active
oldest
votes
active
oldest
votes
This trick works for both horizontal and vertical borders:
/*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;
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>no
<br>border</div>
<div class='dotted'>dotted
<br>border</div>
<div class='dotted-gradient'>dotted
<br>with gradient</div>
<div class='dotted-spaced'>dotted
<br>spaced</div>
<div class='left'>no
<br>border</div>
<div class='dotted left'>dotted
<br>border</div>
<div class='dotted-gradient left'>dotted
<br>with gradient</div>
<div class='dotted-spaced left'>dotted
<br>spaced</div>
23
Should be the selected answer.
– Kevin Jurkowski
May 6 '14 at 21:21
18
Used this answer to do the following pen: codepen.io/Elyx0/pen/bLldB
– Elyx0
Aug 27 '14 at 19:00
4
imho it's a hack of n degree.
– Muhammad Umer
Jun 6 '15 at 17:12
5
I want to do the same thing but dotted border width is 3px rather than 1px and now it becomes square rather than dotted.
– Bhojendra Rauniyar
Jun 8 '15 at 6:10
5
I've made a SCSS mixin to implement this and change colors and spacing quickly. Check it out at github.com/florbraz/Dotted-Border-w-custom-spacing-SCSS-Mixin.
– Flor Braz
Aug 31 '15 at 21:13
|
show 9 more comments
This trick works for both horizontal and vertical borders:
/*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;
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>no
<br>border</div>
<div class='dotted'>dotted
<br>border</div>
<div class='dotted-gradient'>dotted
<br>with gradient</div>
<div class='dotted-spaced'>dotted
<br>spaced</div>
<div class='left'>no
<br>border</div>
<div class='dotted left'>dotted
<br>border</div>
<div class='dotted-gradient left'>dotted
<br>with gradient</div>
<div class='dotted-spaced left'>dotted
<br>spaced</div>
23
Should be the selected answer.
– Kevin Jurkowski
May 6 '14 at 21:21
18
Used this answer to do the following pen: codepen.io/Elyx0/pen/bLldB
– Elyx0
Aug 27 '14 at 19:00
4
imho it's a hack of n degree.
– Muhammad Umer
Jun 6 '15 at 17:12
5
I want to do the same thing but dotted border width is 3px rather than 1px and now it becomes square rather than dotted.
– Bhojendra Rauniyar
Jun 8 '15 at 6:10
5
I've made a SCSS mixin to implement this and change colors and spacing quickly. Check it out at github.com/florbraz/Dotted-Border-w-custom-spacing-SCSS-Mixin.
– Flor Braz
Aug 31 '15 at 21:13
|
show 9 more comments
This trick works for both horizontal and vertical borders:
/*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;
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>no
<br>border</div>
<div class='dotted'>dotted
<br>border</div>
<div class='dotted-gradient'>dotted
<br>with gradient</div>
<div class='dotted-spaced'>dotted
<br>spaced</div>
<div class='left'>no
<br>border</div>
<div class='dotted left'>dotted
<br>border</div>
<div class='dotted-gradient left'>dotted
<br>with gradient</div>
<div class='dotted-spaced left'>dotted
<br>spaced</div>
This trick works for both horizontal and vertical borders:
/*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;
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>no
<br>border</div>
<div class='dotted'>dotted
<br>border</div>
<div class='dotted-gradient'>dotted
<br>with gradient</div>
<div class='dotted-spaced'>dotted
<br>spaced</div>
<div class='left'>no
<br>border</div>
<div class='dotted left'>dotted
<br>border</div>
<div class='dotted-gradient left'>dotted
<br>with gradient</div>
<div class='dotted-spaced left'>dotted
<br>spaced</div>
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>no
<br>border</div>
<div class='dotted'>dotted
<br>border</div>
<div class='dotted-gradient'>dotted
<br>with gradient</div>
<div class='dotted-spaced'>dotted
<br>spaced</div>
<div class='left'>no
<br>border</div>
<div class='dotted left'>dotted
<br>border</div>
<div class='dotted-gradient left'>dotted
<br>with gradient</div>
<div class='dotted-spaced left'>dotted
<br>spaced</div>
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>no
<br>border</div>
<div class='dotted'>dotted
<br>border</div>
<div class='dotted-gradient'>dotted
<br>with gradient</div>
<div class='dotted-spaced'>dotted
<br>spaced</div>
<div class='left'>no
<br>border</div>
<div class='dotted left'>dotted
<br>border</div>
<div class='dotted-gradient left'>dotted
<br>with gradient</div>
<div class='dotted-spaced left'>dotted
<br>spaced</div>
edited Apr 26 '16 at 14:25
insertusernamehere
18.9k667105
18.9k667105
answered Aug 5 '13 at 17:52
EagorajoseEagorajose
3,6711119
3,6711119
23
Should be the selected answer.
– Kevin Jurkowski
May 6 '14 at 21:21
18
Used this answer to do the following pen: codepen.io/Elyx0/pen/bLldB
– Elyx0
Aug 27 '14 at 19:00
4
imho it's a hack of n degree.
– Muhammad Umer
Jun 6 '15 at 17:12
5
I want to do the same thing but dotted border width is 3px rather than 1px and now it becomes square rather than dotted.
– Bhojendra Rauniyar
Jun 8 '15 at 6:10
5
I've made a SCSS mixin to implement this and change colors and spacing quickly. Check it out at github.com/florbraz/Dotted-Border-w-custom-spacing-SCSS-Mixin.
– Flor Braz
Aug 31 '15 at 21:13
|
show 9 more comments
23
Should be the selected answer.
– Kevin Jurkowski
May 6 '14 at 21:21
18
Used this answer to do the following pen: codepen.io/Elyx0/pen/bLldB
– Elyx0
Aug 27 '14 at 19:00
4
imho it's a hack of n degree.
– Muhammad Umer
Jun 6 '15 at 17:12
5
I want to do the same thing but dotted border width is 3px rather than 1px and now it becomes square rather than dotted.
– Bhojendra Rauniyar
Jun 8 '15 at 6:10
5
I've made a SCSS mixin to implement this and change colors and spacing quickly. Check it out at github.com/florbraz/Dotted-Border-w-custom-spacing-SCSS-Mixin.
– Flor Braz
Aug 31 '15 at 21:13
23
23
Should be the selected answer.
– Kevin Jurkowski
May 6 '14 at 21:21
Should be the selected answer.
– Kevin Jurkowski
May 6 '14 at 21:21
18
18
Used this answer to do the following pen: codepen.io/Elyx0/pen/bLldB
– Elyx0
Aug 27 '14 at 19:00
Used this answer to do the following pen: codepen.io/Elyx0/pen/bLldB
– Elyx0
Aug 27 '14 at 19:00
4
4
imho it's a hack of n degree.
– Muhammad Umer
Jun 6 '15 at 17:12
imho it's a hack of n degree.
– Muhammad Umer
Jun 6 '15 at 17:12
5
5
I want to do the same thing but dotted border width is 3px rather than 1px and now it becomes square rather than dotted.
– Bhojendra Rauniyar
Jun 8 '15 at 6:10
I want to do the same thing but dotted border width is 3px rather than 1px and now it becomes square rather than dotted.
– Bhojendra Rauniyar
Jun 8 '15 at 6:10
5
5
I've made a SCSS mixin to implement this and change colors and spacing quickly. Check it out at github.com/florbraz/Dotted-Border-w-custom-spacing-SCSS-Mixin.
– Flor Braz
Aug 31 '15 at 21:13
I've made a SCSS mixin to implement this and change colors and spacing quickly. Check it out at github.com/florbraz/Dotted-Border-w-custom-spacing-SCSS-Mixin.
– Flor Braz
Aug 31 '15 at 21:13
|
show 9 more comments
Here's a trick I've used on a recent project to achieve nearly anything I want with horizontal borders. I use <hr/>
each time I need an horizontal border. The basic way to add a border to this hr is something like
hr {border-bottom: 1px dotted #000;}
But if you want to take control of the border and, for example increase, the space between dots, you may try something like this:
hr {
height:14px; /* specify a height for this hr */
overflow:hidden;
}
And in the following, you create your border (here's an example with dots)
hr:after {
content:".......................................................................";
letter-spacing: 4px; /* Use letter-spacing to increase space between dots*/
}
This also means that you can add text-shadow to the dots, gradients etc. Anything you want...
Well, it works really great for horizontal borders. If you need vertical ones, you may specify a class for another hr and use the CSS3 rotation
property.
2
Is this cross-browser compatible?
– J82
May 31 '13 at 21:52
48
I can't imagine what a pain in the a** that would be to maintain.
– Kzqai
Sep 4 '13 at 22:24
1
how to get same effect for vertical one?
– Rinku
Nov 25 '13 at 7:47
4
@Rinku with transform:rotate(90deg); display:block;
– Jeroen K
Dec 27 '13 at 9:20
3
so ugly, but so clever :) I also notice that I can have finer control over placement if I set height:0; and use padding to control placement. So I wanted the dotted line on the bottom with a little room below so I used padding: 0 0 10px;
– MatthewLee
Mar 22 '14 at 21:44
|
show 6 more comments
Here's a trick I've used on a recent project to achieve nearly anything I want with horizontal borders. I use <hr/>
each time I need an horizontal border. The basic way to add a border to this hr is something like
hr {border-bottom: 1px dotted #000;}
But if you want to take control of the border and, for example increase, the space between dots, you may try something like this:
hr {
height:14px; /* specify a height for this hr */
overflow:hidden;
}
And in the following, you create your border (here's an example with dots)
hr:after {
content:".......................................................................";
letter-spacing: 4px; /* Use letter-spacing to increase space between dots*/
}
This also means that you can add text-shadow to the dots, gradients etc. Anything you want...
Well, it works really great for horizontal borders. If you need vertical ones, you may specify a class for another hr and use the CSS3 rotation
property.
2
Is this cross-browser compatible?
– J82
May 31 '13 at 21:52
48
I can't imagine what a pain in the a** that would be to maintain.
– Kzqai
Sep 4 '13 at 22:24
1
how to get same effect for vertical one?
– Rinku
Nov 25 '13 at 7:47
4
@Rinku with transform:rotate(90deg); display:block;
– Jeroen K
Dec 27 '13 at 9:20
3
so ugly, but so clever :) I also notice that I can have finer control over placement if I set height:0; and use padding to control placement. So I wanted the dotted line on the bottom with a little room below so I used padding: 0 0 10px;
– MatthewLee
Mar 22 '14 at 21:44
|
show 6 more comments
Here's a trick I've used on a recent project to achieve nearly anything I want with horizontal borders. I use <hr/>
each time I need an horizontal border. The basic way to add a border to this hr is something like
hr {border-bottom: 1px dotted #000;}
But if you want to take control of the border and, for example increase, the space between dots, you may try something like this:
hr {
height:14px; /* specify a height for this hr */
overflow:hidden;
}
And in the following, you create your border (here's an example with dots)
hr:after {
content:".......................................................................";
letter-spacing: 4px; /* Use letter-spacing to increase space between dots*/
}
This also means that you can add text-shadow to the dots, gradients etc. Anything you want...
Well, it works really great for horizontal borders. If you need vertical ones, you may specify a class for another hr and use the CSS3 rotation
property.
Here's a trick I've used on a recent project to achieve nearly anything I want with horizontal borders. I use <hr/>
each time I need an horizontal border. The basic way to add a border to this hr is something like
hr {border-bottom: 1px dotted #000;}
But if you want to take control of the border and, for example increase, the space between dots, you may try something like this:
hr {
height:14px; /* specify a height for this hr */
overflow:hidden;
}
And in the following, you create your border (here's an example with dots)
hr:after {
content:".......................................................................";
letter-spacing: 4px; /* Use letter-spacing to increase space between dots*/
}
This also means that you can add text-shadow to the dots, gradients etc. Anything you want...
Well, it works really great for horizontal borders. If you need vertical ones, you may specify a class for another hr and use the CSS3 rotation
property.
edited Oct 3 '12 at 14:08
ЯegDwight
21.4k93748
21.4k93748
answered Aug 9 '12 at 17:54
MattMatt
1,409183
1,409183
2
Is this cross-browser compatible?
– J82
May 31 '13 at 21:52
48
I can't imagine what a pain in the a** that would be to maintain.
– Kzqai
Sep 4 '13 at 22:24
1
how to get same effect for vertical one?
– Rinku
Nov 25 '13 at 7:47
4
@Rinku with transform:rotate(90deg); display:block;
– Jeroen K
Dec 27 '13 at 9:20
3
so ugly, but so clever :) I also notice that I can have finer control over placement if I set height:0; and use padding to control placement. So I wanted the dotted line on the bottom with a little room below so I used padding: 0 0 10px;
– MatthewLee
Mar 22 '14 at 21:44
|
show 6 more comments
2
Is this cross-browser compatible?
– J82
May 31 '13 at 21:52
48
I can't imagine what a pain in the a** that would be to maintain.
– Kzqai
Sep 4 '13 at 22:24
1
how to get same effect for vertical one?
– Rinku
Nov 25 '13 at 7:47
4
@Rinku with transform:rotate(90deg); display:block;
– Jeroen K
Dec 27 '13 at 9:20
3
so ugly, but so clever :) I also notice that I can have finer control over placement if I set height:0; and use padding to control placement. So I wanted the dotted line on the bottom with a little room below so I used padding: 0 0 10px;
– MatthewLee
Mar 22 '14 at 21:44
2
2
Is this cross-browser compatible?
– J82
May 31 '13 at 21:52
Is this cross-browser compatible?
– J82
May 31 '13 at 21:52
48
48
I can't imagine what a pain in the a** that would be to maintain.
– Kzqai
Sep 4 '13 at 22:24
I can't imagine what a pain in the a** that would be to maintain.
– Kzqai
Sep 4 '13 at 22:24
1
1
how to get same effect for vertical one?
– Rinku
Nov 25 '13 at 7:47
how to get same effect for vertical one?
– Rinku
Nov 25 '13 at 7:47
4
4
@Rinku with transform:rotate(90deg); display:block;
– Jeroen K
Dec 27 '13 at 9:20
@Rinku with transform:rotate(90deg); display:block;
– Jeroen K
Dec 27 '13 at 9:20
3
3
so ugly, but so clever :) I also notice that I can have finer control over placement if I set height:0; and use padding to control placement. So I wanted the dotted line on the bottom with a little room below so I used padding: 0 0 10px;
– MatthewLee
Mar 22 '14 at 21:44
so ugly, but so clever :) I also notice that I can have finer control over placement if I set height:0; and use padding to control placement. So I wanted the dotted line on the bottom with a little room below so I used padding: 0 0 10px;
– MatthewLee
Mar 22 '14 at 21:44
|
show 6 more comments
You cannot do it with pure CSS - the CSS3 spec even has a specific quote about this:
Note: There is no control over the spacing of the dots and dashes, nor over the length of the dashes. Implementations are encouraged to choose a spacing that makes the corners symmetrical.
You can, however, use either a border-image or a background image that does the trick.
7
You may use gradients (pure CSS) for a fully customisable border. See answer below
– Eagorajose
Mar 29 '14 at 16:04
2
-1, @Shadikka, What the CSS3 spec says is that it cannot be done usingborder: dotted
, but it is possible to do it using gradients as Eagorajose's answer has shown.
– Pacerier
Sep 18 '14 at 13:58
add a comment |
You cannot do it with pure CSS - the CSS3 spec even has a specific quote about this:
Note: There is no control over the spacing of the dots and dashes, nor over the length of the dashes. Implementations are encouraged to choose a spacing that makes the corners symmetrical.
You can, however, use either a border-image or a background image that does the trick.
7
You may use gradients (pure CSS) for a fully customisable border. See answer below
– Eagorajose
Mar 29 '14 at 16:04
2
-1, @Shadikka, What the CSS3 spec says is that it cannot be done usingborder: dotted
, but it is possible to do it using gradients as Eagorajose's answer has shown.
– Pacerier
Sep 18 '14 at 13:58
add a comment |
You cannot do it with pure CSS - the CSS3 spec even has a specific quote about this:
Note: There is no control over the spacing of the dots and dashes, nor over the length of the dashes. Implementations are encouraged to choose a spacing that makes the corners symmetrical.
You can, however, use either a border-image or a background image that does the trick.
You cannot do it with pure CSS - the CSS3 spec even has a specific quote about this:
Note: There is no control over the spacing of the dots and dashes, nor over the length of the dashes. Implementations are encouraged to choose a spacing that makes the corners symmetrical.
You can, however, use either a border-image or a background image that does the trick.
edited Aug 17 '14 at 13:01
Cody Gray♦
193k35379467
193k35379467
answered Jun 6 '11 at 10:06
ShadikkaShadikka
3,19611119
3,19611119
7
You may use gradients (pure CSS) for a fully customisable border. See answer below
– Eagorajose
Mar 29 '14 at 16:04
2
-1, @Shadikka, What the CSS3 spec says is that it cannot be done usingborder: dotted
, but it is possible to do it using gradients as Eagorajose's answer has shown.
– Pacerier
Sep 18 '14 at 13:58
add a comment |
7
You may use gradients (pure CSS) for a fully customisable border. See answer below
– Eagorajose
Mar 29 '14 at 16:04
2
-1, @Shadikka, What the CSS3 spec says is that it cannot be done usingborder: dotted
, but it is possible to do it using gradients as Eagorajose's answer has shown.
– Pacerier
Sep 18 '14 at 13:58
7
7
You may use gradients (pure CSS) for a fully customisable border. See answer below
– Eagorajose
Mar 29 '14 at 16:04
You may use gradients (pure CSS) for a fully customisable border. See answer below
– Eagorajose
Mar 29 '14 at 16:04
2
2
-1, @Shadikka, What the CSS3 spec says is that it cannot be done using
border: dotted
, but it is possible to do it using gradients as Eagorajose's answer has shown.– Pacerier
Sep 18 '14 at 13:58
-1, @Shadikka, What the CSS3 spec says is that it cannot be done using
border: dotted
, but it is possible to do it using gradients as Eagorajose's answer has shown.– Pacerier
Sep 18 '14 at 13:58
add a comment |
See the MDN docs for the available values for border-style
:
- none : No border, sets width to 0.
This is the default value.
- hidden : Same as 'none', except in terms of
border conflict resolution for table
elements.
- dashed : Series of short
dashes or line segments.
- dotted :
Series of dots.
- double : Two straight
lines that add up to the pixel amount
defined as border-width.
- groove :
Carved effect.
- inset : Makes the box
appear embedded.
- outset : Opposite of
'inset'. Makes the box appear 3D
(embossed).
- ridge : Opposite of
'groove'. The border appears 3D
(coming out).
- solid : Single,
straight, solid line.
Apart from those choices, there is no way to influence the standard border's style.
If the possibilities there are not to your liking, you could use CSS3's border-image
but note that browser support for this is still very spotty.
thanks pekka, that mean i can't use border property ... so i have to use image for it.
– Kali Charan Rajput
Jun 6 '11 at 10:30
@kc if none of the border styles is to your liking, yes.
– Pekka 웃
Jun 6 '11 at 10:47
add a comment |
See the MDN docs for the available values for border-style
:
- none : No border, sets width to 0.
This is the default value.
- hidden : Same as 'none', except in terms of
border conflict resolution for table
elements.
- dashed : Series of short
dashes or line segments.
- dotted :
Series of dots.
- double : Two straight
lines that add up to the pixel amount
defined as border-width.
- groove :
Carved effect.
- inset : Makes the box
appear embedded.
- outset : Opposite of
'inset'. Makes the box appear 3D
(embossed).
- ridge : Opposite of
'groove'. The border appears 3D
(coming out).
- solid : Single,
straight, solid line.
Apart from those choices, there is no way to influence the standard border's style.
If the possibilities there are not to your liking, you could use CSS3's border-image
but note that browser support for this is still very spotty.
thanks pekka, that mean i can't use border property ... so i have to use image for it.
– Kali Charan Rajput
Jun 6 '11 at 10:30
@kc if none of the border styles is to your liking, yes.
– Pekka 웃
Jun 6 '11 at 10:47
add a comment |
See the MDN docs for the available values for border-style
:
- none : No border, sets width to 0.
This is the default value.
- hidden : Same as 'none', except in terms of
border conflict resolution for table
elements.
- dashed : Series of short
dashes or line segments.
- dotted :
Series of dots.
- double : Two straight
lines that add up to the pixel amount
defined as border-width.
- groove :
Carved effect.
- inset : Makes the box
appear embedded.
- outset : Opposite of
'inset'. Makes the box appear 3D
(embossed).
- ridge : Opposite of
'groove'. The border appears 3D
(coming out).
- solid : Single,
straight, solid line.
Apart from those choices, there is no way to influence the standard border's style.
If the possibilities there are not to your liking, you could use CSS3's border-image
but note that browser support for this is still very spotty.
See the MDN docs for the available values for border-style
:
- none : No border, sets width to 0.
This is the default value.
- hidden : Same as 'none', except in terms of
border conflict resolution for table
elements.
- dashed : Series of short
dashes or line segments.
- dotted :
Series of dots.
- double : Two straight
lines that add up to the pixel amount
defined as border-width.
- groove :
Carved effect.
- inset : Makes the box
appear embedded.
- outset : Opposite of
'inset'. Makes the box appear 3D
(embossed).
- ridge : Opposite of
'groove'. The border appears 3D
(coming out).
- solid : Single,
straight, solid line.
Apart from those choices, there is no way to influence the standard border's style.
If the possibilities there are not to your liking, you could use CSS3's border-image
but note that browser support for this is still very spotty.
edited Nov 8 '18 at 12:11
Mark Amery
62.5k31249295
62.5k31249295
answered Jun 6 '11 at 10:03
Pekka 웃Pekka 웃
358k1178431014
358k1178431014
thanks pekka, that mean i can't use border property ... so i have to use image for it.
– Kali Charan Rajput
Jun 6 '11 at 10:30
@kc if none of the border styles is to your liking, yes.
– Pekka 웃
Jun 6 '11 at 10:47
add a comment |
thanks pekka, that mean i can't use border property ... so i have to use image for it.
– Kali Charan Rajput
Jun 6 '11 at 10:30
@kc if none of the border styles is to your liking, yes.
– Pekka 웃
Jun 6 '11 at 10:47
thanks pekka, that mean i can't use border property ... so i have to use image for it.
– Kali Charan Rajput
Jun 6 '11 at 10:30
thanks pekka, that mean i can't use border property ... so i have to use image for it.
– Kali Charan Rajput
Jun 6 '11 at 10:30
@kc if none of the border styles is to your liking, yes.
– Pekka 웃
Jun 6 '11 at 10:47
@kc if none of the border styles is to your liking, yes.
– Pekka 웃
Jun 6 '11 at 10:47
add a comment |
This uses the standard CSS border and a pseudo element+overflow:hidden.
In the example you get three different 2px dashed borders: normal, spaced like a 5px, spaced like a 10px. Is actually 10px with only 10-8=2px visible.
div.two{border:2px dashed #FF0000}
div.five:before {
content: "";
position: absolute;
border: 5px dashed #FF0000;
top: -3px;
bottom: -3px;
left: -3px;
right: -3px;
}
div.ten:before {
content: "";
position: absolute;
border: 10px dashed #FF0000;
top: -8px;
bottom: -8px;
left: -8px;
right: -8px;
}
div.odd:before {left:0;right:0;border-radius:60px}
div {
overflow: hidden;
position: relative;
text-align:center;
padding:10px;
margin-bottom:20px;
}
<div class="two">Kupo nuts here</div>
<div class="five">Kupo nuts<br/>here</div>
<div class="ten">Kupo<br/>nuts<br/>here</div>
<div class="ten odd">Kupo<br/>nuts<br/>here</div>
Applied to small elements with big rounded corners may make for some fun effects.
1
Strong work! This is the only one of these answers that really works without being terrible to maintain, IMO. Even the accepted answer only works for one edge of the div. This works for the whole border.
– Ryan Shillington
Jun 13 '18 at 13:52
add a comment |
This uses the standard CSS border and a pseudo element+overflow:hidden.
In the example you get three different 2px dashed borders: normal, spaced like a 5px, spaced like a 10px. Is actually 10px with only 10-8=2px visible.
div.two{border:2px dashed #FF0000}
div.five:before {
content: "";
position: absolute;
border: 5px dashed #FF0000;
top: -3px;
bottom: -3px;
left: -3px;
right: -3px;
}
div.ten:before {
content: "";
position: absolute;
border: 10px dashed #FF0000;
top: -8px;
bottom: -8px;
left: -8px;
right: -8px;
}
div.odd:before {left:0;right:0;border-radius:60px}
div {
overflow: hidden;
position: relative;
text-align:center;
padding:10px;
margin-bottom:20px;
}
<div class="two">Kupo nuts here</div>
<div class="five">Kupo nuts<br/>here</div>
<div class="ten">Kupo<br/>nuts<br/>here</div>
<div class="ten odd">Kupo<br/>nuts<br/>here</div>
Applied to small elements with big rounded corners may make for some fun effects.
1
Strong work! This is the only one of these answers that really works without being terrible to maintain, IMO. Even the accepted answer only works for one edge of the div. This works for the whole border.
– Ryan Shillington
Jun 13 '18 at 13:52
add a comment |
This uses the standard CSS border and a pseudo element+overflow:hidden.
In the example you get three different 2px dashed borders: normal, spaced like a 5px, spaced like a 10px. Is actually 10px with only 10-8=2px visible.
div.two{border:2px dashed #FF0000}
div.five:before {
content: "";
position: absolute;
border: 5px dashed #FF0000;
top: -3px;
bottom: -3px;
left: -3px;
right: -3px;
}
div.ten:before {
content: "";
position: absolute;
border: 10px dashed #FF0000;
top: -8px;
bottom: -8px;
left: -8px;
right: -8px;
}
div.odd:before {left:0;right:0;border-radius:60px}
div {
overflow: hidden;
position: relative;
text-align:center;
padding:10px;
margin-bottom:20px;
}
<div class="two">Kupo nuts here</div>
<div class="five">Kupo nuts<br/>here</div>
<div class="ten">Kupo<br/>nuts<br/>here</div>
<div class="ten odd">Kupo<br/>nuts<br/>here</div>
Applied to small elements with big rounded corners may make for some fun effects.
This uses the standard CSS border and a pseudo element+overflow:hidden.
In the example you get three different 2px dashed borders: normal, spaced like a 5px, spaced like a 10px. Is actually 10px with only 10-8=2px visible.
div.two{border:2px dashed #FF0000}
div.five:before {
content: "";
position: absolute;
border: 5px dashed #FF0000;
top: -3px;
bottom: -3px;
left: -3px;
right: -3px;
}
div.ten:before {
content: "";
position: absolute;
border: 10px dashed #FF0000;
top: -8px;
bottom: -8px;
left: -8px;
right: -8px;
}
div.odd:before {left:0;right:0;border-radius:60px}
div {
overflow: hidden;
position: relative;
text-align:center;
padding:10px;
margin-bottom:20px;
}
<div class="two">Kupo nuts here</div>
<div class="five">Kupo nuts<br/>here</div>
<div class="ten">Kupo<br/>nuts<br/>here</div>
<div class="ten odd">Kupo<br/>nuts<br/>here</div>
Applied to small elements with big rounded corners may make for some fun effects.
div.two{border:2px dashed #FF0000}
div.five:before {
content: "";
position: absolute;
border: 5px dashed #FF0000;
top: -3px;
bottom: -3px;
left: -3px;
right: -3px;
}
div.ten:before {
content: "";
position: absolute;
border: 10px dashed #FF0000;
top: -8px;
bottom: -8px;
left: -8px;
right: -8px;
}
div.odd:before {left:0;right:0;border-radius:60px}
div {
overflow: hidden;
position: relative;
text-align:center;
padding:10px;
margin-bottom:20px;
}
<div class="two">Kupo nuts here</div>
<div class="five">Kupo nuts<br/>here</div>
<div class="ten">Kupo<br/>nuts<br/>here</div>
<div class="ten odd">Kupo<br/>nuts<br/>here</div>
div.two{border:2px dashed #FF0000}
div.five:before {
content: "";
position: absolute;
border: 5px dashed #FF0000;
top: -3px;
bottom: -3px;
left: -3px;
right: -3px;
}
div.ten:before {
content: "";
position: absolute;
border: 10px dashed #FF0000;
top: -8px;
bottom: -8px;
left: -8px;
right: -8px;
}
div.odd:before {left:0;right:0;border-radius:60px}
div {
overflow: hidden;
position: relative;
text-align:center;
padding:10px;
margin-bottom:20px;
}
<div class="two">Kupo nuts here</div>
<div class="five">Kupo nuts<br/>here</div>
<div class="ten">Kupo<br/>nuts<br/>here</div>
<div class="ten odd">Kupo<br/>nuts<br/>here</div>
answered Oct 15 '16 at 1:44
lenioialenioia
16113
16113
1
Strong work! This is the only one of these answers that really works without being terrible to maintain, IMO. Even the accepted answer only works for one edge of the div. This works for the whole border.
– Ryan Shillington
Jun 13 '18 at 13:52
add a comment |
1
Strong work! This is the only one of these answers that really works without being terrible to maintain, IMO. Even the accepted answer only works for one edge of the div. This works for the whole border.
– Ryan Shillington
Jun 13 '18 at 13:52
1
1
Strong work! This is the only one of these answers that really works without being terrible to maintain, IMO. Even the accepted answer only works for one edge of the div. This works for the whole border.
– Ryan Shillington
Jun 13 '18 at 13:52
Strong work! This is the only one of these answers that really works without being terrible to maintain, IMO. Even the accepted answer only works for one edge of the div. This works for the whole border.
– Ryan Shillington
Jun 13 '18 at 13:52
add a comment |
This is a really old question but it has a high ranking in Google so I'm going to throw in my method which could work depending on your needs.
In my case, I wanted a thick dashed border that had a minimal break in between dashes. I used a CSS pattern generator (like this one: http://www.patternify.com/) to create a 10px wide by 1px tall pattern. 9px of that is solid dash color, 1px is white.
In my CSS, I included that pattern as the background image, and then scaled it up by using the background-size attribute. I ended up with a 20px by 2px repeated dash, 18px of that being solid line and 2px white. You could scale it up even more for a really thick dashed line.
The nice thing is since the image is encoded as data you don't have the additional outside HTTP request, so there's no performance burden. I stored my image as a SASS variable so I could reuse it in my site.
Works for me! thx
– pztrick
Nov 13 '14 at 15:22
add a comment |
This is a really old question but it has a high ranking in Google so I'm going to throw in my method which could work depending on your needs.
In my case, I wanted a thick dashed border that had a minimal break in between dashes. I used a CSS pattern generator (like this one: http://www.patternify.com/) to create a 10px wide by 1px tall pattern. 9px of that is solid dash color, 1px is white.
In my CSS, I included that pattern as the background image, and then scaled it up by using the background-size attribute. I ended up with a 20px by 2px repeated dash, 18px of that being solid line and 2px white. You could scale it up even more for a really thick dashed line.
The nice thing is since the image is encoded as data you don't have the additional outside HTTP request, so there's no performance burden. I stored my image as a SASS variable so I could reuse it in my site.
Works for me! thx
– pztrick
Nov 13 '14 at 15:22
add a comment |
This is a really old question but it has a high ranking in Google so I'm going to throw in my method which could work depending on your needs.
In my case, I wanted a thick dashed border that had a minimal break in between dashes. I used a CSS pattern generator (like this one: http://www.patternify.com/) to create a 10px wide by 1px tall pattern. 9px of that is solid dash color, 1px is white.
In my CSS, I included that pattern as the background image, and then scaled it up by using the background-size attribute. I ended up with a 20px by 2px repeated dash, 18px of that being solid line and 2px white. You could scale it up even more for a really thick dashed line.
The nice thing is since the image is encoded as data you don't have the additional outside HTTP request, so there's no performance burden. I stored my image as a SASS variable so I could reuse it in my site.
This is a really old question but it has a high ranking in Google so I'm going to throw in my method which could work depending on your needs.
In my case, I wanted a thick dashed border that had a minimal break in between dashes. I used a CSS pattern generator (like this one: http://www.patternify.com/) to create a 10px wide by 1px tall pattern. 9px of that is solid dash color, 1px is white.
In my CSS, I included that pattern as the background image, and then scaled it up by using the background-size attribute. I ended up with a 20px by 2px repeated dash, 18px of that being solid line and 2px white. You could scale it up even more for a really thick dashed line.
The nice thing is since the image is encoded as data you don't have the additional outside HTTP request, so there's no performance burden. I stored my image as a SASS variable so I could reuse it in my site.
answered Nov 10 '14 at 16:12
Nick AngiolilloNick Angiolillo
47635
47635
Works for me! thx
– pztrick
Nov 13 '14 at 15:22
add a comment |
Works for me! thx
– pztrick
Nov 13 '14 at 15:22
Works for me! thx
– pztrick
Nov 13 '14 at 15:22
Works for me! thx
– pztrick
Nov 13 '14 at 15:22
add a comment |
So starting with the answer given and applying the fact that CSS3 allows multiple settings - the below code is useful for creating a complete box:
#border {
width: 200px;
height: 100px;
background: yellow;
text-align: center;
line-height: 100px;
background: linear-gradient(to right, orange 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(blue 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(to right, green 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(red 50%, rgba(255, 255, 255, 0) 0%);
background-position: top, right, bottom, left;
background-repeat: repeat-x, repeat-y;
background-size: 10px 1px, 1px 10px;
}
<div id="border">
bordered area
</div>
Its worth noting that the 10px in the background size gives the area that the dash and gap will cover. The 50% of the background tag is how wide the dash actually is. It is therefore possible to have different length dashes on each border side.
add a comment |
So starting with the answer given and applying the fact that CSS3 allows multiple settings - the below code is useful for creating a complete box:
#border {
width: 200px;
height: 100px;
background: yellow;
text-align: center;
line-height: 100px;
background: linear-gradient(to right, orange 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(blue 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(to right, green 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(red 50%, rgba(255, 255, 255, 0) 0%);
background-position: top, right, bottom, left;
background-repeat: repeat-x, repeat-y;
background-size: 10px 1px, 1px 10px;
}
<div id="border">
bordered area
</div>
Its worth noting that the 10px in the background size gives the area that the dash and gap will cover. The 50% of the background tag is how wide the dash actually is. It is therefore possible to have different length dashes on each border side.
add a comment |
So starting with the answer given and applying the fact that CSS3 allows multiple settings - the below code is useful for creating a complete box:
#border {
width: 200px;
height: 100px;
background: yellow;
text-align: center;
line-height: 100px;
background: linear-gradient(to right, orange 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(blue 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(to right, green 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(red 50%, rgba(255, 255, 255, 0) 0%);
background-position: top, right, bottom, left;
background-repeat: repeat-x, repeat-y;
background-size: 10px 1px, 1px 10px;
}
<div id="border">
bordered area
</div>
Its worth noting that the 10px in the background size gives the area that the dash and gap will cover. The 50% of the background tag is how wide the dash actually is. It is therefore possible to have different length dashes on each border side.
So starting with the answer given and applying the fact that CSS3 allows multiple settings - the below code is useful for creating a complete box:
#border {
width: 200px;
height: 100px;
background: yellow;
text-align: center;
line-height: 100px;
background: linear-gradient(to right, orange 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(blue 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(to right, green 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(red 50%, rgba(255, 255, 255, 0) 0%);
background-position: top, right, bottom, left;
background-repeat: repeat-x, repeat-y;
background-size: 10px 1px, 1px 10px;
}
<div id="border">
bordered area
</div>
Its worth noting that the 10px in the background size gives the area that the dash and gap will cover. The 50% of the background tag is how wide the dash actually is. It is therefore possible to have different length dashes on each border side.
#border {
width: 200px;
height: 100px;
background: yellow;
text-align: center;
line-height: 100px;
background: linear-gradient(to right, orange 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(blue 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(to right, green 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(red 50%, rgba(255, 255, 255, 0) 0%);
background-position: top, right, bottom, left;
background-repeat: repeat-x, repeat-y;
background-size: 10px 1px, 1px 10px;
}
<div id="border">
bordered area
</div>
#border {
width: 200px;
height: 100px;
background: yellow;
text-align: center;
line-height: 100px;
background: linear-gradient(to right, orange 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(blue 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(to right, green 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(red 50%, rgba(255, 255, 255, 0) 0%);
background-position: top, right, bottom, left;
background-repeat: repeat-x, repeat-y;
background-size: 10px 1px, 1px 10px;
}
<div id="border">
bordered area
</div>
edited May 16 '18 at 10:45
Tushar
3,46251632
3,46251632
answered May 16 '18 at 10:33
Ukuser32Ukuser32
1,01421124
1,01421124
add a comment |
add a comment |
Short answer: You can't.
You will have to use border-image
property and a few images.
add a comment |
Short answer: You can't.
You will have to use border-image
property and a few images.
add a comment |
Short answer: You can't.
You will have to use border-image
property and a few images.
Short answer: You can't.
You will have to use border-image
property and a few images.
answered Jun 6 '11 at 10:04
CrozinCrozin
35.5k1076122
35.5k1076122
add a comment |
add a comment |
IF you're only targeting modern browsers, AND you can have your border on a separate element from your content, then you can use the CSS scale transform to get a larger dot or dash:
border: 1px dashed black;
border-radius: 10px;
-webkit-transform: scale(8);
transform: scale(8);
It takes a lot of positional tweaking to get it to line up, but it works. By changing the thickness of the border, the starting size and the scale factor, you can get to just about thickness-length ratio you want. Only thing you can't touch is dash-to-gap ratio.
By doing so content will also gets appliedscale(8)
– Pardeep Jain
Aug 9 '18 at 7:36
add a comment |
IF you're only targeting modern browsers, AND you can have your border on a separate element from your content, then you can use the CSS scale transform to get a larger dot or dash:
border: 1px dashed black;
border-radius: 10px;
-webkit-transform: scale(8);
transform: scale(8);
It takes a lot of positional tweaking to get it to line up, but it works. By changing the thickness of the border, the starting size and the scale factor, you can get to just about thickness-length ratio you want. Only thing you can't touch is dash-to-gap ratio.
By doing so content will also gets appliedscale(8)
– Pardeep Jain
Aug 9 '18 at 7:36
add a comment |
IF you're only targeting modern browsers, AND you can have your border on a separate element from your content, then you can use the CSS scale transform to get a larger dot or dash:
border: 1px dashed black;
border-radius: 10px;
-webkit-transform: scale(8);
transform: scale(8);
It takes a lot of positional tweaking to get it to line up, but it works. By changing the thickness of the border, the starting size and the scale factor, you can get to just about thickness-length ratio you want. Only thing you can't touch is dash-to-gap ratio.
IF you're only targeting modern browsers, AND you can have your border on a separate element from your content, then you can use the CSS scale transform to get a larger dot or dash:
border: 1px dashed black;
border-radius: 10px;
-webkit-transform: scale(8);
transform: scale(8);
It takes a lot of positional tweaking to get it to line up, but it works. By changing the thickness of the border, the starting size and the scale factor, you can get to just about thickness-length ratio you want. Only thing you can't touch is dash-to-gap ratio.
answered Dec 6 '13 at 19:16
DaveDave
479212
479212
By doing so content will also gets appliedscale(8)
– Pardeep Jain
Aug 9 '18 at 7:36
add a comment |
By doing so content will also gets appliedscale(8)
– Pardeep Jain
Aug 9 '18 at 7:36
By doing so content will also gets applied
scale(8)
– Pardeep Jain
Aug 9 '18 at 7:36
By doing so content will also gets applied
scale(8)
– Pardeep Jain
Aug 9 '18 at 7:36
add a comment |
So many people are say "You can't". Yes you can. It's true that there is not a css rule to control the gutter space between the dashes but css has other abilities. Don't be so quick to say that a thing can not be done.
.hr {
border-top: 5px dashed #CFCBCC;
margin: 30px 0;
position: relative;
}
.hr:before {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -2px;
width: 100%;
}
.hr:after {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -13px;
width: 100%;
}
Basically the border-top height (5px in this case) is the rule that determines the gutter "width". OIf course you would need to adjust the colors to match your needs. This also is a small example for a horizontal line, use left and right to make the vertical line.
1
To be fair, I think most people are saying you can't do it to the literal question of adjusting the border dotted styling. They're not saying something similar isn't possible using other CSS properties. In my opinion it makes a lot more sense from a semantic point of view to use a background image or border-image as others have shown, than use pseudo elements and a dozen lines of CSS.
– Alex
Mar 3 '14 at 11:49
add a comment |
So many people are say "You can't". Yes you can. It's true that there is not a css rule to control the gutter space between the dashes but css has other abilities. Don't be so quick to say that a thing can not be done.
.hr {
border-top: 5px dashed #CFCBCC;
margin: 30px 0;
position: relative;
}
.hr:before {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -2px;
width: 100%;
}
.hr:after {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -13px;
width: 100%;
}
Basically the border-top height (5px in this case) is the rule that determines the gutter "width". OIf course you would need to adjust the colors to match your needs. This also is a small example for a horizontal line, use left and right to make the vertical line.
1
To be fair, I think most people are saying you can't do it to the literal question of adjusting the border dotted styling. They're not saying something similar isn't possible using other CSS properties. In my opinion it makes a lot more sense from a semantic point of view to use a background image or border-image as others have shown, than use pseudo elements and a dozen lines of CSS.
– Alex
Mar 3 '14 at 11:49
add a comment |
So many people are say "You can't". Yes you can. It's true that there is not a css rule to control the gutter space between the dashes but css has other abilities. Don't be so quick to say that a thing can not be done.
.hr {
border-top: 5px dashed #CFCBCC;
margin: 30px 0;
position: relative;
}
.hr:before {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -2px;
width: 100%;
}
.hr:after {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -13px;
width: 100%;
}
Basically the border-top height (5px in this case) is the rule that determines the gutter "width". OIf course you would need to adjust the colors to match your needs. This also is a small example for a horizontal line, use left and right to make the vertical line.
So many people are say "You can't". Yes you can. It's true that there is not a css rule to control the gutter space between the dashes but css has other abilities. Don't be so quick to say that a thing can not be done.
.hr {
border-top: 5px dashed #CFCBCC;
margin: 30px 0;
position: relative;
}
.hr:before {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -2px;
width: 100%;
}
.hr:after {
background-color: #FFFFFF;
content: "";
height: 10px;
position: absolute;
top: -13px;
width: 100%;
}
Basically the border-top height (5px in this case) is the rule that determines the gutter "width". OIf course you would need to adjust the colors to match your needs. This also is a small example for a horizontal line, use left and right to make the vertical line.
answered Mar 1 '14 at 17:23
devinfddevinfd
5027
5027
1
To be fair, I think most people are saying you can't do it to the literal question of adjusting the border dotted styling. They're not saying something similar isn't possible using other CSS properties. In my opinion it makes a lot more sense from a semantic point of view to use a background image or border-image as others have shown, than use pseudo elements and a dozen lines of CSS.
– Alex
Mar 3 '14 at 11:49
add a comment |
1
To be fair, I think most people are saying you can't do it to the literal question of adjusting the border dotted styling. They're not saying something similar isn't possible using other CSS properties. In my opinion it makes a lot more sense from a semantic point of view to use a background image or border-image as others have shown, than use pseudo elements and a dozen lines of CSS.
– Alex
Mar 3 '14 at 11:49
1
1
To be fair, I think most people are saying you can't do it to the literal question of adjusting the border dotted styling. They're not saying something similar isn't possible using other CSS properties. In my opinion it makes a lot more sense from a semantic point of view to use a background image or border-image as others have shown, than use pseudo elements and a dozen lines of CSS.
– Alex
Mar 3 '14 at 11:49
To be fair, I think most people are saying you can't do it to the literal question of adjusting the border dotted styling. They're not saying something similar isn't possible using other CSS properties. In my opinion it makes a lot more sense from a semantic point of view to use a background image or border-image as others have shown, than use pseudo elements and a dozen lines of CSS.
– Alex
Mar 3 '14 at 11:49
add a comment |
This is an old, but still very relevant topic. The current top answer works well, but only for very small dots. As Bhojendra Rauniyar already pointed out in the comments, for larger (>2px) dots, the dots appear square, not round. I found this page searching for spaced dots, not spaced squares (or even dashes, as some answers here use).
Building on this, I used radial-gradient
. Also, using the answer from Ukuser32, the dot-properties can easily be repeated for all four borders. Only the corners are not perfect.
div {
padding: 1em;
background-image:
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px);
background-position: top, right, bottom, left;
background-size: 15px 5px, 5px 15px;
background-repeat: repeat-x, repeat-y;
}
<div>Some content with round, spaced dots as border</div>
The radial-gradient
expects:
- the shape and optional position
- two or more stops: a color and radius
Here, I wanted a 5 pixel diameter (2.5px radius) dot, with 2 times the diameter (10px) between the dots, adding up to 15px. The background-size
should match these.
The two stops are defined such that the dot is nice and smooth: solid black for half the radius and than a gradient to the full radius.
add a comment |
This is an old, but still very relevant topic. The current top answer works well, but only for very small dots. As Bhojendra Rauniyar already pointed out in the comments, for larger (>2px) dots, the dots appear square, not round. I found this page searching for spaced dots, not spaced squares (or even dashes, as some answers here use).
Building on this, I used radial-gradient
. Also, using the answer from Ukuser32, the dot-properties can easily be repeated for all four borders. Only the corners are not perfect.
div {
padding: 1em;
background-image:
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px);
background-position: top, right, bottom, left;
background-size: 15px 5px, 5px 15px;
background-repeat: repeat-x, repeat-y;
}
<div>Some content with round, spaced dots as border</div>
The radial-gradient
expects:
- the shape and optional position
- two or more stops: a color and radius
Here, I wanted a 5 pixel diameter (2.5px radius) dot, with 2 times the diameter (10px) between the dots, adding up to 15px. The background-size
should match these.
The two stops are defined such that the dot is nice and smooth: solid black for half the radius and than a gradient to the full radius.
add a comment |
This is an old, but still very relevant topic. The current top answer works well, but only for very small dots. As Bhojendra Rauniyar already pointed out in the comments, for larger (>2px) dots, the dots appear square, not round. I found this page searching for spaced dots, not spaced squares (or even dashes, as some answers here use).
Building on this, I used radial-gradient
. Also, using the answer from Ukuser32, the dot-properties can easily be repeated for all four borders. Only the corners are not perfect.
div {
padding: 1em;
background-image:
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px);
background-position: top, right, bottom, left;
background-size: 15px 5px, 5px 15px;
background-repeat: repeat-x, repeat-y;
}
<div>Some content with round, spaced dots as border</div>
The radial-gradient
expects:
- the shape and optional position
- two or more stops: a color and radius
Here, I wanted a 5 pixel diameter (2.5px radius) dot, with 2 times the diameter (10px) between the dots, adding up to 15px. The background-size
should match these.
The two stops are defined such that the dot is nice and smooth: solid black for half the radius and than a gradient to the full radius.
This is an old, but still very relevant topic. The current top answer works well, but only for very small dots. As Bhojendra Rauniyar already pointed out in the comments, for larger (>2px) dots, the dots appear square, not round. I found this page searching for spaced dots, not spaced squares (or even dashes, as some answers here use).
Building on this, I used radial-gradient
. Also, using the answer from Ukuser32, the dot-properties can easily be repeated for all four borders. Only the corners are not perfect.
div {
padding: 1em;
background-image:
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px);
background-position: top, right, bottom, left;
background-size: 15px 5px, 5px 15px;
background-repeat: repeat-x, repeat-y;
}
<div>Some content with round, spaced dots as border</div>
The radial-gradient
expects:
- the shape and optional position
- two or more stops: a color and radius
Here, I wanted a 5 pixel diameter (2.5px radius) dot, with 2 times the diameter (10px) between the dots, adding up to 15px. The background-size
should match these.
The two stops are defined such that the dot is nice and smooth: solid black for half the radius and than a gradient to the full radius.
div {
padding: 1em;
background-image:
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px);
background-position: top, right, bottom, left;
background-size: 15px 5px, 5px 15px;
background-repeat: repeat-x, repeat-y;
}
<div>Some content with round, spaced dots as border</div>
div {
padding: 1em;
background-image:
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle at 2.5px, #000 1.25px, rgba(255,255,255,0) 2.5px),
radial-gradient(circle, #000 1.25px, rgba(255,255,255,0) 2.5px);
background-position: top, right, bottom, left;
background-size: 15px 5px, 5px 15px;
background-repeat: repeat-x, repeat-y;
}
<div>Some content with round, spaced dots as border</div>
answered Nov 21 '18 at 8:44
Marten KoetsierMarten Koetsier
1,63011325
1,63011325
add a comment |
add a comment |
AFAIK there isn't a way to do this. You could use a dashed border or perhaps increase the width of the border a bit, but just getting more spaced out dots is impossible with CSS.
add a comment |
AFAIK there isn't a way to do this. You could use a dashed border or perhaps increase the width of the border a bit, but just getting more spaced out dots is impossible with CSS.
add a comment |
AFAIK there isn't a way to do this. You could use a dashed border or perhaps increase the width of the border a bit, but just getting more spaced out dots is impossible with CSS.
AFAIK there isn't a way to do this. You could use a dashed border or perhaps increase the width of the border a bit, but just getting more spaced out dots is impossible with CSS.
answered Jun 6 '11 at 10:03
BojanglesBojangles
68.3k42147193
68.3k42147193
add a comment |
add a comment |
You could create a canvas (via javascript) and draw a dotted line within. Within the canvas you can control how long the dash and the space in between shall be.
That is a very convoluted solution. I can't help but feel that this would also cost a tiny bit more in performance and perceived load times, depending on the weight of the rest of the JS on the page.
– Emmett R.
May 24 '16 at 16:48
add a comment |
You could create a canvas (via javascript) and draw a dotted line within. Within the canvas you can control how long the dash and the space in between shall be.
That is a very convoluted solution. I can't help but feel that this would also cost a tiny bit more in performance and perceived load times, depending on the weight of the rest of the JS on the page.
– Emmett R.
May 24 '16 at 16:48
add a comment |
You could create a canvas (via javascript) and draw a dotted line within. Within the canvas you can control how long the dash and the space in between shall be.
You could create a canvas (via javascript) and draw a dotted line within. Within the canvas you can control how long the dash and the space in between shall be.
answered Apr 25 '13 at 13:39
velopvelop
1,5071223
1,5071223
That is a very convoluted solution. I can't help but feel that this would also cost a tiny bit more in performance and perceived load times, depending on the weight of the rest of the JS on the page.
– Emmett R.
May 24 '16 at 16:48
add a comment |
That is a very convoluted solution. I can't help but feel that this would also cost a tiny bit more in performance and perceived load times, depending on the weight of the rest of the JS on the page.
– Emmett R.
May 24 '16 at 16:48
That is a very convoluted solution. I can't help but feel that this would also cost a tiny bit more in performance and perceived load times, depending on the weight of the rest of the JS on the page.
– Emmett R.
May 24 '16 at 16:48
That is a very convoluted solution. I can't help but feel that this would also cost a tiny bit more in performance and perceived load times, depending on the weight of the rest of the JS on the page.
– Emmett R.
May 24 '16 at 16:48
add a comment |
Building 4 edges solution basing on @Eagorajose's answer with shorthand syntax:
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
#page {
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
width: 100px;
height: 100px;
}
<div id="page"></div>
add a comment |
Building 4 edges solution basing on @Eagorajose's answer with shorthand syntax:
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
#page {
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
width: 100px;
height: 100px;
}
<div id="page"></div>
add a comment |
Building 4 edges solution basing on @Eagorajose's answer with shorthand syntax:
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
#page {
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
width: 100px;
height: 100px;
}
<div id="page"></div>
Building 4 edges solution basing on @Eagorajose's answer with shorthand syntax:
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
#page {
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
width: 100px;
height: 100px;
}
<div id="page"></div>
#page {
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
width: 100px;
height: 100px;
}
<div id="page"></div>
#page {
background: linear-gradient(to right, #000 33%, #fff 0%) top/10px 1px repeat-x, /* top */
linear-gradient(#000 33%, #fff 0%) right/1px 10px repeat-y, /* right */
linear-gradient(to right, #000 33%, #fff 0%) bottom/10px 1px repeat-x, /* bottom */
linear-gradient(#000 33%, #fff 0%) left/1px 10px repeat-y; /* left */
width: 100px;
height: 100px;
}
<div id="page"></div>
answered Nov 14 '18 at 21:54
Aleksander StelmaczonekAleksander Stelmaczonek
430812
430812
add a comment |
add a comment |
<div style="width: 100%; height: 100vh; max-height: 20px; max-width: 100%; background: url('https://kajabi-storefronts-production.global.ssl.fastly.net/kajabi-storefronts-production/themes/853636/settings_images/Ei2yf3t7TvyRpFaLQZiX_dot.jpg') #000; background-repeat: repeat;"> </div>
this is what I did - use an image
enter image description here
New contributor
add a comment |
<div style="width: 100%; height: 100vh; max-height: 20px; max-width: 100%; background: url('https://kajabi-storefronts-production.global.ssl.fastly.net/kajabi-storefronts-production/themes/853636/settings_images/Ei2yf3t7TvyRpFaLQZiX_dot.jpg') #000; background-repeat: repeat;"> </div>
this is what I did - use an image
enter image description here
New contributor
add a comment |
<div style="width: 100%; height: 100vh; max-height: 20px; max-width: 100%; background: url('https://kajabi-storefronts-production.global.ssl.fastly.net/kajabi-storefronts-production/themes/853636/settings_images/Ei2yf3t7TvyRpFaLQZiX_dot.jpg') #000; background-repeat: repeat;"> </div>
this is what I did - use an image
enter image description here
New contributor
<div style="width: 100%; height: 100vh; max-height: 20px; max-width: 100%; background: url('https://kajabi-storefronts-production.global.ssl.fastly.net/kajabi-storefronts-production/themes/853636/settings_images/Ei2yf3t7TvyRpFaLQZiX_dot.jpg') #000; background-repeat: repeat;"> </div>
this is what I did - use an image
enter image description here
New contributor
New contributor
answered 14 hours ago
Christine Nicole YuChristine Nicole Yu
11
11
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6250394%2fhow-to-increase-space-between-dotted-border-dots%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown