【发布时间】:2022-11-28 15:08:41
【问题描述】:
抱歉这个愚蠢的问题,但我对 CSS 很陌生。 我正在尝试将两个元素与 display: table 并排对齐。
然而,右边的元素莫名其妙地(对我来说)比左边的元素更多地位于底部。
.container {
content: "";
display: table;
clear: both;
margin-left: 10%;
margin: 0 auto;
/* width: auto;
height: auto; */
vertical-align: middle;
border-radius: 5px;
border: 5px solid #ff656c;
height: auto;
padding: 0 20px;
width: inherit;
}
#column1 {
display: table-cell;
}
#column2 {
display: table-cell;
width: 50%;
}
#scope {
width: 100%;
padding-right: 5px;
}
<div class="container">
<div id="column1">
<img id="scope" src="https://cdn.pixabay.com/photo/2018/07/08/19/59/blood-pressure-3524615_960_720.jpg">
</div>
<div id="column2">
<h2>Welcome to PATHFINDER</h2>
<p>For people with heart failure, GPs are crucial in initiating and optimising dosages of recommended medications
</p>
<p>The National Heart Foundation of Australia and the Cardiac Society of Australia and New Zealand published guidelines that outline the goal of pharmacological therapy for persons with heart failure with reduced ejection fraction (HFrEF), and how to
up-titrate these medicines.</p>
<p>PATHFINDER aims to provide assistance to GPs to identify the most appropriate medicines and dosages for each patient</p>
</div>
</div>
我尝试使用我用于放入两列的表单的相同代码,并查看盒子模型中是否存在任何问题,但我真的无法解决这个问题......
任何帮助深表感谢!
【问题讨论】:
-
使用 flex 而不是 table - 这将帮助您并排对齐项目。
-
您可以将
vertical-align附加到#column2作为vertical-align: top;或vertical-align: middle;。不过,我想知道为什么您需要table布局来处理这个特定示例。因为还有其他现代替代品,如flex或grid用于通用布局目的。