Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a small color box using html and css?

Tags:

html

css

I have a picture on a html file/site and I want to add the list of available colors for that picture. I want to create very small boxes or dots, a small box for every color.

How can I do this?

Thanks!

like image 476
Ionut Cristea Avatar asked Jun 27 '12 12:06

Ionut Cristea


People also ask

How do I make a small square box in HTML?

Put the text inside a header or <p> inside the <div></div> Then it will be inside the box.


2 Answers

With old browsers, you would often use float, but then you would need a clearfix so this approach is not used often these days.

.box {   float: left;   width: 20px;   height: 20px;   border: 1px solid rgba(0, 0, 0, .2); }  .blue {   background: #13b4ff; }  .purple {   background: #ab3fdd; }  .wine {   background: #ae163e; }
<div class="box blue"></div> <div class="box purple"></div> <div class="box wine"></div>

In modern browsers, the easiest way is with flexbox:

.wrapper {   display: flex; }  .box {   width: 20px;   height: 20px;   border: 1px solid rgba(0, 0, 0, .2); }  .blue {   background: #13b4ff; }  .purple {   background: #ab3fdd; }  .wine {   background: #ae163e; }
<div class="wrapper">   <div class="box blue"></div>   <div class="box purple"></div>   <div class="box wine"></div> </div>

Or alternatively with display: inline-block:

.box {   display: inline-block;   width: 20px;   height: 20px;   border: 1px solid rgba(0, 0, 0, .2); }  .blue {   background: #13b4ff; }  .purple {   background: #ab3fdd; }  .wine {   background: #ae163e; }
<div class="box blue"></div> <div class="box purple"></div> <div class="box wine"></div>
like image 149
Etheryte Avatar answered Sep 21 '22 08:09

Etheryte


If you want to create a small dots, just use icon from font awesome.

fa fa-circle 
like image 23
syadiqfaliq Avatar answered Sep 24 '22 08:09

syadiqfaliq