Bootstrap 3 Align Text To Bottom of Div

前端 未结 5 1786
-上瘾入骨i
-上瘾入骨i 2020-12-03 02:22

I\'m trying to get a setup in Bootstrap that would look something like this, where I have text aligned with the bottom of an image:

=========================         


        
相关标签:
5条回答
  • 2020-12-03 02:50

    Here's another solution: http://jsfiddle.net/6WvUY/7/.

    HTML:

    <div class="container">
        <div class="row">
            <div class="col-sm-6">
                <img src="//placehold.it/600x300" alt="Logo" class="img-responsive"/>
            </div>
            <div class="col-sm-6">
                <h3>Some Text</h3>
            </div>
        </div>
    </div>
    

    CSS:

    .row {
        display: table;
    }
    
    .row > div {
        float: none;
        display: table-cell;
    }
    
    0 讨论(0)
  • 2020-12-03 02:51

    I think your best bet would be to use a combination of absolute and relative positioning.

    Here's a fiddle: http://jsfiddle.net/PKVza/2/

    given your html:

    <div class="row">
        <div class="col-sm-6">
            <img src="~/Images/MyLogo.png" alt="Logo" />
        </div>
        <div class="bottom-align-text col-sm-6">
            <h3>Some Text</h3>
        </div>
    </div>
    

    use the following CSS:

    @media (min-width: 768px ) {
      .row {
          position: relative;
      }
    
      .bottom-align-text {
        position: absolute;
        bottom: 0;
        right: 0;
      }
    }
    

    EDIT - Fixed CSS and JSFiddle for mobile responsiveness and changed the ID to a class.

    0 讨论(0)
  • 2020-12-03 02:52

    The easiest way I have tested just add a <br> as in the following:

    <div class="col-sm-6">
        <br><h3><p class="text-center">Some Text</p></h3>
    </div>
    

    The only problem is that a extra line break (generated by that <br>) is generated when the screen gets smaller and it stacks. But it is quick and simple.

    0 讨论(0)
  • 2020-12-03 02:56

    I collected some ideas from other SO question (largely from here and this css page)

    Fiddle

    The idea is to use relative and absolute positioning to move your line to the bottom:

    @media (min-width: 768px ) {
    .row {
        position: relative;
    }
    
    #bottom-align-text {
        position: absolute;
        bottom: 0;
        right: 0;
      }}
    

    The display:flex option is at the moment a solution to make the div get the same size as its parent. This breaks on the other hand the bootstrap possibilities to auto-linebreak on small devices by adding col-sx-12 class. (This is why the media query is needed)

    0 讨论(0)
  • 2020-12-03 02:57

    You can do this:

    CSS:

    #container {
        height:175px;
    }
    
    #container h3{
        position:absolute;
        bottom:0;
        left:0;
    }
    

    Then in HTML:

    <div class="row">
        <div class="col-sm-6">
            <img src="//placehold.it/600x300" alt="Logo" />
        </div>
        <div id="container" class="col-sm-6">
            <h3>Some Text</h3>
        </div>
    </div>
    

    EDIT: add the <

    0 讨论(0)
提交回复
热议问题