Possible Duplicate:
HTML: Sub-pixel border
The default border:1px
is too big. However, border: 0.5px solid;
is not working.
Is there a CSS solution that would make the border half the size?
Possible Duplicate:
HTML: Sub-pixel border
The default border:1px
is too big. However, border: 0.5px solid;
is not working.
Is there a CSS solution that would make the border half the size?
A pixel is the smallest unit value to render something with, but you can trick thickness with optical illusions by modifying colors (the eye can only see up to a certain resolution too).
Here is a test to prove this point:
div { border-color: blue; border-style: solid; margin: 2px; }
div.b1 { border-width: 1px; }
div.b2 { border-width: 0.1em; }
div.b3 { border-width: 0.01em; }
div.b4 { border-width: 1px; border-color: rgb(160,160,255); }
<div class="b1">Some text</div>
<div class="b2">Some text</div>
<div class="b3">Some text</div>
<div class="b4">Some text</div>
Which gives the illusion that the last DIV
has a smaller border width, because the blue border blends more with the white background.
Alpha values may also be used to simulate the same effect, without the need to calculate and manipulate RGB values.
.container {
border-style: solid;
border-width: 1px;
margin-bottom: 10px;
}
.border-100 { border-color: rgba(0,0,255,1); }
.border-75 { border-color: rgba(0,0,255,0.75); }
.border-50 { border-color: rgba(0,0,255,0.5); }
.border-25 { border-color: rgba(0,0,255,0.25); }
<div class="container border-100">Container 1 (alpha = 1)</div>
<div class="container border-75">Container 2 (alpha = 0.75)</div>
<div class="container border-50">Container 3 (alpha = 0.5)</div>
<div class="container border-25">Container 4 (alpha = 0.25)</div>
0.5px and
0.25px, and it doesn't work on UHD screens (as you mentioned). The vast majority of users do not have those screens, so your solution may only be truly practical in a few years... At the moment, this answer be be the only viable solution. I will also add a solution with a
rgba()` alternative, to prevent calculating RGB values. –
Puddling 0.5px
at all. Other units may be used, but it's deceiving, really. Truth be told, until displays aren't pixel-based anymore (i.e. and use some kind of "true vision" future tech), we are bound to pixels because of hardware limitations. Alpha blending and retina display are nothing but hacks over the current technology, to offer better image quality, but on the programming side, sub-pixels are always hacks. Personally, I do not try to hide this fact and tell the programmers the real thing, instead of some utopia. :) –
Puddling rgb(r,g,b)
requires manually calculating the correct "arbitrary" color to simulate sub-pixel borders, 2) using rgb(r,g,b)
may not look well (or not at all) with certain color combination. Whereas using rgba(r,b,g,a)
: 1) only requires a single ajudtement of the alpha component, 2) blends the color with the background, also called alpha blending, a technique used by every graphic engine. Sub-pixel is physically impossible, but there are ways around it. This is what this answer is all about. :) –
Puddling It's impossible to draw a line on screen that's thinner than one pixel. Try using a more subtle color for the border instead.
try giving border in % for example 0.1% according to your need.
The minimum width that your screen can display is 1 pixel. So its impossible to display less then 1px. 1 pixels can only have 1 color and cannot be split up.
© 2022 - 2024 — McMap. All rights reserved.
em
) the idea of "real physical pixels" and "viewport css pixels" is only platform dependent. Just like how OpenGL provides an abstraction of the display area. The vast majority of devices use physical pixels and, until new technologies are released, this will still be the case for most use cases. – Puddling