Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to create a small square colour filled box in HTML & CSS. And most important - I want to write one line after the box

Tags:

html

css

i have created colored squre box using code

.box {
  height: 20px;
  width: 20px;
  margin-bottom: 15px;
  border: 1px solid black;
}

.red {
  background-color: red;
}

.green {
  background-color: green;
}

.blue {
  background-color: blue;
}
<div class='box red'></div>= Super Fast Trains<br>
<div class='box green'></div>= Mail/Express Trains<br>
<div class='box blue'></div>= Local/ Passenger Trains

But I want the text beside the boxes which is not showing in this current code.I also tried 'float:left' attribute but that making the second & third lines not showing in same margin. See the code at https://jsfiddle.net/14to4gej/
So please help me with correct modification in my code to get text after boxes an in same margin. Thanks in advance.

like image 837
j. dot Avatar asked Mar 02 '18 14:03

j. dot


2 Answers

Try next:

.box {
  float: left;
  height: 20px;
  width: 20px;
  margin-bottom: 15px;
  border: 1px solid black;
  clear: both;
}

.red {
  background-color: red;
}

.green {
  background-color: green;
}

.blue {
  background-color: blue;
}
<div><div class='box red'></div>= Super Fast Trains</div>
<br>
<div><div class='box green'></div>= Mail/Express Trains</div>
<br>
<div><div class='box blue'></div>= Local/ Passenger Trains</div>
like image 142
Max Wolfen Avatar answered Sep 16 '22 23:09

Max Wolfen


How about using the square html entity?

<div style="color:blue">&#9632;</div>
like image 29
RobD Avatar answered Sep 20 '22 23:09

RobD