html如何将图片放在左边文字在右
时间: 2024-09-22 15:08:49 浏览: 183
要在HTML中创建一个图片位于左侧、文字在右侧的布局,你可以使用`<figure>`和`<figcaption>`元素结合浮动(float)属性来实现。这是一个基本的例子:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.image-container {
display: flex;
justify-content: space-between; /* 这会让图片和文字并排,但图片靠左 */
}
img {
float: left; /* 将图片设置为左浮动 */
}
figcaption {
margin-left: 10px; /* 添加一些间距,防止文字贴着图片 */
}
</style>
</head>
<body>
<div class="image-container">
<img src="path_to_your_image.jpg" alt="Image description">
<figcaption>这是图片的描述或文本</figcaption>
</div>
</body>
</html>
```
在这个例子中,`.image-container`设置了弹性布局,并使用`justify-content: space-between`确保图片和文字之间有间隔。`img`标签被设置为浮动在左边,而`figcaption`则在其后添加了边距以保持清晰。
阅读全文
相关推荐


















