CSS 2nd Part
CSS 2nd Part
1.Color Keywords:
CSS provides a set of predefined color keywords that represent
common colors, such as "red", "blue", "green", etc.
2.Hexadecimal Notation:
Colors can be specified using a six-digit hexadecimal code preceded
by a hash (#). Each pair of digits represents the intensity of red, green,
and blue (RGB) components, respectively.
3.RGB Values:
Colors can also be defined using RGB values, where each component
(red, green, and blue) is represented by an integer between 0 and 255.
For example: color: rgb(255, 0, 0); represents red, color: rgb(0, 255,
0); represents green, and color: rgb(0, 0, 255); represents blue.
Example:
HTML file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph with some text.</p>
<div class="color-box"></div>
</body>
</html>
CSS file:
/* CSS Color Examples */
h1 {
color: red;
}
p{
color: #00FF00;
}
.color-box {
width: 100px;
height: 100px;
background-color: rgb(0, 0, 255);
border: 1px solid red;
}
2. font-family: Specifies the font family for the text. (Value: font family
names or generic font families)
3. font-size: Sets the size of the text. (Value: length values, percentages,
or keywords like "small", "medium", "large")
Example:
HTML file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a Heading</h1>
CSS file:
/* Text Properties */
h1 {
color: blue;
font-size: 24px;
text-align: center;
font-weight: bold;
text-decoration: underline;
}
p{
color: red;
font-family: Arial, sans-serif;
font-size: 18px;
text-align: justify;
}
.highlight {
color: green;
text-transform: uppercase;
}
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
</body>
</html>
CSS file:
/* List Properties */
ul {
list-style-type: square;
}
ol {
list-style-type: upper-roman;
list-style-position: inside;
list-style-image: url(image name);
.custom-list li::before {
counter-increment: custom-counter;
content: counter(custom-counter) ".";
margin-right: 5px;
color: #FF0000;
font-weight: bold;
font-size:20px;
}
1. .custom-list: Removes the default bullet points from the unordered list
by setting list-style to none. It also resets the value of a custom
counter using the counter-reset property. We'll use this counter to
generate the custom list numbers.
2. .custom-list li::before: This selector targets the pseudo-element
::before of each list item (<li>) within the custom-list class.
3. counter-increment: Increments the value of the custom counter by
1 for each list item.
4. content: Specifies the content that should be displayed before each
list item. In this case, we use the counter() function to retrieve the
current value of the custom counter and append a period (.) after it.
CSS Table Properties:
1. border-collapse: Specifies whether the table cells share borders or
have separate borders. (Values: "collapse", "separate")
3. width: Sets the width of the table. (Value: length values, percentages)
Example:
HTML file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
</body>
</html>
td, th {
border: 1px solid black;
padding: 8px;
text-align: center;
vertical-align: middle;
}
Example:
HTML file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="box"></div>
</body>
</html>
CSS file:
/* Background Properties */
.box {
width: 200px;
height: 200px;
background-color: #f2f2f2;
background-image: url("background-image.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
4. cursor: Sets the mouse cursor appearance when hovering over the
link. (Values: "auto", "pointer", "default", and more)
HTML file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<a href="#">This is a link</a>
</body>
</html>
CSS file:
/* Link Formatting Properties */
a{
color: blue;
text-decoration: underline;
font-weight: bold;
cursor: pointer;
}
3. border: Sets the border properties around the image. (Value: border
properties such as width, style, and color)
5. object-fit: Specifies how the image should be resized to fit within its
container. (Values: "fill", "contain", "cover", "none", "scale-down")
6. object-position: Sets the starting position of the image within its
container. (Values: length values, percentages, keywords like "top",
"bottom", "center", "left", "right")
Example:
HTML file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<img src="example.jpg" alt="Example Image">
</body>
</html>
CSS file:
/* Image Formatting Properties */
img {
width: 300px;
height: auto;
border: 1px solid black;
border-radius: 10px;
object-fit: cover;
object-position: center;
opacity: 0.8;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
}
CSS Form Formatting Properties:
CSS form properties allow you to style and customize the appearance of
HTML form elements. These properties help you control the layout, colors,
borders, and other visual aspects of form inputs, buttons, checkboxes, and
more.
Example:
Html File:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Registration Form</h1>
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"
placeholder="Enter your name">
<label for="email">Email:</label>
<input type="email" id="email" name="email"
placeholder="Enter your email">
<label for="password">Password:</label>
<input type="password" id="password" name="password"
placeholder="Enter your password">
<label for="gender">Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<label for="interests">Interests:</label>
<input type="checkbox" id="music" name="interests" value="music">
<label for="music">Music</label>
CSS File:
h1 {
color: blue;
}
form {
width: 300px;
margin: 0 auto;
border: 2px solid red;
background-color: aquamarine;
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="email"],
input[type="password"] {
width: 90%;
padding: 5px;
margin-bottom: 10px;
}
input[type="radio"],
input[type="checkbox"] {
margin-bottom: 10px;
display: inline;
}
input[type="radio"] + label,
input[type="checkbox"] + label {
margin-left: 5px;
display: inline;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
In this example,
1. h1 - Sets the color of the heading text to blue.
2. form - Styles the form element. It sets the width to 300 pixels and
centers it horizontally using margin: 0 auto;.