In CSS, relative length units are used to specify the length relative to another length attribute.
Serial number | Unit and description |
---|---|
1 | em Relative to the font size of the element, that is, 4em means 4 times the current font size. |
2 |
ex x-height relative to the current font |
3 |
ch Width relative to 0 |
4 |
rem Font size relative to the root element |
5 |
vw 1% relative to the viewport width* |
6 |
vh 1% relative to the viewport height* |
7 |
vmin 1% of the smaller size relative to the viewport* |
vmax1% of the larger size relative to the viewport* | |
% | Relative to parent element |
Demonstration
<!DOCTYPE html> <html> <head> <style> .demo { text-decoration: overline underline; text-decoration-color: blue; font-size: 1.4em; } </style> </head> <body> <h1>Details</h1> <p class="demo">Examination Center near ABC College.</p> <p class="demo2">Exam begins at 9AM.</p> </body> </html>
Output
Example
Real-time demonstration
<!DOCTYPE html> <html> <head> <style> .demo { text-decoration: overline underline; text-decoration-color: blue; font-size: 4ch; } </style> </head> <body> <h1>Details</h1> <p class="demo">Examination Center near ABC College.</p> <p class="demo2">Exam begins at 9AM.</p> </body> </html>
Output
The above is the detailed content of Relative length units in CSS. For more information, please follow other related articles on the PHP Chinese website!