CSS Part 1
CSS Part 1
DOCUMENTS IN 3 WAYS:
• Syntax:
ADVANTAGES AND DISADVANTAGES OF
INTERNAL CSS
• Advantages:
• Allows you to change the style of the same HTMl file in which you are working.
• Since you’ll only add the code within the same HTML file, you don’t need to upload multiple files.
• Disadvantages:
• Affects only to one page to which they are applied. If you want to use same styling for multiple
document you will have to repeat the same styling for all pages.
• Increases the page load time.
CSS SELECTORS
IV.The
I.The type II.The ID III.The class
universal
selector selector selector
selector
I.THE TYPE SELECTOR
Example:
This applies color
Red to text in the <p> tag
II. THE ID SELECTOR
• The value od if attribute is unique within a document therefore the slector is applied to the
content of one element or tag.
• For id selector a hash(#) symbol is used followed by the value od the id to which css needs to be
applied.
Example:
In this example the id of <p> tag is alt
To which a css of color blue,alignment to
left and size100 % will be applied.
III.THE CLASS SELECTOR
• The class selector is similar to id selector.
• It allows you to apply css rules to the tags/elements that carry class attribute whose value
matches with class attribute specified in the selector.
IV.UNIVERSAL SELECTOR
• The universal selctor selects all the elements that are present in an HTML document.
• You can use this selector to apply the same css rule to all the elemets/tags of HTML document.
• Star(*) is used as universal selector.
Example: This will turn all the tags content of the html
page RED in color.
CSS FOT TEXT
• p{
color:red; //will change color of text to red
text-align:center; //will align the text in the center
text-align:right; // will align the text to the right
font-size:50px; //will increase the size of text
font-family:Arial; //will change the font of the text //font-family: cursive;
}
CSS FOR WEBSITE BACKGROUND:
body{
background-color:lime;
}
• How to add image to website background?
body{
background-image:url(“imagename.jpg”);
background-repeat:no-repeat;
background-size:cover;
}
COLOR PROPERTY OF CSS:
value –
"rgb(255,0,0)"
COLORS
• Is like an in line container which is used to mark-up a part of text or part of document.
• It is used to group elements for styling purposes (by using the class or id attributes
• The span tag is a paired tag means it has both open(<) and closing (>) tags, and it is mandatory
to close the tag.
• this tag does not make any visual change by itself.
• span is very similar to the div tag, but div is a block-level tag and span is an inline tag.
• Span conforms to the width of whatever element it contains.
<SPAN> TAG EXAMPLE
• It is a block level tag and is used to put multiple tags in a container so that css could be applied to
them.
• It adds a line break before and after it
• The span tag is also a div tag sometimes there is no specific meaning at all the times but not vice
versa.
• Div tag takes up the entire width of the screen
<DIV> tag Example
2) EXTERNAL CSS
• With external CSS, you’ll link your web pages to an external .css file, which can be created by
any text editor in your device (e.g., Notepad++).
• This CSS type is a more efficient method, especially for styling a large website.
• By editing one .css file, you can change your entire site at once.
Example of External CSS
ADVANTAGES AND DISADVANTAGES OF
EXTERNAL CSS
• Advantages:
• Since the CSS code is in a separate document, your HTML files will have a cleaner structure and are
smaller in size.
• You can use the same .css file for multiple pages.
• Disadvantages:
• Your pages may not be rendered correctly until the external CSS is loaded.
• Uploading or linking to multiple CSS files can increase your site’s download time.
3) INLINE CSS
• Disadvantages:
• Adding CSS rules to every HTML element is time-consuming and makes your HTML structure messy.
• Styling multiple elements can affect your page’s size and download time.
CSS FOR BORDER
body
{
border: 3px solid blue;
}
Types: dashed,solid,double,ridge,inset,outset,groove
BORDER TYPES:
LIST CSS
• list-style-type: circle;
• list-style-type: square
• list-style-type: upper-roman;
• list-style-type: lower-alpha;
• list-style-type: none;
• list-style-image: url('sqpurple.gif');
LINKS CSS
• When setting the style for several link states, there are some order rules:
• a:hover MUST come after a:link and a:visited
• a:active MUST come after a:hover
LINK CSS
MARGIN & PADDING
• In CSS, a margin is the space around an element’s border, while padding is the space between an
element’s border and the element’s content.
PADDING
• The size of the inner margins can be defined using the following properties:
• padding-top: size of the upper inner margin
• padding-right: size of the inner margin on the right
• padding-bottom: size of the lower inner margin
• padding-left: size of the inner margin on the left
• padding: defines the four inner margins in the order top, right, bottom then left
• The size of the outer margins can be defined using the following properties:
• margin-top: size of the top outer margin
• margin-right: size of the outer margin on the right
• margin-bottom: size of the lower outer margin
• margin-left: size of the outer margin on the left
• margin defines the four outer margins in the order top, right, bottom then left