CSS: Fonts and Alignment

Introduction

 
In this chapter, we will learn different properties of fonts like size, weight, text-alignment, etc. Also, we will download new fonts and change fonts. 
 

Font

 
Note one thing, not every OS has every font. Google Font is free and easy to apply in the CSS file. Not only these fonts, but the box model is also an interesting part of the Webpage. It is a great combination of content and margins. Let's see in detail.  
 
This image will give us a better idea of the new fonts in HTML.
 
Visit this link in your browser: https://fonts.google.com/ and we can find out there are 987 types of fonts available, which is useful for advanced web development as well as we can save it as a new font in our operating system. We can resize them, and go through different languages. There is also another attribute font property where we can see different choices like thickness, slant, and width. 
 
Django Bootcamp
 
Note
Before selecting a new font for the web development make sure that it's going to be reusable and the source code is available.
 
The most popular font properties are:
  • font-family, 
  • font-size,
  • font-style,
  • font-weight,
  • font-variant,
  • color,
  • text-decoration,
  • text-shadow,
  • text-transform,
  • letter-spacing,
  • word-spacing,
  • white-spacing. 

Box

 
The box model allows us to precisely dictate how we want HTML elements to look.
 
These are the images on which we will elaborate on the box concept of the web page. 
 
Django Bootcamp
 
When we are talking about the web page design or a layout this will be reflected below. 
 
The properties are work in order: top, right, bottom, and left. 
 
Django Bootcamp
 
TIP
  • When you set the width and height properties of an element in CSS it is ultimately content area. When setting background-color, it will cover the content area and padding both. Total element height= height + top padding + bottom padding + top border + bottom border +top margin + bottom margin
  • Width and height are usually expressed with pixels and percentages.
In this chapter, we will learn the font and box concept with complete CSS. It is an advanced concept of web development.
 
Let's see with an example where I had generated a spectrum image. I will also share some links where you will find out these images and grab the color palate code easily.
 
Check this link for the color palates and spectrum images.
 
Also, visit this link for advanced fonts,
 
Django Bootcamp
 
Example - pro.html
  1. <!DOCTYPE html>  
  2. <html lang="en" dir="ltr">  
  3.   
  4.      <head>  
  5.           <meta charset="utf-8">  
  6.           <title>Spectrum Project</title>  
  7.           <link href="https://fonts.googleapis.com/css2?family=IM+Fell+French+Canon+SC&display=swap" rel="stylesheet">  
  8.           <link rel="stylesheet" href="pro.css">  
  9.      </head>  
  10.   
  11.      <body>  
  12.           <h1>My Spectrum Project</h1>  
  13.           <table class="art">  
  14.                <tr>  
  15.                     <td id='one'></td>  
  16.                     <td id='two'></td>  
  17.                     <td id='three'></td>  
  18.                     <td id='four'></td>  
  19.                     <td id='five'></td>  
  20.                </tr>  
  21.           </table>  
  22.      </body>  
  23.   
  24. </html>   
pro.css
  1. h1 {  
  2.   text-aligncenter;  
  3.   font-family'IM Fell French Canon SC', serif;  
  4. }  
  5.   
  6. .art {  
  7.   marginauto;  
  8. }  
  9.   
  10. td {  
  11.   background-colorblack;  
  12.   height300px;  
  13.   width150px;  
  14.   border6px solid white;  
  15. }  
  16.   
  17. #one {  
  18.   background-color#183446;  
  19. }  
  20.   
  21. #two {  
  22.   background-color#2D4656;  
  23. }  
  24.   
  25. #three {  
  26.   background-color#A81E1E;  
  27. }  
  28.   
  29. #four {  
  30.   background-color#020F14;  
  31. }  
  32.   
  33. #five {  
  34.   background-color#0F1620;  
  35. }    
Output
 
Django Bootcamp
 
Kindly check the attached file for a better idea.
 
As we know, CSS is a vast subject for web development with a variety of attributes for all web content. The very rare and attractive features are discussed below.
 

Styling the table

 
The empty-cell property,
 
There are two possible values for it: Show and Hide
 
Example 
  1. <!DOCTYPE html>  
  2. <html lang="en" dir="ltr">  
  3.   
  4.      <head>  
  5.           <meta charset="utf-8">  
  6.           <title>rare contents</title>  
  7.           <link rel="stylesheet" href="rare.css">  
  8.      </head>  
  9.   
  10.      <body>  
  11.           <table border="1">  
  12.                <tr>  
  13.                     <td>HTML</td>  
  14.                     <td>CSS</td>  
  15.                </tr>  
  16.                <tr>  
  17.                     <td>Python</td>  
  18.                     <td></td>  
  19.                </tr>  
  20.           </table>  
  21.      </body>  
  22.   
  23. </html>   
  1. table{  
  2.   border-collapse:separate;  
  3.   empty-cellshide;  
  4. }  
Output
 
Django Bootcamp
 

Styling the list

 
We can style the the list with circle,square,decimal, disc, lower-alpha(a,b,c). Apart from these list-style-image properties, it looks good for the professional website.
 
Example   
  1. <!DOCTYPE html>    
  2. <html lang="en" dir="ltr">    
  3.   <head>    
  4.     <meta charset="utf-8">    
  5.     <title>rare contents</title>    
  6.     <link rel="stylesheet" href="rare.css">    
  7.   </head>    
  8.   <body>    
  9.     <p>Following list is list-style-position: <h2>inside</h2></p>    
  10.     <ul>    
  11.       <li>Red</li>    
  12.       <li>Blue</li>    
  13.       <li>Green</li>    
  14.     </ul>    
  15.   </body>    
  16. </html>    
  1. ul{  
  2.   list-style-imageurl("python-logo.png");  
  3.   list-style-positioninside;  
  4. }  
Output
 
Django Bootcamp
 

Positioning Elements

  1. Static Positioning
    Static value used in a position to make the element run in the natural order of the page.
  2. Fixed Positioning
    Fixed position is related to the browser window, will not move even if the window scrolls. It has more top, right, left, and bottom is properties.
  3. Relative Position
    Relative value puts the element relative to the normal flow.
  4. Absolute Position
    It overlaps other elements.

Float

 
Floated element means the element can be in the left or right direction, not up or down. The clear float property accepts the values none, left, right, and both. The clear property is used to take the next element off the floating group.
 

z-index property

 
Example
  1. <!DOCTYPE html>  
  2. <html lang="en" dir="ltr">  
  3.     <head>  
  4.         <meta charset="utf-8">  
  5.             <title>rare contents</title>  
  6.             <link rel="stylesheet" href="rare.css">  
  7.             </head>  
  8.             <body>  
  9.                 <div class="blue">Blue    
  10.     
  11.                </div>  
  12.                 <div class="red">Red    
  13.     
  14.                </div>  
  15.             </body>  
  16.         </html>    
  1. .blue {  
  2.   background-color#8EC4D0;  
  3.   margin-bottom15px;  
  4.   width120px;  
  5.   height120px;  
  6.   color#FFF;  
  7. }  
  8.   
  9. .red {  
  10.   background-color#FF4D4D;  
  11.   positionrelative;  
  12.   margin-top-50px;  
  13.   margin-left50px;  
  14.   width120px;  
  15.   height120px;  
  16.   color#FFF;  
  17. }    
Output
 
Django Bootcamp
 
This property is to specify the stack order of an element.
 

Summary

 
In the next chapter, we will start discussing Django data models.
Author
Dipa Mehta
144 12.6k 499.3k
Next » Django Models