javascript - 如何将跨度的高度设置为同一行中跨度的最大高度?

标签 javascript html css layout alignment

考虑以下 html 代码:

<span style="display: inline-block;">
<div>Caption - to display at top</div>
<div>Picture - to display at the middle</div>
</span>
<span style="display: inline-block;">
<div>Caption - to display at top</div>
<div>Picture - to display at the middle</div>
</span>

当这些跨度彼此相邻显示时(连续 2 个或 3 个),我希望标题在顶部对齐,图片在中心对齐。图片可能大小不一,标题可能占多行。例如。这是我目前拥有的:http://probqa.com/ Current state - both image and caption are top-aligned 这是我希望它看起来的样子: Desired - caption is top-aligned and image is center-aligned 这可能只用 HTML/CSS 来做吗?怎么办?

或者为此我需要一些 JavaScript 吗?什么?

最佳答案

要在中心放置一些东西,您可以使用这个 css 技巧:

.center{
  position: fixed;
  left: 50%; /*move the top left point of block to the center*/
  transform: translate(-50%,0%);
  margin-top:60px;
}

当您想要更改两个图像或文本之间的距离时,请更改 margin-top 属性。

关于javascript - 如何将跨度的高度设置为同一行中跨度的最大高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54574701/

相关文章:

javascript - 如何检查所有带 Angular 复选框

html - 填充使水平滚动条出现

c# - 使用 Regex C# 从 HTML 标签中删除样式

html - 触摸屏的可拖动范围 slider

javascript - 如何修复 Angular Material Components 的构建错误?

javascript - WebDriver/Java中如何点击子元素

javascript - 使用 id/class 滚动 div 隐藏/显示

html - 将文字放在图片上以适应响应页面

html - 同一行中的三个圆圈使用 HTML 和 Css

javascript - JQuery:当元素隐藏时防止div折叠()