CSS bar chart is a form that we often encounter in web design. Bar charts can visually represent quantities in the form of bar graphs.
What is the implementation method of basic CSS bar chart? Let's look at the following example:
This is xhtml The code defines a container, applies the class graph, which includes an xhtml element strong, and applies the class bar to this element.
Let’s look at the following CSS definition:
. graph {
position: relative; /* IE is dumb */
width: 200px;
border: 1px solid #B1D632;
padding: 2px;
}
.graph . bar {
display: block;
position: relative;
background: #B1D632;
text-align: center;
color: #333;
height: 2em;
line-height: 2em;
}
.graph .bar span { position: absolute; left: 1em; }
Through the definition of the border and color above, we outline a strip shape. We define the size of the set area in the xhtml code with style="width: 24%;". Such a basic bar chart is complete!
Let’s see the final running effect: