html - css height, max-height, line-height VS.垂直对齐

标签 html css image height vertical-alignment

<分区>

请帮忙,这让我发疯!

我想我还是不明白属性之间的区别,例如:

  • 高度
  • 最大高度
  • 行高

或者它们如何影响文本和图像的垂直对齐等属性。


我想要什么:

单行文本,垂直居中,内联图像大小不一,在一个 block 中粘在屏幕底部,基本上是这样的:

文本将始终小于单个“屏幕宽度”行,但图像高度可能会有所不同(大于和/或小于文本高度)。


我有什么:

  • Note that the borders and background are only for demo purposes.
    I only need the text & images in a transparent block, stuck to the bottom of the screen.

下面是我生成“我所拥有的”(上图)的代码。我尝试了无数令人沮丧的变体,但似乎离我想要的越来越远。

怎么可能这么多属性似乎什么都不影响?!(我认为我的错误是愚蠢和/或明显的!)

.page-container {
  position: absolute;
  /* does nothing?! */
  height: 100%;
}

.txt-img-container {
  background-color: lightgreen;
  border: dotted 5px green;
  width: 100%;
  position: sticky;
  /* does nothing?! */
  bottom: 0px;
  /* does nothing?! */
  vertical-align: middle;
  /* does nothing?! */
  min-height: 300px;
  /* does nothing?! */
  line-height: 300px;
  /* does nothing?! */
  height: 300px;
  /* does nothing?! */
}

.img-container {
  border: dashed 5px red;
  vertical-align: middle;
  /* does nothing?! */
  min-height: 300px;
  /* does nothing?! */
  line-height: 300px;
  /* does nothing?! */
  height: 300px;
  /* does nothing?! */
}
<div class="page-container">
  <div class="txt-img-container">
    This text && various imgs . . .
    <span class="img-container">
    				<img src="https://placehold.it/50?text=50"/> 
    			</span> . . . should all be centered vertically . . .
    <span class="img-container">
    				<img src="https://placehold.it/100?text=100"/> 
    			</span> . . . within the green 300px div.
  </div>
</div>

最佳答案

尝试将文本放在 span 标签中,并使用 css 填充属性(padding/padding-top/padding-right 等)调整文本在 span 中的位置。

关于html - css height, max-height, line-height VS.垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55315656/

上一篇:html - 导航栏没有完全覆盖

下一篇:html - CSS 代码仅在网站上线时不起作用

相关文章:

java - 线程中的异常 "main"java.lang.IllegalArgumentException : image == null

html - SVG 不在 linkedin 中显示图像

javascript - 如何放置 XML 值并在 href anchor 标记中使用它?

javascript - 输入中的最后一个字母需要为红色

html - 微调器在 IE 中不旋转

css - wordpress style.css 加载但不使用

python - 如何使用openCV保存裁剪后的图像?

javascript - 用动画更改 div 的背景图像

html - 单击 anchor 标记会导致内容从页面中消失

jQuery fadeIn 和 fadeOut 在 chrome 中滞后,但在 Firefox 中没有