Can someone explain me conceptually, .box::before why does ‘Hello World’ get printed inside the box rather than before the box?
.box {
display:flex;
width:200px;
height:200px;
font-size: 2em;
border:5px solid red;
}
.box::before {
content: 'Hello World';
width: 0px;
}
<a class="box"></a>
2
Answers
Word breaks after
width: 0px
because there is no space for both the words. When you removewidth: 0px
, it becomes default width which iswidth: auto
.And default value for
white-space
isnormal
, If you don’t want word to break you can usewhite-space: nowrap
.Read more about white space on MDN.