CSS
CSS
VIGNESH M
What is css?
CSS
Cascading Style Sheet is styling language used to define presentation of document written
in markup language like HTML
Inline CSS:
IF we providing css as a style attribute to individual element in HTML it is inline css
Eg: <h1 style=“color:red”>red</h1>
Internal CSS:
If we providing css by using <style> element in Header part of HTML it is Internal css.
Eg:<header>
<style>
p{color:red;
font-size:60px;}
</style></header>
External CSS:
If we provide css by using separate file with “.css ”extension it is external css. But this file should link
HTML document .
HTML:
<header>
<link rel=“stylesheet” href=“here we have to provide css file path”>
</header>
CSS:
p{
color:red;
font-size:60px;
}
NOTE:
IF all three together given for one particular element first preference will give to inline . Second preference
depends on which connect the last .and this process of providing priority is known as cascading
Selectors :
In CSS, selectors are the patterns used to identify and target specific
elements within your HTML document. They act as the foundation for applying styles to
different parts of your web page content.
Simple selectors :
by using name and attribute if we are selecting elements is simple selectors
Types of simple selectors
1.Element selector
2.Id selector
3.Class
4.Universal
5.Attribute selector
1.Element Selector :
by using tag name if we are selecting HTML element is element selector
eg: HTML : <h1> element selector </h1>
2.ID
ID will target specific element with unique identifier. It is a nattribute to HTML Element.IT should be
unique .for name should start with alphabets. Can be followed by letters,numbers,Hypens(-) and
underscores(_)
To trigger id selector in css we have to use # followed by the name.
Eg:
HTML : <h2 id=“ex1”>id</h2>
CSS: #ex1{ color:red;}
3.Class
Class selector used to target and style HTML elements hat have a specific class
attribute.for single element we can give multiple class name for multiple element we can
give common class name . For name should start with alphabets. Can be followed by
letters,numbers,Hypens(-) and underscores(_)
To trigger calss selector in css we have to use . followed by the name.
Eg:
HTML : <h2 class=“ex1”>id</h2>
Universal selector :
If we need to select each and every element in html then we have to go for universal selector .
In css we have to use * for universal selector
Css:
*{
Color:red;
}
Attribute selector :
By using attribute if we are selecting an element in HTML it is attribute selector . For triggering
attribute in css we have to use [ ] . Within [ ] we have to mention the attribute
HTML : <input type= “text”> <input type =“password”>
CSS: [type=“password”]{
Color : red;
}
This will select only password input not text input
Combinator selectors:
Combinator selectors define relationships between different elements,
specifying how they should be related for styling.
The CSS box model is a fundamental concept that describes how elements in
HTML are rendered as rectangular boxes on a web page. Each box consists of several
components, including content, padding, border, and margin.
Content:
The actual content of the box, such as text, images, or other media.
Padding:
The space between the content and the border. Padding adds internal spacing
within the box.
Border:
The border surrounds the padding. It is a line or area that goes around the
padding and content.
Margin:
The space outside the border. Margin defines the gap between the border of the
box and the adjacent elements.
div{
width:500px;
height:500px;
padding:10px;
margin:10px;
border:2px solid black;
}
Box-sizing: border-box is used for width and height properties set the total width and height of the
element, including content, padding, and border.
Box-sizing :content-box border-box is used for width and height properties set the total width and
height of the element, excluding padding, and border
Overflow:
The ‘overflow’ property in CSS is used to control how content that is too large to fit into an
element's box is handled.
values:
visible - It may overflow the box, extending beyond its boundaries.(default)
hidden-Content that exceeds the box is clipped and not visible.
scroll-A scrollbar is always provided, allowing the user to scroll to see the hidden content.
auto-A scrollbar is provided only when the content overflows the box. Otherwise, no
scrollbar is shown.
transition:
transition property in CSS is used to create smooth animations and transitions between
different states of an element.
Syntax:
transition : property duration timing function delay
For different screen css:
Media queries used for writing css for different screens
Syntax:
/* Styles for small screens */
@media (max-width: 600px) {
/* ... */
}
@keyframes animation-name {
0% {
/* Styles at the start of the animation */
}
50% {
/* Styles in the middle of the animation */
}
100% {
/* Styles at the end of the animation */
}
}
Absolute units :
Absolute units in CSS have a fixed and consistent size regardless of the viewing device or
user preferences.
Eg:cm,mm,in,pt,px
Relative units :
Relative units in CSS are units of measurement that are based on the size or characteristics
of other elements in the document, or on the viewport dimensions
Ex:em,rem,%,vh,vw
Use case :
px-for precise measurement .generally used for border and border-radius
rem or em- used for padding margin font-size
%-used for width
vh,vw-when we want sizes to be relative to the viewport dimensions.