A Complete CSS Guide for Beginners.
SidhPrakash&NerdTalkies

A Complete CSS Guide for Beginners.

Introduction to CSS

CSS is a short abbreviation for 'Cascading Style Sheet' . It was launched on 17th December 1996 and was developed by W3C(World Wide Web Consortium).CSS is a Styling language used to style and embed special features in Webpages with the help of markup languages like HTML(Hypertext Markup Language) or XML(Extensible Markup Language). CSS comes with a special properties for all elements of a webpage like Font ,Text, Border, color, margin, padding, transitions etc.

The First Version of CSS was CSS 1 launched in 1996 and CSS 2 was developed in 1998 . The Latest Version of CSS is CSS 4.15 and was developed in December 2020. Now as CSS come under W3C recommendation so it is also aligned in a hierarchical Structure of DOM discussed in the next paragraph.


.

DOM

DOM stands for 'Document Object Model'. DOM is data representation of objects the contains a logical and hierarchal structure of contents and elements in webpages. DOM is also used for presenting the a way that how a document should be accessed or manipulated. We can Understand DOM by a simple hierarchy model structure..

DOM hierarchy Model Structure through HTML Tags (Fig 1.0)

By seeing Figure1.0 we can clearly understand how the following HTML Tags are in a proper hierarchy Model Structure Firstly we have created one document named as document.html(ext.) then opened up with a <html> tags containing two sub tags <head> and <body>. <head> tag contain <title> tag with a text value. and <body> tag contains <p> and <ul> tag . <p> tag contains text value whereas, <ul> contains 3 <li> tags with 3 text value. Now we will write these in a proper code manner.


<html>
<head>
<title>text</title>
</head>
<body>
<p>
<ul>
<li>text</li>
<li>text<li>
<li>text<li>
</ul>
</p>
</body>
</html>         


DHTML

DHTML Stands for 'Dynamic Hypertext Markup language' . It is not a language like HTML but it is a combination of web development technologies which contains a Markup Language(HTML), Styling Language(CSS) , Scripting Language Like(JavaScript & TypeScript). For creating webpages more creative , dynamic and attractive.


CSS Syntax

For Defining CSS Syntax we should be familiar with some terms.

CSS Syntax Fig 2.0


  1. Selectors: Selector is used to target or calling a HTML element on our webpage which is use to be styled. In Fig 2.0 <h1>tag is the selector.
  2. Property: Property is the style rule or function which is to be applied on the particular element like in fig 2.0 the color of <h1>tag and font-size .
  3. Value: The value set of property is known as Property Value like the color value is blue and font-size value is 12px.
  4. Declaration: The combination of Property and value is known as declaration.[Declaration = Property+Value]


Linking CSS with HTML Document

  1. Internal CSS - In this type of linking the CSS style will remains inside the html file and for styling we can use <style> tag.
  2. Inline CSS - In this type of CSS we style a particular tag of html with the help of Style Attribute.

<a href = "www.google.com" style = "color: hot pink; margins:0;">Click Here</a>        


  1. External CSS - In this type of linking for styling the webpage we have to make a dedicated external .css file . for linking the CSS file with HTML we can use this code

<link rel = "stylesheet" type="text/css" href="name of file.css">        

Properties of CSS

CSS contain some Properties for designing and making html elements more beautiful and attractive. The Types of CSS Properties are as follows:-

  • Font-Properties
  • Text-Properties
  • Border-Properties
  • Background-Properties
  • Outline-Properties
  • Margins and Padding
  • Height and width Property


Font-Properties

Font Properties are a set of features and rule applied for styling font of a webpage.

There are 4 type of Font-Properties

  1. Font-Family: Font Family Property is used to font of html element.<p style="font-family: sans-serif;">Hello world</p>
  2. Font-Style: This Property contains three values (italic,oblique,and normal). For Example -

a{
font-family: italic;
}
a{
font-family:normal;
} a{font-family: oblique;}        




  1. Font-Weight: Font-Weight Property is used to set weight or to customized the level of of boldness of font. Its value ranges between 100 to 900. Where less than 400 is said to be lighter and more than 400 and less than 700 is said to be bolder and above 700 value is the boldest.
  2. Font-Size: Font-Size Property is used to set the size of font. There are two types of Font-Size. 1(Absolute), 2(Relative) . In Absolute Font-Size the unit for measuring the font is px ,pt,,and cm. Where is Relative Font-Size the unit for measuring the font is % and em (1em=16px).
  3. Line-Height: Line Height is used to Sets the amount of space above and below inline elements. We can calculate line-height if we multiply the font-size with a random integers number.(line-height=number*font-size).

body{
font-size:16px;
} 
h1{
font-size:10pt
} 
p{
font-size:1em
} 
a{
font-size:35%
}
i{                     
font-size:1em
line-height:1.5
}                /* here in the <i>tag the relative font-size is 1em=16px
                    and number=1.5 so , line-height=16px*1.5=24px */        

Text-Properties

Text-Properties Determines and styles texts elements of webpage

  • color: Determines the color of the text.
  • text-align: Sets horizontal alignment of text. e.g., left, right, center, justify.
  • text-decoration: Adds decoration to text like underline, overline, line-through.
  • text-transform: Controls capitalization. Values include uppercase, lowercase, and capitalize.
  • text-shadow: Adds shadow to text.
  • text-indent: Indents the first line of a block of text.

Example:-

p{
color: blue; 
text-align: center; 
text-decoration: underline; 
text-transform: uppercase; 
text-shadow: 2px 2px 4px red; 
text-indent: 20px;}        



Border-Properties

Border-Properties styles the border element of a webpage.

  • border-style: Specifies the style of the border. e.g., solid, dashed, dotted.
  • border-color: Determines the color of the border.
  • border-width: Sets the thickness of the border.
  • border-radius: Rounds the corners of an element.

Example:

div { 
border-style: solid; 
border-color: green; 
border-width: 2px; 
border-radius: 10px; 
}        

Background-Properties

Background Property sets the background of a page.

  • background-color: Sets the background color of an element.
  • background-image: Places an image as the background of an element.
  • background-repeat: Determines if/how a background image will repeat.
  • background-position: Sets the starting position of a background image.
  • background-size: Specifies the size of the background images.
  • background-attachment: Determines whether a background image scrolls with the content or is fixed.

Example:-

div { background-color: yellow; 
background-image: url('path_to_image.jpg'); 
background-repeat: no-repeat; 
background-position: center center; 
background-size: cover; 
background-attachment: fixed; 
}        

Outline-Properties

Outline Property designs the outline or the outer border of webpage.

  • outline-style: Specifies the style of the outline. e.g., solid, dashed.
  • outline-color: Determines the color of the outline.
  • outline-width: Sets the thickness of the outline.
  • outline-offset: Adds space between an outline and the edge/border of an element.

Example:-

a{ 
outline-style: dotted; 
outline-color: orange; 
outline-width: 3px; 
outline-offset: 5px; 
}        

Margins and Padding

  • Margin: Specifies the space around an element, outside of any defined borders. It can have top, right, bottom, and left values. Having the following individual margin properties: margin-top: It is used to set the top margin of an element.margin-right: It is used to set the right margin of an element.margin-bottom :It is used to set the bottom margin of an element.margin-left: It is used to set left margin of an element.

Example:

div { 
margin: 10px 20px 10px 20px;
}        

  • Padding: Specifies the space between the content of the element and its border. Like margin, it can have values for all four sides. It also have separate margin properties. It also have 4 values top, right, bottom ,left.

Example:-

p {margin:150px;}         

Height and Width Property

Height and width property is used to set the height and width of elements. It contains six properties.

  1. height: Sets the height of an element.
  2. width: Sets the width of an element.
  3. max-height: Sets the maximum height of an element.
  4. max-width: Sets the maximum width of an element.
  5. min-height: Sets the minimum height of an element.
  6. min-width: Sets the minimum width of an element.

Example:

div {                         /* height = 100px or 100/16 = 6.25em*/
height: 100px;                /* width = 200px or 200/16 = 12.50em*/
width: 200px;                 /*max-height = 150px or 9.375em*/
max-height: 150px;            /*max width = 250px or 15.625em*/
max-width: 250px;             /*min-height = 50px or 3.125 */
min-height: 50px;             /*min-width = 100px  */
min-width: 100px;  
}        


shaurya prakash

Student at Loyola High School, Patna

11 个月

great it helped me ??

要查看或添加评论,请登录

Sidh Prakash的更多文章

  • How to Start Coding in 2024

    How to Start Coding in 2024

    In the ever-evolving landscape of technology, the ability to code is a gateway to innovation and opportunity. As we…

  • RoadMap for becoming a Software Developer

    RoadMap for becoming a Software Developer

    Becoming a software developer is a rewarding journey that requires a combination of education, practical experience…

    1 条评论
  • Turing's Test

    Turing's Test

    The Turing test was coined by a Mathematician ‘Alan Turing’ in 1950 afterwards he was also called the “Father of…

社区洞察

其他会员也浏览了