How can the code be modified to incorporate CSS classes for styling the elements instead of inline styling?
To incorporate CSS classes for styling the elements instead of inline styling, we can add a class attribute to each HTML element and define the styles in an external CSS file. This helps in separating the content from the presentation, making the code more maintainable and easier to update in the future.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<?php
$names = array("Alice", "Bob", "Charlie");
echo "<ul>";
foreach ($names as $name) {
echo "<li class='name'>$name</li>";
}
echo "</ul>";
?>
</body>
</html>
```
styles.css:
```css
.name {
color: blue;
font-weight: bold;
}
Related Questions
- Are there any best practices or recommended resources for implementing a countdown feature in PHP?
- What are the advantages of using a pre-built BBcode parser like the one mentioned in the thread compared to building one from scratch?
- Are there any specific PHP functions or methods that can help with sorting and organizing data from multiple SELECT queries in PHP and MySQL?