vertical-align: text-top;
во втором div может приблизительно соответствовать этому
#d1 {
width: 50px;
display: inline-block;
vertical-align: 0.1em; /* rectify the alignment*/
}
#d2 {
width: 50px;
display: inline-block;
vertical-align: text-top;
}
<div style="border:1px solid red;">
<div id="d1">
Here is some text
</div>
<div id="d2">
Here is some other text
</div>
</div>
<div style="border:1px solid red;font-size:20px;">
<div id="d1">
Here is some text
</div>
<div id="d2">
Here is some other text
</div>
</div>
Еще один трюк с использованием float, где вам нужна дополнительная оболочка:
#d1 {
width: 50px;
display: inline-block;
vertical-align: 0.1em;
}
#d2 {
width: 50px;
display: inline-block;
}
#d2:before {
content: "";
display: inline-block;
}
#d2>span {
float: left;
}
<div style="border:1px solid red;">
<div id="d1">
Here is some text
</div>
<div id="d2">
<span>Here is some other text</span>
</div>
</div>
<div style="border:1px solid red;font-size:20px">
<div id="d1">
Here is some text
</div>
<div id="d2">
<span>Here is some other text</span>
</div>
</div>
Еще одна идея, если ширина всегда известна и фиксирована:
.container {
border: 1px solid red;
line-height:1.2em;
}
#d1 {
width: 50px;
}
#d2 {
width: 50px;
margin-top: -1.1em;
transform: translate(50px); /* the width of the first div */
}
<div class="container">
<div id="d1">
Here is some text
</div>
<div id="d2">
Here is some other text
</div>
</div>
<div class="container" style="font-size:20px">
<div id="d1">
Here is some text
</div>
<div id="d2">
Here is some other text
</div>
</div>
Другой с сеткой CSS
.container {
border: 1px solid red;
line-height:1.2em;
display:grid;
grid-template-rows:auto 1.1em auto;
justify-content:flex-start;
}
.container > * {
width: 50px;
grid-row-end:span 2;
}
#d2 {
width: 50px;
grid-column:2;
grid-row-start:2;
}
<div class="container">
<div id="d1">
Here is some text
</div>
<div id="d2">
Here is some other text
</div>
</div>
<div class="container" style="font-size:20px">
<div id="d1">
Here is some text
</div>
<div id="d2">
Here is some other text
</div>
</div>
Во всех приведенных выше решениях вам может потребоваться отрегулировать значения em
в зависимости от используемого шрифта.