can i have half pixel in border width like this , I tried it but it is not working
element.style {
border-left-width: 0.5px;
border-color: #818181;
border-left-style: solid;
}
can i have half pixel in border width like this , I tried it but it is not working
element.style {
border-left-width: 0.5px;
border-color: #818181;
border-left-style: solid;
}
Most of browsers will not display fraction pixel borders correctly.
It's better to use box-shadow
for such cases. It can display fractions of pixels.
.one-pixel-border {
box-shadow: -1px 0 0 #818181;
}
.half-pixel-border {
box-shadow: -.5px 0 0 #818181;
}
.quarter-pixel-border {
box-shadow: -.25px 0 0 #818181;
}
<div class="one-pixel-border">
one pixel border
</div>
<div class="half-pixel-border">
half pixel border
</div>
<div class="quarter-pixel-border">
quarter pixel border
</div>
I think that is achievable by either transform
or translate
options here. For example this:
border-bottom: 1px #ff0000 solid;
transform: scaleY(0.5);
will render a sort of a half-size border. Also check the article by Priit Pirita which might be useful :)
Theorically speaking, you can't do that because the pixel is the smallest physical unit used to display stuff on your screen ; however, you could want to do that for high resolution devices, like Retina and others.
The reason why border-width:0.5px
does not work is that browsers do layout with regards to (device independent) pixels. Even though physical pixels might be much smaller, so they can render elements smaller than a pixel, this doesn't affect the layout.
Since the css border
property affects layout, browsers will only allow integer pixel widths. The box-shadow
only affects the rendering and not the layout, and therefore supports fractional units.
You could try to get a smaller border then 1px by using em.
But anyway it will always round to full pixels because like Jeremy said it is the smallest display unit.