用弹性盒子写一个卡片,卡片内容有照片放在最左边,右边放文字内容,呈上下分布
时间: 2023-05-29 15:03:22 浏览: 60
HTML代码:
```html
<div class="card">
<img src="photo.jpg" alt="照片">
<div class="content">
<h2>卡片标题</h2>
<p>卡片内容</p>
</div>
</div>
```
CSS代码:
```css
.card {
display: flex;
align-items: center;
padding: 20px;
background-color: white;
border-radius: 10px;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3);
}
.card img {
width: 150px;
height: 150px;
object-fit: cover;
border-radius: 50%;
margin-right: 20px;
}
.card .content {
display: flex;
flex-direction: column;
}
.card h2 {
margin: 0;
font-size: 24px;
font-weight: bold;
}
.card p {
margin: 10px 0;
font-size: 18px;
line-height: 1.5;
}
```
说明:
1. .card 设置为弹性盒子,使其内部元素能够灵活布局;
2. align-items: center; 属性使照片和文字内容垂直居中对齐;
3. 照片使用了 border-radius: 50%; 属性使其变为圆形;
4. 文字内容部分使用了 flex-direction: column; 属性使其呈上下分布。