<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Poems</title> <style> p:hover { color: red; font-weight: bold; } body { background-color: MistyRose; font-family: Arial, sans-serif; color: DarkSlateGray; } h2 { font-size: 30px; font-family: Georgia, serif; color: DarkSlateBlue; margin-bottom: 5px; } p { font-size: 20px; line-height: 28px; margin-top: 0px; margin-bottom: 20px; } .hover { color: white; background-color: DarkSlateGray; cursor: pointer; } </style> </head> <body> <h2>Poem 1</h2> <p>Roses are red,<br> Violets are blue,<br> Sugar is sweet,<br> And so are you.</p> <h2>Poem 2</h2> <p>There is a charm about<br> the forbidden that makes<br> it unspeakably desirable.</p> <script> var hoverEls = document.querySelectorAll('.hover'); hoverEls.forEach(function(hoverEl) { hoverEl.addEventListener('mouseover', function() { hoverEl.classList.add('hover'); }); hoverEl.addEventListener('mouseout', function() { hoverEl.classList.remove('hover'); }); }); </script> </body> </html>优化这段代码,为其段落给予不同的字体以及加入表格
时间: 2023-06-10 13:02:52 浏览: 328
对于代码的优化,可以像下面这样对段落进行样式调整,给予不同的字体,并且加入表格:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Poems</title>
<style>
body {
background-color: MistyRose;
font-family: sans-serif;
color: DarkSlateGray;
}
h2 {
font-size: 30px;
font-family: Georgia, serif;
color: DarkSlateBlue;
margin-bottom: 5px;
}
p:first-of-type {
font-size: 25px;
line-height: 35px;
font-family: Arial, sans-serif;
margin-top: 0px;
margin-bottom: 20px;
}
p:last-of-type {
font-size: 23px;
line-height: 33px;
font-family: Verdana, sans-serif;
margin-top: 20px;
margin-bottom: 0px;
}
table {
border-collapse: collapse;
border-spacing: 0px;
}
td {
padding: 10px;
border: 1px solid black;
}
</style>
</head>
<body>
<h2>Poem 1</h2>
<p>Roses are red,<br>
Violets are blue,<br>
Sugar is sweet,<br>
And so are you.</p>
<h2>Poem 2</h2>
<p>There is a charm about<br>
the forbidden that makes<br>
it unspeakably desirable.</p>
<table>
<tr>
<td>表格中的内容1</td>
<td>表格中的内容2</td>
</tr>
<tr>
<td>表格中的内容3</td>
<td>表格中的内容4</td>
</tr>
</table>
</body>
</html>
阅读全文