css - 如何正确对齐居中的行内 block 元素?

标签 css html position css-float css-position

http://jsfiddle.net/ytn6z8oo/

要查看问题所在,请在 jsfiddle 中调整结果窗口的大小,使三个元素连续出现。如您所见,第三项与其他项不一致,显然是因为它的内容较少。我怎样才能解决这个问题?我尝试了 float:left,但后来它们不再居中,这是必不可少的。

HTML

<div id="red">

<figure class="red"><img src="images/redaktion_fotos/kubi.jpg" class="profil" /> <figcaption>Kubilay Yalçın</figcaption>
<p><img src="/templates/askanier/images/icons/crown.png" /> Chefredakteur</p>
<p><img src="/templates/askanier/images/icons/askanier.png" /> Allgemein</p><br>
<p><a href="https://www.facebook.com/kubyal" class="button fb" target="_blank">Kontakt</a><a href="mailto:kubilayyalcin@yahoo.de" class="button mail">Kontakt</a></p>
</figure>

<figure class="red"><img src="images/redaktion_fotos/simon.jpg" class="profil" /> <figcaption>Simon Mathewson</figcaption>
<p><img src="/templates/askanier/images/icons/cursor.png" /> Website</p>
<p><img src="/templates/askanier/images/icons/askanier.png" /> Allgemein</p>
<br>
<p><a href="https://www.facebook.com/simon.mathewson" class="button fb" target="_blank">Kontakt</a></p>
</figure>

<figure class="red"><img src="images/redaktion_fotos/sophie.jpg" class="profil" /> <figcaption>Sophie Altst&auml;dt</figcaption>
<p><img src="/templates/askanier/images/icons/sport.png" /> Sport und Fitness</p><br>
<p><a href="https://www.facebook.com/sophie.eatme" class="button fb">Kontakt</a></p>
</figure>

<figure class="red"><img src="images/redaktion_fotos/safa.jpg" class="profil" /> <figcaption>Safa Hazem</figcaption>
<p><img src="/templates/askanier/images/icons/karikatur.png" /> Karikaturistin</p><br>
<p><a href="https://www.facebook.com/safa.ha.921" class="button fb" target="_blank">Kontakt</a></p>
</figure>

<figure class="red"><img src="images/redaktion_fotos/vicky.jpg" class="profil" /> <figcaption>Vicky Mielczarek</figcaption>
<p><img src="/templates/askanier/images/icons/fashion.png" /> Mode und Lifestyle</p><br>
<p><a href="https://www.facebook.com/vicky.mk.5" class="button fb target="_blank"">Kontakt</a></p>
</figure>


</div>

CSS

#red {
  padding: 0 0 20px 0;
  text-align: center;
}

#red::after {
  content: "";
  display: block;
  height: 0;
  clear: both;
}

figure.red {
  margin: 30px 15px 0 15px;
  display: inline-block;
  background-color: #ddd;
  border: 1px solid #ccc;
  padding: 10px 10px 0 10px;
  font-family: dejan;
  height: 300px;
} 

figure.red:hover {
  border: 1px solid #bbb;
}

figure.red img.profil {
  width: 150px;
  height: 150px;
  margin: 0 auto;
  display: block;
}

figure.red figcaption {
  color: white;
  background: url(../images/figcaption.png) no-repeat;
  width: 236px;
  height: 44px;
  font-weight: bold;
  text-shadow: -1px -1px 0px rgba(0,0,0,0.5);
  padding-top: 25px;
  margin: -12px auto 0 auto;
  text-align: center;
}

figure.red p {
  margin: 0;
  text-align: center;
}

figure.red .button {
  margin-bottom: -10px;
  padding: 10px 15px 10px 40px;
  background-position: center left 15px;
}

figure.red .fb {
  background-image: url(../images/icons/fb.png);
  background-color: #3b5998;
  background-repeat: no-repeat;
}

figure.red .mail {
  background-image: url(../images/icons/mail.png);
  background-color: #666;
  background-repeat: no-repeat;
}

figure.red figcaption a.button:last-child {
  margin-left: 5px;
}

最佳答案

您可以使用 vertical-align: top; 覆盖默认的 vertical-align 值,即 baseline

figure.red {
  vertical-align: top;
} 

fiddle :http://jsfiddle.net/ytn6z8oo/1/

关于css - 如何正确对齐居中的行内 block 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26464489/

相关文章:

javascript - 检测对后台附件的支持 : fixed?

html - float 时Div和Button元素碰撞

javascript - Bootstrap 日期选择器依赖项

html - 带预处理的流式 MP3

html - 我怎样才能制作一个倾斜的倾斜div框

html - 拨动开关 slider 位置有问题

css - 在有序列表编号的左侧添加图像图标

CSS:居中位置:固定

html - 如何在 css 开关上放置内容

javascript - 基于 JavaScript 或 jQuery 中的条件逻辑向页面添加 HTML