【发布时间】:2016-04-26 20:41:44
【问题描述】:
我想将 2 divs 垂直居中,我厌倦了使用 vertical-align: middle 但这不起作用,还尝试了 margin,不起作用。
我可以做些什么来使这两个居中?
代码
.about{
text-align: center;
position: relative;
}
.aboutImg {
position: absolute;
width: 100%;
left: 0px;
}
.textContainer {
position: relative;
width: 60%;
margin-left: auto;
margin-right: auto;
z-index: 20;
}
<div class="about" id="aboutStrings">
<img class="aboutImg" src="about1.jpg">
<div class="textContainer">
<h1>About Strings</h1>
<p>Strings Ramen Shop pulls a piece of Japanese Culture to Chicago, we can be found in the heart of Chinatown, directly across from New Chinatown Square. While other restaurants may serve ramen along with a number of other entrees, Strings Ramen focuses specifically on ramen. Along with ramen, Strings will also offer the appetizing oden, a Japanese winter street food. On top of tasting delightful, the ramen at Strings is also affordable but gives the option of adding more deluxe ingredients. The menu includes four types of ramen broth with a variety of high-end ingredients that are added to make the dish even more delectable.
One of the major aspects of Strings is the noodles themselves. Strings will make fresh noodles daily using only their unique dough mixer and noodle maker imported straight from Japan. The use of fresh noodles, and genuine broth combined with passion and the use of only the best ingredients will certainly set Strings Ramen Shop apart.</p>
</div>
</div>
我还希望图像根据屏幕大小调整大小,最重要的是,文本应该始终包含在图像中。因此,如果屏幕变小时段落的高度拉伸到 500 像素,则图像高度应自动调整大小以包含文本。我已经包含了 Bootstrap css。
【问题讨论】:
-
只是确保我理解,您希望内部
<div>在.aboutdiv 中垂直居中?
标签: html css twitter-bootstrap responsive-design