Chapter 04 Web_Engineering
Chapter 04 Web_Engineering
• Out put
• This is a blue paragraph.
Internal Style Sheet Example
• <style>
• p{
• color: green;
• font-size: 18px;
• }
• </style>
• <!DOCTYPE html>
• <html>
• <head> <style>
• p { color: green; font-size: 18px; } </style>
• </head>
• <body>
• <p>This is a paragraph.</p> <p>
• Another paragraph with the same style.</p>
• </body>
• </html>
Out put will be
Text Color: Green✔
Font Size: 18px✔
Applies to all <p> elements
External Style Sheet Example
• <link rel="stylesheet" href="styles.css">
• p{
• color: orange;
• font-size: 16px;
• }
• Example:
• h1 {
• color: red;
• text-align: center;
• }
Types of Selectors
• 1. Universal Selector (*)
• 2. Element Selector (h1, p)
• 3. Class Selector (.classname)
• 4. ID Selector (#idname)
• 5. Attribute Selector ([type="text"])
Universal Selector Example
• The universal selector (*) in CSS3 is used to apply styles to all elements
on a webpage. It is useful when you want to reset margins, padding, or
apply a default style to every element.
• *{
• margin: 0;
• padding: 0;
• }
Element Selector Example
• The element selector (also called type selector) is used to
select and style HTML elements based on their tag name. It
applies styles to all instances of the specified element.
• p{
• font-size: 20px;
• }
Class Selector Example
• The class selector is used to apply styles to multiple elements that
share the same class. It allows you to define a specific style once and
apply it to different elements without modifying the HTML structure.
• blue-text {
• color: blue;
• }
• #header {
• background-color: grey;
• }
• <h1 id="header">Welcome</h1>
Attribute Selector Example
• The attribute selector allows you to style elements based on the
presence, value, or partial match of an HTML attribute. This is useful
for styling form inputs, links, and other elements dynamically.
• input[type="text"] {
• border: 2px solid blue;
• }
Grouping Selectors
• The grouping selector allows you to apply the same styles to
multiple elements by separating them with a comma (,). This
helps to reduce redundancy in CSS code and make it more
efficient.
• h1, p, div {
• color: green;
• }
Pseudo-Classes
• A pseudo-class is a keyword added to a selector that defines a special state
of an element. It allows you to apply styles based on user interaction,
position, or other conditions without modifying HTML.
• a:hover {
• color: red;
• }
Pseudo-Elements
• A pseudo-element in CSS allows you to style specific parts of an
element without modifying the HTML. They are used to add special
effects to text, elements, or content.
• p::first-letter {
• font-size: 30px;
• color: red;
• }
Descendant Selector
• The descendant selector is used to style elements that are nested
inside another element. It applies styles to all matching elements that
are inside a specified ancestor, regardless of how deep they are nested.
• div p {
• color: blue;
• }
Child Selector
• The child selector (>) is used to select only the direct children
of an element. Unlike the descendant selector ( space), it does
not apply styles to deeper nested elements.
• div > p {
• font-weight: bold;
• }
Adjacent Sibling Selector
• The adjacent sibling selector (+) selects an element that comes
immediately after another element and shares the same
parent.
• h1 + p {
• color: red;
• }
General Sibling Selector
• The general sibling selector (~) selects all elements that come
after a specified element and share the same parent.
• h1 ~ p {
• color: purple;
• }
Media Queries
• Media queries allow developers to apply different styles depending on the screen
size, resolution, or device type. They are essential for responsive web design
(RWD), ensuring that websites look good on all devices, from desktops to mobile
phones.
• @keyframes example {
• from {background-color: red;}
• to {background-color: yellow;}
• }
• Create loading indicators
✔ Improve user experience (UX)
✔ Add hover effects
✔ Replace JavaScript for simple animations