【发布时间】:2021-01-16 18:01:05
【问题描述】:
我无法将某些元素与 CSS/HTML 对齐。
Screenshot of my current code output
我的主要目标是即使在窗口调整大小时,左侧“第 2 行”的底部和右侧的徽标也保持在同一条红线上,并确保徽标的中心始终在中间垂直对齐屏幕。
更具体地说:
- 在 即使在窗口调整大小时,红线右侧的徽标也是如此。我知道这个 可以通过将图像的宽度更改为 px 值来解决,但是 我希望徽标的大小根据宽度做出响应 窗口,使其在调整大小时变小,同时仍保持与左侧的“第 2 行”一致。
- 调整绿色部分(.flex-container 类)的高度以始终适合里面的内容,使徽标(.middle 类)始终垂直对齐在窗口的中间(顶部:50vh) .我知道这可以通过将 .flex-container 高度更改为“auto”来解决,但是“g”开始悬挂的点消失了,我需要它可见。
- 文本的字体大小和行高必须保持指定值。
这里是 codepen 的链接:https://codepen.io/yuvi100/pen/yLOdyzG
当前 HTML:
<div class="middle">
<div class="flex-container">
<div class="flex-item left">
<div class="inner-wrapper">
<div class="flex-body">Line 1<br>Line 2</div>
</div>
</div>
<div class="flex-item right">
<div class="inner-wrapper">
<div class="flex-img">
<img src='https://yuvalashkenazi.com/logo.png'>
</div>
<div class="flex-body"></div>
</div>
</div>
</div>
</div>
当前的 CSS:
body {
background: orange;
}
.middle {
position: absolute;
top: 50vh;
transform: translateY(-50%);
}
.left {
float: left;
width: 20vw;
}
.right {
float: right;
width: 80vw;
}
img {
margin-bottom: -40px;
width: 15vw;
}
.flex-container {
overflow: hidden;
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: baseline;
align-items: baseline;
width: 100vw;
height: 320px;
background-color: green;
flex-wrap: nowrap;
box-sizing: border-box;
}
.inner-wrapper {
display: inline-block;
width: 100%;
background-color: cornflowerblue;
}
.flex-body {
border-bottom: 4px solid red;
text-align: left;
color: white;
font-size: 16pt;
line-height: 18pt;
}
.flex-img {
text-align: right;
}
【问题讨论】:
标签: html css flexbox responsive-design vertical-alignment