Unit 3:cascading Style Sheets 3: Screen, Paper, or in Other Media
Unit 3:cascading Style Sheets 3: Screen, Paper, or in Other Media
Unit 3:cascading Style Sheets 3: Screen, Paper, or in Other Media
What is CSS?
CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed on
screen, paper, or in other media
CSS saves a lot of work. It can control the layout of multiple web
pages all at once
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
p{
font-family: verdana;
font-size: 20px;
}
</style>
</head>
<body>
<h1>My First CSS Example</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS is used to define styles for your web pages, including the
design, layout and variations in display for different devices and
screen sizes.
CSS Syntax
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
text-align: center;
}
</style>
</head>
<body>
<p>Hello World!</p>
<p>These paragraphs are styled with CSS.</p>
</body>
</html>
Example Explained
p is a selector in CSS (it points to the HTML element you want to
style: <p>).
color is a property, and red is the property value
text-align is a property, and center is the property value
Inline CSS
Inline CSS is generally used to style a specific HTML element only.
We can write inline CSS simply by adding the style attribute to each
HTML element.
This CSS type is not really recommended, as each HTML tag
needs to be styled individually. Managing a website may be difficult if
we use only inline CSS.
<!DOCTYPE html>
<html>
<body>
<h1 style="color:red">Simple Box Design
</h1>
<div style="height:200px;width:300px;background-color:yellow">
</div>
</body>
</html>
Internal CSS
Internal CSS is also known as embedded CSS. It is generally used to
style a single page. We can write internal CSS inside a <style> tag
within the HTML pages.
This CSS type is an effective method of styling a single page.
However, using this style for multiple pages is time-consuming as you
need to put CSS style on every page of your website.
In HTML, for an element, the ID name starts with the "#" symbol
followed by a unique name assigned to it. "class" assigned to an
element has its name starts with "." followed by class name. Only one ID
selector can be attached to an element.
<!DOCTYPE html>
<html>
<head>
<style>h1{
background-color:orange
}
.box{
height:200px;
width:300px;
background-color:#ff0}
#circle{
height:200px;
width:200px;
background-color:red;
border-radius:50%}
</style>
</head>
<body>
<h1>Simple example of internal CSS
</h1>
<div class="box">
</div>
<div id="circle">
</div>
</body>
</html>