CSS3 Modules
CSS3 Modules
<html>
<head>
body {
background-color: linen;
h1 {
color: maroon;
margin-left: 40px;
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<html>
<head>
</head>
<body>
</h1>
</body>
</html>
External CSS - The <link> Element
The <link> element can be used to include an external stylesheet file in your HTML document.
An external style sheet is a separate text file with .css extension. You define all the Style rules within this text file and then you can
include this file in any HTML document using <link> element.
Example
Consider a simple style sheet file with a name mystyle.css having the following rules −
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
Now you can include this file mystyle.css in any HTML document as follows −
<head>
</head>
CSS Comments
Many times, you may need to put additional comments in your style sheet blocks. So, it is very easy to comment any part in style sheet.
You can simple put your comments inside /*.....this is a comment in style sheet.....*/.
You can use /* ....*/ to comment multi-line blocks in similar way you do in C and C++ programming languages.
Example
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
text-align: center;
</style>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
CSS - Backgrounds
This chapter teaches you how to set backgrounds of various HTML elements. You can set the following background properties of an
element −
The background-repeat property is used to control the repetition of an image in the background.
The background-position property is used to control the position of an image in the background.
The background-attachment property is used to control the scrolling of an image in the background.
The background property is used as a shorthand to specify a number of other background properties.
body {
background-image: url("/css/images/css.jpg");
background-color: #cccccc;
background-repeat: repeat;
background-repeat: repeat-y;
background-position:100px;
background-position:100px 200px;
background-repeat: no-repeat;
background-attachment: fixed;
Eg:-
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url('/css/images/css.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-attachment:scroll;
</style>
</head>
<body>
</body>
</html>
CSS – Fonts
This chapter teaches you how to set fonts of a content, available in an HTML element. You can set following font properties of an
element −The font-family property is used to change the face of a font.
The font-weight property is used to increase or decrease how bold or light a font appears.
(Possible values could be normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900.)
(xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger, size in pixels or in %.)
Possible values could be normal, wider, narrower, ultra-condensed, extra-condensed, condensed, semi-condensed, semi-
expanded, expanded, extra-expanded, ultra-expanded.
CSS – Text
This chapter teaches you how to manipulate text using CSS properties. You can set following text properties of an element −
The letter-spacing property is used to add or subtract space between the letters that make up a word.
The word-spacing property is used to add or subtract space between the words of a sentence.
The text-transform property is used to capitalize text or convert text to uppercase or lowercase letters.
The white-space property is used to control the flow and formatting of text.
The text-shadow property is used to set the text shadow around a text.
Eg:-
Images play an important role in any webpage. Though it is not recommended to include a lot of images, but it is still important to use
good images wherever required.
CSS plays a good role to control image display. You can set the following image properties using CSS.
<html>
<head>
</head>
<body>
<img style = "border:1px solid red; height:100px;" src = "/css/images/logo.png" /> <br />
<img style = "border:1px solid red; -moz-opacity:0.4; filter:alpha(opacity=40);" src = "/css/images/logo.png" />
</body>
</html>
CSS – Links
This chapter teaches you how to set different properties of a hyper link using CSS. You can set following properties of a hyper link −
We will revisit the same properties when we will discuss Pseudo-Classes of CSS.
The :hover signifies an element that currently has the user's mouse pointer hovering over it.
Eg:-
</style>
Example:-
<html>
<head>
a:link {color:#000000}
</style>
</head>
<body>
</body>
</html>
CSS – Tables
The border-collapse specifies whether the browser should control the appearance of the adjacent borders that touch each other or
whether each cell should maintain its style.
The border-spacing specifies the width that should appear between table cells.
The caption-side captions are presented in the <caption> element. By default, these are rendered above the table in the document. You
use the caption-side property to control the placement of the table caption.
The empty-cells specifies whether the border should be shown if a cell is empty.
The table-layout allows browsers to speed up layout of a table by using the first width properties it comes across for the rest of a column
rather than having to load the whole table before rendering it.
Example:-
<html>
<head>
table.one {border-collapse:collapse;}
table.two {border-collapse:separate;}
td.a {
border-style:dotted;
border-width:3px;
border-color:#000000;
padding: 10px;
td.b {
border-style:solid;
border-width:3px;
border-color:#333333;
padding:10px;
</style>
</head>
<body>
</table>
<br />
</table>
</body>
</html>
Eg:-2
<html>
<head>
table.one {
border-collapse:separate;
width:400px;
border-spacing:10px;
table.two {
border-collapse:separate;
width:400px;
border-spacing:10px 50px;
</style>
</head>
<body>
</table>
<br />
</table>
</body>
</html>
The caption-side property allows you to specify where the content of a <caption> element should be placed in relationship to the table.
This property can have one of the four values top, bottom, left or right. The following example uses each value.
<html>
<head>
caption.top {caption-side:top}
caption.bottom {caption-side:bottom}
caption.left {caption-side:left}
caption.right {caption-side:right}
</style>
</head>
<body>
</caption>
</table>
<br />
</caption>
</table>
<br />
</caption>
</table>
<br />
</caption>
</table>
</body>
</html>
********************************************
CSS3 modules
CSS3 is collaboration of CSS2 specifications and new specifications, we can called this collaboration is module. Some of the modules are
shown below −
CSS3 Rounded corners are used to add special colored corner to body or text by using the border-radius property.A simple syntax of
rounded corners is as follows −
#rcorners7 {
border-radius: 60px/15px;
background: #FF0000;
padding: 20px;
width: 200px;
height: 150px;
1 border-radius Use this element for setting four boarder radius property
2 border-top-left-radius Use this element for setting the boarder of top left corner
3 border-top-right-radius Use this element for setting the boarder of top right corner
4 border-bottom-right-radius Use this element for setting the boarder of bottom right corner
5 border-bottom-left-radius
Use this element for setting the boarder of bottom left corner
Example:-
<html>
<head>
<style>
#rcorners1 {
border-radius: 25px;
background: #8AC007;
padding: 20px;
width: 200px;
height: 150px;
#rcorners2 {
border-radius: 25px;
padding: 20px;
width: 200px;
height: 150px;
#rcorners3 {
border-radius: 25px;
background: url(/https/www.scribd.com/css/images/logo.png);
background-repeat: repeat;
padding: 20px;
width: 200px;
height: 150px;
</style>
</head>
<body>
</body>
</html>
Example:2
<html>
<head>
<style>
#rcorners1 {
background: #a44170;
padding: 20px;
width: 100px;
height: 100px;
#rcorners2 {
background: #a44170;
padding: 20px;
width: 100px;
height: 100px;
#rcorners3 {
background: #a44170;
padding: 20px;
width: 100px;
height: 100px;
</style>
</head>
<body>
<p id = "rcorners1"></p>
<p id = "rcorners2"></p>
<p id = "rcorners3"></p>
</body>
<body>
CSS Border image property is used to add image boarder to some elements.you don't need to use any HTML code to call boarder image.A
sample syntax of boarder image is as follows –
#borderimg {
padding: 15px;
4 border-image-repeat Used to set the boarder image as rounded, repeated and stretched
Eg:-
<html>
<head>
<style>
#borderimg1 {
padding: 15px;
border-image-source: url(/https/www.scribd.com/css/images/border.png);
border-image-repeat: round;
border-image-slice: 30;
border-image-width: 10px;
#borderimg2 {
padding: 15px;
border-image-source: url(/https/www.scribd.com/css/images/border.png);
border-image-repeat: round;
border-image-slice: 30;
border-image-width: 20px;
#borderimg3 {
padding: 15px;
border-image-source: url(/https/www.scribd.com/css/images/border.png);
border-image-repeat: round;
border-image-slice: 30;
border-image-width: 30px;
</style>
</head>
<body>
</body>
</html>
Multi Background
CSS Multi background property
#multibackground {
padding: 75px;
1 background Used to setting all the background image properties in one section
<html>
<head>
<style>
#multibackground {
padding: 75px;
</style>
</head>
<body>
<div id = "multibackground">
<h1>www.abc.com</h1>
<p>
readers who respond better to online content and prefer to learn new
skills at their own pace from the comforts of their drawing rooms.
The journey commenced with a single tutorial on HTML in 2006 and elated
</p>
</div>
</body>
</html>
Multi background property is accepted to add different sizes for different images.A sample syntax is as shown below −
#multibackground {
background: url(/https/www.scribd.com/css/imalges/logo.png) left top no-repeat, url(/https/www.scribd.com/css/images/boarder.png) right bottom no-repeat, url(/https/www.scribd.com/css/images/css.gif)
left top repeat;
CSS3 Colors
RGBA colors
RGBA stands for Red Green Blue Alpha.It is an extension of CSS2,Alpha specifies the opacity of a color and parameter number is a
numerical between 0.0 to 1.0. A Sample syntax of RGBA as shown below −
HSL colors
HSL stands for hue, saturation, lightness.Here Huge is a degree on the color wheel, saturation and lightness are percentage values
between 0 to 100%
HSLA colors
HSLA stands for hue, saturation, lightness and alpha. Alpha value specifies the opacity as shown RGBA. A Sample syntax of HSLA as
shown below –
Eg:-
<html>
<head>
<style>
#p1 {background-color:rgba(255,0,0,0.3);}
#p2 {background-color:rgba(0,255,0,0.3);}
#p3 {background-color:rgba(0,0,255,0.3);}
</style>
</head>
<body>
<p>RGBA colors:</p>
<p id = "p1">Red</p>
<p id = "p2">Green</p>
<p id = "p3">Blue</p>
</body>
</html>
Eg2:-
<html>
<head>
<style>
#g2 {background-color:hsl(120,100%,75%);}
#g3 {background-color:hsl(120,100%,25%);}
</style>
</head>
<body>
<p>HSL colors:</p>
<p id = "g1">Green</p>
</body>
</html>
CSS3 – Gradients
What is Gradients?
Types of gradients
Linear Gradients(down/up/left/right/diagonally)
Radial Gradients
Linear gradients
Linear gradients are used to arrange two or more colors in linear formats like top to bottom.
Top to bottom
<html>
<head>
<style>
#grad1 {
height: 100px;
background: -webkit-linear-gradient(pink,green);
background: -o-linear-gradient(pink,green);
background: -moz-linear-gradient(pink,green);
background: linear-gradient(pink,green);
</style>
</head>
<body>
<div id = "grad1"></div>
</body>
Left to right
<html>
<head>
<style>
#grad1 {
height: 100px;
</style>
</head>
<body>
<div id = "grad1"></div>
</body>
</html> </html>
Diagonal
<head>
<style>
#grad1 {
height: 100px;
</style>
</head>
<body>
<div id = "grad1"></div>
</body>
</html>
Multi color
<html>
<head>
<style>
#grad2 {
height: 100px;
</style>
</head>
<body>
<div id = "grad2"></div>
</body>
</html>
<head>
<style>
#grad1 {
height: 100px;
width: 550px;
</style>
</head>
<body>
<div id = "grad1"></div>
</body>
</html>
CSS3 – Shadow
CSS3 supported to add shadow to text or elements.Shadow property has divided as follows −
Text shadow
Box Shadow
Text shadow
CSS3 supported to add shadow effects to text. Following is the example to add shadow effects to text −
<html>
<head>
<style>
h1 {
h2 {
h3 {
h4 {
color: white;
h5 {
h6 {
p{
color: white;
</style>
</head>
<body>
<h2>abc.com</h2>
<h4> abc.com</h4>
<h5>abc.com</h5>
<h6>abc.com</h6>
<p>abc.com</p>
</body>
</html>
Box shadow(Div)
Used to add shadow effects to elements, Following is the example to add shadow effects to element.
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
padding: 15px;
background-color: red;
</style>
</head>
<body>
</body>
</html>
CSS3 – Text
text-overflow
word-wrap
word-break
3 text-overflow used to determines how overflowed content that is not displayed is signaled to users
5 word-wrap Used to break the line and wrap onto next line
Eg:-
Text-overflow
The text-overflow property determines how overflowed content that is not displayed is signaled to users. the sample example of text
overflow is shown as follows −
<html>
<head>
<style>
p.text1 {
white-space: nowrap;
width: 500px;
overflow: hidden;
text-overflow: clip;
p.text2 {
white-space: nowrap;
width: 500px;
text-overflow: ellipsis;
</style>
</head>
<body>
<b>Original Text:</b>
<p>
ABC originated from the idea that there exists a class ofreaders who respond better to online content and prefer to learn new
skills at their own pace from the comforts of their drawing rooms.
</p>
<b>Text overflow:clip:</b>
ABC originated from the idea that there exists a class of readers who respond better to online content and prefer
to learn new skills at their own pace from the comforts of their
drawing rooms.
</p>
<b>Text overflow:ellipsis</b>
ABC originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new
skills at their own pace from the comforts of their drawing rooms.
</p>
</body>
</html>
Used to break the line, following code shows the sample code of word breaking.
<html>
<head>
<style>
p.text1 {
width: 140px;
word-break: keep-all;
p.text2 {
width: 140px;
border: 1px solid #000000;
word-break: break-all;
</style>
</head>
<body>
ABC originated from the idea that there exists a class of readers who respond better to online content and prefer
to learn new skills at their own pace from the comforts of their drawing rooms. </p>
ABC originated from the idea that there exists a class of readers who respond better to online content and
prefer to learn new skills at their own pace from the comforts of their drawing rooms.
</p>
</body>
</html>
CSS3 - 2d Transforms
2D transforms are used to re-change the element structure as translate, rotate, scale, and skew.
The following table has contained common values which are used in 2D transforms −
2 translate(x,y) Used to transforms the element along with x-axis and y-axis
Rotate 20 degrees
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: pink;
border: 1px solid black;
}
div#myDiv {
/* IE 9 */
-ms-transform: rotate(20deg);
/* Safari */
-webkit-transform: rotate(20deg);
/* Standard syntax */
transform: rotate(20deg);
}
</style>
</head>
<body>
<div>
Abc&xyz.com
</div>
<div id = "myDiv">
ABC & XYZ.com
</div>
</body>
</html>
Rotate -20 degrees
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: pink;
div#myDiv {
/* IE 9 */
-ms-transform: rotate(-20deg);
/* Safari */
-webkit-transform: rotate(-20deg);
/* Standard syntax */
transform: rotate(-20deg);
</style>
</head>
<body>
<div>
ABC&XYZ.com
</div>
<div id = "myDiv">
ABC&xyz.com
</div>
</body>
</html>
CSS BOX Model
Eg:-
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 25px;
padding: 35px;
width: 200px;
background-color: lightseagreen;
</style>
</head>
<body>
<div>
</div>
</body>
</html>
Style examples
<!-- <html>
<head>
<style>
header.page-header {
display: flex;
height: 120px;
min-width: 120px;
align-items: center;
color: #fff;
header.page-header > h1 {
fantasy;
margin: 2%;
main {
</style>
</head>
<body>
<header class="page-header">
</header>
<main>
<p>I love beagles <em>so</em> much! Like, really, a lot. They’re adorable and their ears are so, so snuggly soft!</p>
</main>
</body>
</html> -->
<!--
<html>
<article>
<header>
<p>
Jane Smith
</p>
</header>
<p>
We live on a planet that's blue and green, with so many things still unseen.
</p>
</article>
</html> -->
<html>
<head>
<style>
.forecast {
margin: 0;
padding: .3rem;
background-color: #eee;
font: 1rem 'Fira Sans', sans-serif;
.day-forecast {
margin: .5rem;
padding: .3rem;
font-size: 1.2rem;
.day-forecast {
url('/media/examples/rain.svg') white;
.day-forecast > p {
margin: .2rem;
font-size: 1rem;
</style>
</head>
<body>
<article class="forecast">
<article class="day-forecast">
<p>Rain.</p>
</article>
<article class="day-forecast">
<p>Periods of rain.</p>
</article>
<article class="day-forecast">
</article>
</article>
</body>
</html>
<html>
<head>
<style>
nav {
.crumbs ol {
list-style-type: none;
padding-left: 0;
.crumb {
display: inline-block;
.crumb a::after {
display: inline-block;
color: #000;
content: '>';
font-size: 80%;
font-weight: bold;
padding: 0 3px;
</style>
</head>
<body>
<nav class="crumbs">
<ol>
</ol>
</nav>
<p>This BMX bike is a solid step into the pro world. It looks as legit as it rides and is built to polish your skills.</p>
</body>
</html>