CSS border less than 1px

CssBorder

Css Problem Overview


> 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?

Css Solutions


Solution 1 - Css

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>

Output

enter image description here

Which gives the illusion that the last DIV has a smaller border width, because the blue border blends more with the white background.


Edit: Alternate solution

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>

Solution 2 - Css

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.

Solution 3 - Css

try giving border in % for exapmle 0.1% according to your need.

Solution 4 - Css

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWizardView Question on Stackoverflow
Solution 1 - CssYanick RochonView Answer on Stackoverflow
Solution 2 - Cssuser149341View Answer on Stackoverflow
Solution 3 - CssGagan DeepView Answer on Stackoverflow
Solution 4 - CssSharpless512View Answer on Stackoverflow