CSS text after div
3 answers
Changing the property value display
to inline-block
will do this.
.legend {
display: inline-block;
width: 40px;
height: 40px;
border-radius: 10px;
background-color: orange;
vertical-align: middle;/* Ensures that the text is vertically aligned in the middle */
}
<div class="legend"></div> New Order
+7
source to share
Using
display: inline-table;
instead
display: table;
.legend {
display: inline-table;
width: 40px;
height: 40px;
border-radius: 10px;
background: orange;
}
<div class="legend"></div> New Order
+1
source to share
To display the text next to the box and give it the correct line height, you can use the following code:
.legend-wrapper {
line-height: 40px; /* Same as the height of the block */
}
.legend {
display: block;
float: left;
width: 40px;
height: 40px;
border-radius: 10px;
background: orange;
margin-right: 10px; /* Add some between text and block */
}
<div class="legend-wrapper">
<div class="legend"></div> New Order
</div>
+1
source to share