【发布时间】:2021-09-06 05:22:21
【问题描述】:
我的目标是对齐图片旁边的文字!我已经尝试应用 vertical-align:top; 并且它非常有效,但是在您添加更多文本之后,其中一些文本停留在图像旁边的顶部,其余的则落在下面图片。我尝试过使用一堆 div,但都没有帮助。
这是我页面的图片:
HTML 和 CSS:
body {
margin: 3px;
padding: 3px;
background-color: #eeeeee;
}
h1, h5 {
padding: 10px;
margin: 0;
}
.pre-header {
text-align: center;
}
#header-content1-1 {
font-size: 1.15em;
}
img {
vertical-align: top;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Find out who was Avicii!">
<link rel="stylesheet" href="style.css">
<title>David</title>
</head>
<body>
<header>
<div class="pre-header">
<h1 id="header-content1">Avicii - Tim Bergling</h1>
<h5 id="header-content1-1">Swedish DJ, remixer, record producer, musician, and songwriter</h5>
</div>
</header>
<main>
<hr>
<img src="https://i.imgur.com/BX2PS5b.jpeg" alt="Image of Avicii">
<span> this is the textdot oixjf iodfjdoi ndsjfnsjdkf ndsjknf kjdsnf kjdsnfkj sdnfkj nsdjkf nsdjkf ndskjfn kjdsnf jksdnfjk nsdkjf ndsjkfn dskjfn kjsdnf kjdsnfkj dsnfkj ndsjkfn dsjkf ndsjkfn dkjsfn kjdsnf jkdsnf kjdsnf kjdsnfkj dsnkjfn dsjkfndskjfndsjknfjkdsfnjkds nf kjsdnfkjdsnfk</span>
</main>
<footer>
</footer>
</body>
</html>
【问题讨论】: