Practical Examp-WPS Office
Practical Examp-WPS Office
This example includes attribute selectors combined with the `:hover` pseudo-class for better user
experience.
---
```css
input[type] {
padding: 10px;
width: 100%;
border-radius: 5px;
margin: 5px 0;
transition: 0.3s;
input[type="text"] {
background-color: #f9f9f9;
input[type="password"] {
background-color: #f0f0f0;
}
input[required] {
border-color: red;
input:focus {
border-color: dodgerblue;
background-color: #e6f7ff;
input[type]:hover {
border-color: #007bff;
button:hover {
background-color: darkblue;
color: white;
cursor: pointer;
}
/* Style for links that start with 'https' */
a[href^="https"] {
color: green;
text-decoration: none;
font-weight: bold;
a[href^="https"]:hover {
color: darkgreen;
text-decoration: underline;
img[src$=".png"] {
border-radius: 10px;
width: 100px;
img[src$=".png"]:hover {
border-color: red;
```
FHTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<style>
input[type] {
padding: 10px;
width: 100%;
border-radius: 5px;
margin: 5px 0;
transition: 0.3s;
input[type="text"] {
background-color: #f9f9f9;
input[type="password"] {
background-color: #f0f0f0;
input[required] {
border-color: red;
input:focus {
border-color: dodgerblue;
background-color: #e6f7ff;
input[type]:hover {
border-color: #007bff;
button:hover {
background-color: darkblue;
color: white;
cursor: pointer;
}
/* Style for links that start with 'https' */
a[href^="https"] {
color: green;
text-decoration: none;
font-weight: bold;
a[href^="https"]:hover {
color: darkgreen;
text-decoration: underline;
img[src$=".png"] {
border-radius: 10px;
width: 100px;
img[src$=".png"]:hover {
border-color: red;
</style>
</head>
<body>
<div style="width: 300px; margin: auto; padding: 20px; border: 1px solid #ddd; border-radius: 10px;">
<h2>Login Form</h2>
<form>
<label for="username">Username:</label>
<label for="password">Password:</label>
<button type="submit">Login</button>
</form>
</div>
</body>
</html>
```
---
1. **`input[type]`** → Applies styles to all input fields that have a `type` attribute.
2. **`input[type="text"]` and `input[type="password"]`** → Changes background colors.
6. **`button:hover`** → Changes background to dark blue and text to white when hovered.
---
---
HTML is the structure of your webpage. In this step, we will create a **Login Form**.
1. Open **Notepad** (or any code editor like VS Code, Sublime Text).
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Form</title>
</head>
<body>
<div>
<h2>Login</h2>
<form>
<label for="username">Username:</label>
<label for="password">Password:</label>
<button type="submit">Login</button>
</form>
</div>
</body>
</html>
```
---
```html
<style>
*{
box-sizing: border-box;
body {
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
#container {
background: white;
padding: 20px;
border-radius: 10px;
width: 300px;
text-align: center;
.form-group {
margin-bottom: 15px;
text-align: left;
input[type="text"], input[type="password"] {
width: 100%;
padding: 8px;
border-radius: 5px;
}
input:focus {
border-color: dodgerblue;
outline: none;
button, a {
display: block;
width: 100%;
text-align: center;
#container > h2 {
color: darkblue;
h2 + p {
font-size: 14px;
color: gray;
}
/* General Sibling Selector: Styles all <p> after h2 */
h2 ~ p {
font-style: italic;
</style>
```
---
```html
<body>
<div id="container">
<h2>Login</h2>
<form>
<div class="form-group">
<label for="username">Username:</label>
</div>
<div class="form-group">
<label for="password">Password:</label>
<button type="submit">Login</button>
</form>
</div>
</body>
```
---
3. ID Selector (`#container`)
- Example: `display: block; width: 100%;` makes buttons and links full-width.