html - css文本在响应式网站中垂直对齐

标签 html css responsive-design alignment

我在这样的 div 中有一个标题

enter image description here

当我将浏览器缩小时,它看起来像这样:

enter image description here

但我希望它看起来像这样:

enter image description here

我该怎么做?

html:

<div class="wrapper">
        <h4>ALongText LikeThisOne</h4>
</div>

CSS:

.wrapper{
    border:1px red solid;
    height:60px;
}

.wrapper h4{
    margin-top: 0;
    padding-top: 20px;
    text-align: center;
}

jsfiddle:http://jsfiddle.net/4cBxt/

最佳答案

您还可以尝试 transform 属性:

.wrapper h4 {
    margin-top: 0;
    position: relative;
    text-align: center;
    top: 50%;
    transform: translateY(-50%);
    -webkit-transform: translateY(-50%);
    -o-transform: translateY(-50%);
    -moz-transform: translateY(-50%);
    -ms-transform: translateY(-50%);
}

<强> Working fiddle

关于html - css文本在响应式网站中垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23424261/

相关文章:

javascript - 让订单出现在确认警报框中

HTML 谷歌地图添加自定义 div 作为标记

html - 如何在不设置数据库的情况下快速将电子邮件注册表单嵌入我的网站?

css - Div CSS 溢出将后续的 div 推低

css - 在 twitter bootstrap 中使用不同的字体

html - html中可能有 "inheritance"吗?

html - 文本项与 flex-end 不对齐

php - html,css.php?帮助如何将我的表单提交输出到网页而不是文本文件?

html - Css .gif 闪烁故障排除?

html - 如何使用 Bootstrap 在响应图像上放置搜索栏?