How does the browser decide how many pixels each of the 3 lines will get? Here are some cases that I hope will help you understand:
border: 1px double black
=> 1,0,0
or 0,1,0
or 0,0,1
border: 2px double black
=> 0,2,0
or 1,1,0
or 1,0,1
border: 4px double black
=> 2,1,1
or 1,2,1
or 1,1,2
border: 5px double black
=> 2,2,1
or 2,1,2
or 1,3,1
Are there any inconsistencies between browsers?
I'm mostly curious about this question and would appreciate an answer from a reliable source.
The border-style shorthand CSS property sets the line style for all four sides of an element's border.
dotted - Defines a dotted border. dashed - Defines a dashed border. solid - Defines a solid border. double - Defines a double border.
The border-collapse CSS property sets whether cells inside a <table> have shared or separate borders.
In fact, it's quite easy to create double borders with CSS because you can use the border property and assign a style of 'double'. Choose a border width of 3px or more and a color and there you have it!
From the specification we can read:
Two parallel solid lines with some space between them. (The thickness of the lines is not specified, but the sum of the lines and the space must equal border-width.)
So basically there is no rule defined thus each browser may use its own implementation. They simply need to respect the sum of the lines.
As a side note, the specification doesn't always define the exact behavior. Here is another question related to border too (If border-color is not set, it inherits the color of the element) where you can read UAs may choose their own algorithm.
Update
For google chrome you can check the Chromimum source code here: https://cs.chromium.org/ and with some search you will find the component that is used to paint the border BoxBorderPainter
and inside there is a function called DrawDoubleBorder()
. If you investigate this code you will probably find what you want.
For Firefox you can do the same searching here https://dxr.mozilla.org and you will find the nsCSSBorderRenderer
and inside the DrawBorders()
function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With