box-decoration-break helps to define how elements should be rendered across lines (#tilPost)

In the past, I needed to style link elements in particular pretty or fancy ways. These visual effects often turned out to be trickier than expected because links can be broken across several lines. The spread then messed up the beau…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

In the past, I needed to style link elements in particular pretty or fancy ways. These visual effects often turned out to be trickier than expected because links can be broken across several lines. The spread then messed up the beautiful styling. For example, padding and border-radius were only applied to the beginning and end of the elements. This behavior is not always what you want if your element spans across several lines, though.

Example of a cut link element which looks quite ugly spread across two lines

Today I learned that you could use box-decoration-break to define how elements are rendered across pages, columns, and lines. It accepts two values: clone (the default value) and slice.

clone leads to "cut" styles. In contrast, slice changes the rendering so that every element fragment (an element spread across two lines includes two fragments) is rendered independently – thus, styles are applied several times. ?

CSS properties that are rendered independently are the following:

  • background
  • border
  • border-image
  • box-shadow
  • clip-path
  • margin
  • padding

box-decoration-break is a welcome help when dealing with "special" fancy styles across lines and columns. ?

DevSheet showing the difference between box-decoration-break: clone and box-decoration-break: slice

If you want to play around with it you can have a look at a CodePen example or check the excellent MDN docs for box-decoration-break.


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2019-12-13T23:00:00+00:00) box-decoration-break helps to define how elements should be rendered across lines (#tilPost). Retrieved from https://www.scien.cx/2019/12/13/box-decoration-break-helps-to-define-how-elements-should-be-rendered-across-lines-tilpost/

MLA
" » box-decoration-break helps to define how elements should be rendered across lines (#tilPost)." Stefan Judis | Sciencx - Friday December 13, 2019, https://www.scien.cx/2019/12/13/box-decoration-break-helps-to-define-how-elements-should-be-rendered-across-lines-tilpost/
HARVARD
Stefan Judis | Sciencx Friday December 13, 2019 » box-decoration-break helps to define how elements should be rendered across lines (#tilPost)., viewed ,<https://www.scien.cx/2019/12/13/box-decoration-break-helps-to-define-how-elements-should-be-rendered-across-lines-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » box-decoration-break helps to define how elements should be rendered across lines (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2019/12/13/box-decoration-break-helps-to-define-how-elements-should-be-rendered-across-lines-tilpost/
CHICAGO
" » box-decoration-break helps to define how elements should be rendered across lines (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2019/12/13/box-decoration-break-helps-to-define-how-elements-should-be-rendered-across-lines-tilpost/
IEEE
" » box-decoration-break helps to define how elements should be rendered across lines (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2019/12/13/box-decoration-break-helps-to-define-how-elements-should-be-rendered-across-lines-tilpost/. [Accessed: ]
rf:citation
» box-decoration-break helps to define how elements should be rendered across lines (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2019/12/13/box-decoration-break-helps-to-define-how-elements-should-be-rendered-across-lines-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.