CSS(Attributes and VALUES)
CSS(Attributes and VALUES)
Sure! Here’s a list of common CSS properties (attributes) and their typical
values:
1. Layout Properties:
- `display`: Defines how an element is displayed.
Values: `block`, `inline`, `inline-block`, `flex`, `grid`, `none`, `inline-flex`,
`inline-grid`
3. Typography Properties:
- `font-family`: Specifies the font of the text.
Values: Font name (e.g., `Arial`, `Times New Roman`, `'Helvetica Neue'`)
4. Background Properties:
- `background-color`: Sets the background color of an element.
Values: Color names (`red`, `blue`, etc.), hex (`#000`), rgb (`rgb(255, 0, 0)`)
5. Flexbox Properties:
- `display: flex`: Activates flexbox layout on the container.
- `grid-row`: Defines the start and end position of a grid item in rows.
Values: `start / end`, e.g., `2 / 4`
7. Border Properties:
- `border-radius`: Defines the radius of the element's corners.
Values: Length units (`px`, `em`, `%`), e.g., `10px`
TABLE ATTRIBUTES
In CSS, the `<table>` element can be styled using various properties to
control the appearance and layout of tables. These properties are
applied not only to the table itself but also to its various components,
such as the table rows (`<tr>`), cells (`<td>`, `<th>`), and headers
(`<thead>`, `<tbody>`, `<tfoot>`).
- `border`: You can also add borders to rows, although this is less
common than styling cells.
```css
tr {
border-bottom: 1px solid #ccc;
}
```
- Fixed Header on Scroll: You can make the table header fixed when
scrolling, by combining `position: sticky` and `top` properties.
```css
th {
position: sticky;
top: 0;
background-color: #fff;
z-index: 1;
}
```
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Styled Table</title>
<style>
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 12px;
border: 1px solid #ddd;
text-align: left;
}
th {
background-color: #4CAF50;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
caption {
font-size: 1.5em;
margin: 10px 0;
}
</style>
</head>
<body>
<table>
<caption>Employee Table</caption>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>Manager</td>
<td>$100,000</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>Developer</td>
<td>$80,000</td>
</tr>
<tr>
<td>Sam Johnson</td>
<td>Designer</td>
<td>$70,000</td>
</tr>
</tbody>
</table>
</body>
</html>
```
This creates a table with a fixed header, alternating row colors, hover
effects, and padding in the cells.
ROW TAGS
It seems you are asking specifically about row tags in the context of
CSS. The term "row tags" likely refers to the <tr> (table row) element in
HTML. While you cannot directly style the row itself with CSS just by
referring to a "row tag," you can target the <tr> element (table row) with
CSS selectors to style it as needed.
Here's a comprehensive guide on how to style the <tr> tag (table row)
in CSS:
You can directly style <tr> tags to control the background color,
borders, padding, and other visual properties.
css
Copy code
tr {
background-color: #f9f9f9; /* Light gray
background */
border: 1px solid #ddd; /* Border around the
rows */
padding: 10px; /* Padding inside the
row */
}
This will alternate the row background color every other row.
You can add a hover effect that changes the background color of a row
when the user hovers over it.
Example:
css
Copy code
tr:hover {
background-color: #e0e0e0; /* Change to a slightly
darker gray when hovered */
}
Example:
css
Copy code
/* Style the first row */
tr:first-child {
background-color: #4CAF50; /* Green background for
the first row */
color: white; /* White text */
}
You can add borders to table rows, but keep in mind that table cells
(<td> and <th>) usually define the appearance of borders.
Example:
css
Copy code
/* Apply a border to each row */
tr {
border-bottom: 1px solid #ddd;
}
You can target specific rows by adding classes to <tr> tags and styling
those classes in CSS.
Example:
html
Copy code
<table>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr class="highlight">
<td>John Doe</td>
<td>Manager</td>
<td>$100,000</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>Developer</td>
<td>$80,000</td>
</tr>
</tbody>
</table>
css
Copy code
/* Target the row with the class 'highlight' */
tr.highlight {
background-color: #ffeb3b; /* Yellow background
for highlighted row */
font-weight: bold;
}
th, td {
padding: 12px;
text-align: left;
border: 1px solid #ddd;
}
tr:nth-child(even) {
background-color: #ffffff;
}
/* Hover effect */
tr:hover {
background-color: #ddd;
}
<table>
<caption>Employee List</caption>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>Manager</td>
<td>$100,000</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>Developer</td>
<td>$80,000</td>
</tr>
<tr>
<td>Sam Johnson</td>
<td>Designer</td>
<td>$70,000</td>
</tr>
</tbody>
</table>
</body>
</html>
In conclusion, although "row tags" isn't a direct CSS term, you can target
the <tr> (table row) element to apply various styles that enhance the
look and usability of tables. By using CSS selectors like
:nth-child(), :hover, and :first-child, you can customize
table rows in dynamic and interactive ways.
You can directly style <tr> tags to control the background color,
borders, padding, and other visual properties.
css
Copy code
tr {
background-color: #f9f9f9; /* Light gray
background */
border: 1px solid #ddd; /* Border around the
rows */
padding: 10px; /* Padding inside the
row */
}
This will alternate the row background color every other row.
You can add a hover effect that changes the background color of a row
when the user hovers over it.
Example:
css
Copy code
tr:hover {
background-color: #e0e0e0; /* Change to a slightly
darker gray when hovered */
}
You can style the first and last rows using the :first-child and
:last-child pseudo-classes.
Example:
css
Copy code
/* Style the first row */
tr:first-child {
background-color: #4CAF50; /* Green background for
the first row */
color: white; /* White text */
}
You can add borders to table rows, but keep in mind that table cells
(<td> and <th>) usually define the appearance of borders.
Example:
css
Copy code
/* Apply a border to each row */
tr {
border-bottom: 1px solid #ddd;
}
/* Apply a thick border to the first row */
tr:first-child {
border-top: 3px solid #000;
}
You can target specific rows by adding classes to <tr> tags and styling
those classes in CSS.
Example:
html
Copy code
<table>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr class="highlight">
<td>John Doe</td>
<td>Manager</td>
<td>$100,000</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>Developer</td>
<td>$80,000</td>
</tr>
</tbody>
</table>
css
Copy code
/* Target the row with the class 'highlight' */
tr.highlight {
background-color: #ffeb3b; /* Yellow background
for highlighted row */
font-weight: bold;
}
th, td {
padding: 12px;
text-align: left;
border: 1px solid #ddd;
}
/* Zebra striping (alternating row colors) */
tr:nth-child(odd) {
background-color: #f9f9f9;
}
tr:nth-child(even) {
background-color: #ffffff;
}
/* Hover effect */
tr:hover {
background-color: #ddd;
}
<table>
<caption>Employee List</caption>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>Manager</td>
<td>$100,000</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>Developer</td>
<td>$80,000</td>
</tr>
<tr>
<td>Sam Johnson</td>
<td>Designer</td>
<td>$70,000</td>
</tr>
</tbody>
</table>
</body>
</html>
In conclusion, although "row tags" isn't a direct CSS term, you can target
the <tr> (table row) element to apply various styles that enhance the
look and usability of tables. By using CSS selectors like
:nth-child(), :hover, and :first-child, you can customize
table rows in dynamic and interactive way
COLUMN TAGS
In CSS, the concept of "column tags" isn't a specific term, but when working with
tables in HTML, we commonly style columns using CSS. There are no dedicated
<col> tags in CSS (other than the <col> element itself), but you can apply styles to
entire columns using CSS in a variety of ways.
The <col> tag in HTML is used to define column properties for tables. It is typically
used within a <colgroup> to apply styles such as background colors or width to
entire columns. While this is one way to style columns, it's not a tag directly styled by
CSS itself but rather used in conjunction with CSS for column-specific styling.
Here’s a breakdown of how you can style columns in tables using CSS:
html
Copy code
<table>
<colgroup>
</colgroup>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>Manager</td>
<td>$100,000</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>Developer</td>
<td>$80,000</td>
</tr>
</tbody>
</table>
Explanation:
If you prefer not to use the <col> tag, you can target individual columns using the
nth-child() pseudo-class. This method applies to table cells (<td>) in a specific
column.
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<style>
table {
width: 100%;
border-collapse: collapse;
th, td {
padding: 12px;
text-align: left;
td:nth-child(1), th:nth-child(1) {
background-color: #f9f9f9;
font-weight: bold;
td:nth-child(2), th:nth-child(2) {
background-color: #f2f2f2;
td:nth-child(3), th:nth-child(3) {
background-color: #e9e9e9;
tr:nth-child(even) {
background-color: #f2f2f2;
tr:hover {
background-color: #ddd;
</style>
</head>
<body>
<table>
<caption>Employee Table</caption>
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>Manager</td>
<td>$100,000</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>Developer</td>
<td>$80,000</td>
</tr>
<tr>
<td>Sam Johnson</td>
<td>Designer</td>
<td>$70,000</td>
</tr>
</tbody>
</table>
</body>
</html>
Explanation:
While tables in HTML use rows (<tr>) and columns (<td>) for layout, CSS Grid and
Flexbox can also be used for more complex layouts, especially for table-like
structures. You can apply Grid or Flexbox to control the layout of data in a table-like
structure.
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.grid-table {
display: grid;
.grid-table div {
padding: 10px;
text-align: left;
.grid-table .header {
background-color: #4CAF50;
color: white;
font-weight: bold;
.grid-table .row:nth-child(even) {
background-color: #f9f9f9;
}
.grid-table .row:hover {
background-color: #ddd;
</style>
</head>
<body>
<div class="grid-table">
<div class="header">Name</div>
<div class="header">Position</div>
<div class="header">Salary</div>
<div class="row">Manager</div>
<div class="row">$100,000</div>
<div class="row">Developer</div>
<div class="row">$80,000</div>
<div class="row">Designer</div>
<div class="row">$70,000</div>
</div>
</body>
</html>
Explanation:
Conclusion
Although there isn’t a specific “column tag” in CSS, there are multiple ways to style
columns in HTML tables:
1. Using the <col> element: This method allows you to apply styles directly to
columns.
2. Using the nth-child() pseudo-class: This method applies styles to specific
columns based on their position.
3. Using CSS Grid or Flexbox: These advanced techniques allow you to create
custom layouts similar to table structures but with more flexibility and control.
Each method has its own use case depending on the complexity of your design and
your layout requirements. The most common approaches for traditional table layouts
remain the use of the <col> tag or targeting columns using nth-child().