CSS Sunny
CSS Sunny
1)What is CSS?
selector {
property: value;
}
Simple Selector
p{
The element selector selects HTML elements based on the element name.
text-align: center;
Here, all <p> elements on the page will be center-aligned, with a red text color:
color: red;
ID Selector }
The id selector uses the id attribute of an HTML element to select a specific
element.
To select an element with a specific id, write a hash (#) character, followed by
the id of the element.
#para1 {
text-align: center;
color: red;
}
Note: An id and class names cannot start with a number!
Class Selector
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by
the class name.
.center {
text-align: center;
color: red;
}
Universal Selector
The universal selector (*) selects all HTML elements on the page.
* {
text-align: center;
color: blue;
}
Grouping Selector
The grouping selector selects all the HTML elements with the same style
definitions.
Look at the following CSS code (the h1, h2, and p elements have the same style
definitions):
h1, h2, p {
text-align: center;
color: red;
}
Combinator selectors
A CSS selector can contain more than one simple selector. Between the simple
selectors, we can include a combinator.
The following example selects all <p> elements inside <div> elements:
The following example selects all <p> elements that are children of a <div>
element:
The adjacent sibling selector is used to select an element that is directly after
another specific element.
Sibling elements must have the same parent element, and "adjacent" means
"immediately following".
The following example selects the first <p> element that are placed
immediately after <div> elements:
General Sibling Selector (~)
The general sibling selector selects all elements that are next siblings of a
specified element.
The following example selects all <p> elements that are next siblings of <div>
elements:
Pseudo-classes
Pseudo-Elements
The :hover selector in CSS is used to apply styles to an element when the user
hovers over it with a pointing device (like a mouse). This is commonly used to
change the appearance of links, buttons, and other interactive elements to provide
visual feedback when the user interacts with them.
a:hover {
color: red;
text-decoration:
underline;
}
The :active selector in CSS is used to apply styles to an element when it is in the process of being
activated by the user. This typically occurs when the user clicks on the element
input:focus {
border-color: In this example, when an input field receives focus
blue; (such as when a user clicks into it or navigates to it
using the keyboard), its border color changes to blue,
outline: none; and any default outline is removed.
}
</body>
</html>
10)What is the use of the box-sizing property in CSS?
The box-sizing property in CSS controls how the total width and height of an
element is calculated. It defines whether the padding and border of the element
should be included in the specified width and height values, or if they should be
added on top of the specified values.
.box {
width: 200px;
In this example, if box-sizing is set to border-box, the total width
height: 100px;
of the .box element will be 200px, including padding and border.
padding: 20px; If it's set to content-box, the width would be 244px (200px + 2 *
20px padding + 2 * 2px border).
border: 2px solid black;
box-sizing: border-box;
}
vertical-align: baseline|length|sub|super|top|texttop|middle|bottom|
text-bottom|initial|inherit;
button {
background-color: blue;
transition: background-
color 0.5s ease-in-out 0s;
}
div {
transform:
translate(50px, 100px)
rotate(45deg) scale(1.5);
}
21) What is the use of the animation property in CSS?
The animation property in CSS is used to create complex animations by specifying keyframes
and various animation parameters. This property allows elements to transition smoothly between
different styles over a specified duration, providing a rich user experience.
@keyframes
example {
from { transform:
translateX(0); }
to { transform:
translateX(100px); }
}
div {
animation:
example 2s ease-in-out 1s 22) What is a media query in CSS?
infinite alternate;
Media queries enable responsive web design by allowing CSS to
} adapt to various device environments, ensuring an optimal
viewing experience across a wide range of devices.
@media (max-width:
600px) {
body {
background-color:
lightblue;
}
}
23) What is CSS Grid?
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making
it easier to design web pages without having to use floats and positioning.
24) What is CSS Flexbox?
CSS Flexbox, or the Flexible Box Layout, is a layout model in CSS designed to
provide a more efficient way to lay out, align, and distribute space among items
within a container. Flexbox is especially useful for creating responsive web designs,
as it allows items to adjust and distribute space dynamically.
.container {
display: flex;
flex-direction:
row; /* Default value,
aligns items in a row */
justify-content:
center; /* Centers items
horizontally */
align-items:
center; /* Centers items
vertically */ 25) What is the difference between flex and grid?
.flex-container {
display: flex;
flex-direction: row; /* or
column */
justify-content: center;
align-items: center;
}
Grid:
Two-Dimensional Layout: Handles layout in both rows and columns.
Use Cases: Complex layouts like full-page designs, galleries, dashboards.
.grid-container {
display: grid; Key Differences:
grid-template-rows: auto; Primary Use Case: Flexbox for simpler, linear layouts;
Grid for complex, multi-dimensional layouts.
gap: 10px;
}
.item1 {
grid-column: 1 / 3; /*
Spans two columns */
grid-row: 1 / 2; /*
Occupies the first row */
}
CSS Sprites are a technique used to reduce the number of HTTP requests for images
on a web page by combining multiple images into a single file. This single image,
often called a sprite sheet, is then referenced and displayed using CSS.
2. The parent selector tag is not available, thus you can’t select the
parent selector tag.
Adaptive Design:
It is very time-consuming and takes a lot of effort to build the best possible
adaptive design as examining it will need to go for many options with
respect to the realities of the end user.
There are six standard screen sizes for the appropriate layouts; they are
320px, 480px, 760px, 960px, 1200px, 1600px to design.
Responsive Design
It takes less time to build the design and there is no screen size issue
irrespective of content.
It uses CSS media queries to design the screen layouts with respect to
specific devices and property changes in the screen.
Calc can be used to specify the result of the mathematical operation of two
or more elements. For example to specify the width elements by the addition
of two or more elements, we can write as
.foo {
Width: calc(100px+50px)