html - 将卡片上的垂直文本与图像对齐

标签 html css

<分区>

我需要在卡片设计的图像后对齐垂直文本。一切都很好,除了文字,我需要文字垂直对齐,因为有些卡片的文字很少或很多(3 或 4 行)

.cardscurso {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
  display: inline-block;
  width: 230px;
  max-width: 240px;
  height: 250px;
  max-height: 230px;
  min-height: 230px;
  background-color: #fff;
  border-radius: 5px;
  border-bottom: 22px solid #1EA4D3;
  color: #4E4E4E;
  margin-right: 0.2em;
  margin-left: 0.2em;
  margin-bottom: 3.2em;
  position: relative;
  font-family: roboto;
  font-size: 0.9em;
  line-height: 1.2944em;
  text-align: center !important;
  text-decoration: none;
}

.cardscurso a {
  text-decoration: none;
  color: #4E4E4E;
}

.cardscurso:hover {
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}

.cardscurso img {
  border-radius: 5px 5px 0 0;
  width: 100%;
  height: auto;
  background-position: center;
  overflow: hidden;
  border-radius: 5px 5px 0 0;
  height: 128px;
  width: 100;
  height: auto;
  border-bottom: 3px solid #1EA4D3;
}

.textin {
  position: relative;
  clear: both;
}

.textin p {
  position: absolute;
  top: 50%;
  -webkit-transform: translateY(20%);
  -moz-transform: translateY(20%);
  -ms-transform: translateY(20%);
  -o-transform: translateY(20%);
  transform: translateY(20%);
  margin: 0;
  padding: 0 1.4em;
  vertical-align: middle;
}
<div class="cardscurso">
  <a href="seguridad-industrial/curso-de-montacargas.html">
    <img src="imagenes/ventas/entrenamiento-para-vendedores.png" alt="Entrenamiento para vendedores" />

    <div class="textin">
      <p>Entrenamiento para vendedores</p>
    </div>
  </a>
</div>

文本未垂直对齐,使用该代码文本与父级对齐,请检查我的代码并提供正确的代码,谢谢!!!

最佳答案

你需要改变<p>标记而不是必须添加 <span>因为vertical-align: middle;不适用于 block 元素,CSS 应该是

.textin{
  line-height: 60px;
}
.textin span{
    display: inline-block;
    vertical-align: middle;
    line-height: 1em;
}

这是链接 https://jsfiddle.net/z306mrj4/8/ 希望这对你有帮助

关于html - 将卡片上的垂直文本与图像对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57188089/

上一篇:javascript - 我可以从一开始就隐藏一张 table 吗?

下一篇:c# - Core 2.0 导航栏横幅覆盖移动设备上的页面内容

相关文章:

html - Div不在列中滚动

html 斜体字母从容器中突出(并且可能被下一个容器的背景切割)

html - CSS 是否有任何预定义的动画?

html - 水平 div 树

CSS 3.0 用户选择属性替换

javascript - 从小到大猫头鹰——旋转木马中心模式

html - 文本的 CSS 垂直对齐底部

css - JAVAFX 表格 View 环绕文本字体颜色

javascript - 使用 Javascript 或 jQuery 自动增加 HTML 表中的数据

javascript - jquery 附加下拉选项禁用 ="disabled"