Skip to content

CSS

Course: Web Dev + Devops Orientation - chapter 8

CSS stands for Cascading Style Sheets. It is used to style our applications

You can add CSS to your HTML app by using -

  1. The style attribute (inline styles)
  2. In an external css file

Try updating the body tag in the last style as follows -

<body style="background-color: black;">
... rest of the code
</body>
  1. Add a new file called index.css
  2. Add the following code in it
body {
background-color: black;
}
  • Update index.html
<html>
<title>
Visual Studio Code - Code Editor
</title>
<link rel="stylesheet" href="index.css">
</html>
<body>
... rest of the code
</body>

  • color: Sets the text color.
  • background-color: Sets the background color.
  • font-size: Sets the size of the text.
  • margin: Sets the outer space around an element.
  • padding: Sets the inner space within an element.
  • border: Sets the border around an element.

Flexbox is a CSS layout model designed to help with the arrangement of items within a container.

Update the website to the following -

<html>
<title>
Visual Studio Code - Code Editor
</title>
</html>
<body>
<div style="display: flex;">
<div>Visual Studio Code</div>
<a href="/">Docs</span>
<a href="/">Updates</span>
<a href="/">Blog</span>
<a href="/">API</span>
<a href="/">Extensions</span>
<a href="/">FAQs</span>
<a href="/">Learn</span>
</div>
<div>
<input type="text" placeholder="Search Docs">
<button>Download</button>
</div>
<br/>
<div>
<a href="/">Version 1.82</a> is now available! Read about the new features and fixes from July.
</div>
<br/>
</body>

Notice that the elements are positioned right next to each other even though Visual Studio code is inside a div

Try experimenting with the justify-centent property

<html>
<title>
Visual Studio Code - Code Editor
</title>
</html>
<body>
<div style="display: flex; justify-content: space-between;">
<div>Visual Studio Code</div>
<a href="/">Docs</span>
<a href="/">Updates</span>
<a href="/">Blog</span>
<a href="/">API</span>
<a href="/">Extensions</span>
<a href="/">FAQs</span>
<a href="/">Learn</span>
</div>
<div>
<input type="text" placeholder="Search Docs">
<button>Download</button>
</div>
<br/>
<div>
<a href="/">Version 1.82</a> is now available! Read about the new features and fixes from July.
</div>
<br/>
</body>
$1b

In CSS, classes and IDs are used as selectors to apply styles to HTML elements. They help in targeting specific elements for styling and can be used to enhance the modularity and reusability of CSS code.