【发布时间】:2021-02-25 03:52:46
【问题描述】:
我一直在尝试使用 CSS,但仍然无法做到这一点。
基本上,内容区域就是图片。
div.logo-content-background {
position: fixed;
top: 0px;
left: 0px;
width: 50%;
height: 100%;
background-color: #577fa1;
z-index: 1;
}
div.logo-content-block {
background: #f3f2f0;
width: 80%;
height: 60%;
position: absolute;
top: 50%;
right: 0%;
transform: translate(0, -50%);
}
div.content-description {
padding-left: 50px;
padding-right: 50px;
vertical-align: middle;
position: absolute;
top: 50%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
div.logo-content-background2 {
position: fixed;
top: 0px;
right: 0px;
width: 50%;
height: 100%;
background-color: #f3f2f0;
z-index: 2;
}
<div class="logo-content-background">
<div class="logo-content-block">
<div class="content-description">
<h3>
CLIF Bar
</h3>
<p>
CLIF BAR® is the first bar we made, and it’s still everything we’re about. Nutritious, sustainable ingredients, like organic rolled oats. Performance nutrition. And great taste. Whether you’re on a 150-mile bike ride or exploring a new trail, it’s the ultimate energy bar™ for keeping your adventure going.
</p>
</div>
</div>
</div>
<div class="logo-content-background2">
<img src="http://charlottemcmanus.files.wordpress.com/2012/03/butterclock-2.jpg" width="300px" height="100px" style="vertical-align:middle; margin:50% 0px" />
</div>
我认为我的代码中有很多不必要的东西,但我还是前端开发的新手。我想垂直对齐图像。我该怎么做?
【问题讨论】: