简体   繁体   English

div内块的垂直对齐中间

[英]Vertical-align middle for block inside div

I'm having trouble with vertical-align: center for <p> inside <div> . 我在vertical-align中遇到麻烦: <div><div> <p>中心。 There is nothing more to explain so I just link JSfidle I'm JSFiddle link 没有更多的解释了,所以我只是链接JSfidle 我是JSFiddle链接

edit: please remember that there is ` 编辑:请记住,有`

.cover-price p{

    width: 100%;
    height: 50px;
    background-color: rgba(0,0,0, .3);`

so there is a small blackbackground for price. 因此价格会有一个小的blackbackground。

Use display: table; 使用display: table; to your main div and display: table-cell; vertical-align: middle; 到您的主div并display: table-cell; vertical-align: middle; display: table-cell; vertical-align: middle; to your p 到你的p

Demo 演示版

i added the "position:absolute;" 我添加了“ position:absolute;” attribute-value to the css sheet along with a "margin-top:170px; (which effects 170 in relation to the imaged div) css工作表的属性值以及“ margin-top:170px;”(相对于成像的div效果为170)

.cover-price{
    height: 300px;
    width: 300px;
    background-repeat: no-repeat;
    background-size: cover;
    *position:absolute;*
}
.cover-price p{
    margin: auto 0;
    width: 100%;
    background-color: rgba(0,0,0, .3);
    color: white;
    *margin-top:170px;*
}

let me know if this helps at all. 让我知道这是否有帮助。 This is, of course, placing the $20.00 in the middle of the image (i just hope that's what you want). 当然,这是将$ 20.00放置在图像的中间(我只是希望那是您想要的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM