CSS
CSS is an acronym for Cascading Style Sheets. As a presentation language, CSS is used to style elements of an HTML document. CSS handles styling and presentation issues such as the colour, font, and position of an HTML element.
Consider the CSS as contained in the following string:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const css = `.box{
background: black;
font: 14px "Lucida Console";
position: fixed;
}
.box .head{
background: lime;
color: black;
display: flex;
justify-content: space-between;
}
.box .title{
}
.box .close{
}
.box .body{
color: lime;
}`;
The above CSS code defines various components that make up our dialog box. First is the overall box itself. The box is sub-divided into various components: the head and the body. The head is further sub-divided into the title and the button to close the box. Here’s an explanation of our box’s components.
- The block
.boxdeclares the default styling of the overall box itself. By default, thebackgroundof the box is declared to be black. If you want a different colour for the background, feel free to browse the list of named colours and choose a colour you like. The text of the box has a defaultfontsize of 14 pixels and using Lucida Console as the font family. Here is a list of common font families. We want thepositionof the box to be fixed. A benefit of having a fixed position for our box is that its position does not change when we scroll (either horizontally or vertically) through an HTML document. You can override one or more default styles of the box in the declaration of one or more components of the box. Below, we show how to override various default stylings. - The block
.box .headis for styling the head of the box. The head is made up of 2 components: the block.box .titlefor styling the title and the block.box .closefor styling the button to close the box. For now, the styling of.box .headis the default styling for.box .titleand.box .close, hence we leave the declarations of the latter 2 sub-components empty. In the head of the box, we override the defaultbackgroundcolour by declaring the background colour of the head to be lime. The foregroundcolorof the text is black. Thedisplayof the head is declared asflex, meaning we want to use a flexible layout for the head. The propertyjustify-contentis used to control the spacing of the sub-components in the head. For now, we usespace-betweento insert as much whitespace as possible between the sub-components. The head of the box has 2 sub-components. Thereforejustify-content: space-between;means that the left and right sub-components are positioned to the left-most and right-most, respectively, of the head. - The styling of the body of the box is declared in the block
.box .body. We want the foregroundcolorof text in the body to be lime.