简体   繁体   English

表格单元中内联元素的垂直对齐

[英]Vertical alignment of inline element in table-cell

I have multiple divs with dynamic content and all of them have the same height. 我有多个具有动态内容的div,并且它们的高度都相同。 Beside the content a Submit Button is inside of each div, which is directly next to the content. 在内容旁边,每个div内部都有一个Submit Button,它紧邻内容。 But i want to display the Button at the bottom of the div. 但是我想在div的底部显示Button。

HTML Markup: HTML标记:

<div class="product-teaser-row">
    <div class="product-teaser">
         <h2>Title</h2>

        <p>Content Content Content Content Content Content Content Content Content Content Content Content Content Content</p>
        <button class="btn btn-grey" type="submit" name="action">Ansehen</button>
    </div>
    <div class="product-teaser">
         <h2>Title 2</h2>

        <p>Content</p>
        <button class="btn btn-grey" type="submit" name="action">Ansehen</button>
    </div>
</div>

CSS Code: CSS代码:

div.product-teaser {
    border: 1px #c7d2d6 solid;
    padding: 0px 10px 10px 10px;
    width: 216px;
    height: 100%;
    display: table-cell;
}

div.product-teaser-row {
    display: table;
    border-collapse: separate;
    border-spacing: 10px;
}

I've already tried different things like vertical-align: bottom on the div and display: inline-block on the Button, but nothing worked for me. 我已经尝试了不同的操作,例如vertical-align: bottom在div上的vertical-align: bottomdisplay: inline-block在Button上的display: inline-block ,但是对我没有任何帮助。

Here is a JSFiddle Demo of my code. 这是我的代码的JSFiddle演示

You can try this 你可以试试这个

CSS CSS

div.product-teaser {
    border: 1px #c7d2d6 solid;
    padding: 0px 10px 20px 10px; /*Increase the bottom padding so the button does not overlap the content*/
    width: 216px;
    height: 100%;
    display: table-cell;
  position: relative; /*Add this css*/
}

/*Set the button at the bottom using position: absolute;*/
    .btn-grey {
      bottom: 5px;
        left: 5px;
        position: absolute;
    }

To do that you just have to position absolute your button and define the bottom position and give a padding-bottom to your container to be sure that no content will override your button. 为此,您只需要absolute 定位按钮并定义底部位置,并在容器的底部加上padding-bottom以确保没有内容会覆盖按钮。

here for a jsfiddle exemple. 这里是一个jsfiddle的例子。

You could try adding a height property to the p element. 您可以尝试将height属性添加到p元素。

Example: 例:

p{
  height: 95px;
}

JSFiddle Demo : http://jsfiddle.net/robcabrera/g3p2Y/1/ JSFiddle演示: http : //jsfiddle.net/robcabrera/g3p2Y/1/

why don't you put button in separate <div> tag like: 为什么不将button放在单独的<div>标签中,例如:

 <div id=my>

     <button class="btn btn-grey" type="submit" name="action">
           Ansehen    
     </button>

</div>

set according margin-top to put the button at bottom like: 根据页margin-top设置margin-top以将按钮放在底部,例如:

#my
{
   margin-top:100px;

}

FIDDLE here 在这里

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

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