我有一个带有BG图像的DIV,我想在该DIV中垂直和水平方向只居中两段。下面的代码:垂直和水平对齐DIV
代码:
#dark-table-carol {
background-color: #2e2e2e;
width: 100%;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 40px;
padding-right: 40px;
text-align: left;
margin-top: 30px;
margin-bottom: 30px;
background-image: url(http://scott.ewarena.com/blog/wp-content/themes/bootstrapstarter/carol-candy-carts-quote.jpg);
height: 600px;
background-repeat: no-repeat;
background-position: center bottom;
margin: auto;
/*
position: absolute;
background-size:contain;
top: 0;
left: 0;
bottom: 0;
right: 0;
*/
}
<div id="dark-table-carol">
<h3 id="dark-table-head-style" align="center">"It was like Scott reached into my head and saw exactly what I wanted to achieve. He brought my ideas to life very quickly!</h3>
<p id="dark-table-paragraph" align="center">
Carol Davies - Carol's Candy Carts
</p>
</div>
我已经尝试了几件事情,显然vertical-align:middle;
,顶级&底部设置填充至50%,但没有运气。
任何建议将是伟大的:)谢谢! Scott
这个工作一种享受。非常感谢!我曾尝试过vertical-align:middle;但没有使用display:table-cell;选项。我将不得不阅读它的用法。 谢谢! –
快乐,我很高兴它适合你:)。 – Gezzasa