MK-DK
MK-DK

Reputation: 1085

Align button without affecting other buttons

I am working with Bootstrap 3.3.7.

I need button 1 to align like the below picture, but the button should not affect with Button 2. Before that make sense you can see the demo version here.

Demo Version

I have tried to set a margin-top:80px; on button 1, but that is not working below < 768px. I have tried to make a new row and col-sm-12 inside the card, but then the button is going over the text. Button 2 i called the classcta-right, so I know that button is aligning right.

So how can place the button 1 line the picture, no matter if the text is only 4 lines?

I have cut away so much code as possible, so the question is not getting to long.

    body {
      background-color: #f5f5f5;
    }
    div {
      background-color: #fff;
    }
    .index-content a:hover {
      color: black;
      text-decoration: none;
    }
    .index-content .row {
      margin-top: 20px;
    }
    .index-content a {
      color: black;
    }
    .index-content .card {
      background-color: #FFFFFF;
      padding: 0;
      -webkit-border-radius: 4px;
      -moz-border-radius: 4px;
      border-radius: 4px;
      box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    }
    .index-content .card:hover {
      box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
      color: black;
    }
    .index-content .card img {
      width: 100%;
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
      height: 350px;
    }
    .index-content .card h4 {
      margin: 20px;
    }
    .index-content .card p {
      margin: 20px;
      opacity: 0.65;
    }
    .index-content .blue-button {
      width: 100px;
      -webkit-transition: background-color 1s, color 1s;
      /* For Safari 3.1 to 6.0 */
      transition: background-color 0.5s, color 0.5s;
      min-height: 20px;
      background-color: #4CAF50;
      color: #ffffff;
      border-radius: 4px;
      text-align: center;
      font-weight: lighter;
      margin: 0px 20px 15px 20px;
      padding: 5px 0px;
      display: inline-block;
    }
    .index-content .blue-button:hover {
      background-color: #dadada;
      color: #002E5B;
    }
    /* Set width between block elements */
    .small-padding.top {
       padding-top:10px;
    }

    .small-padding.bottom {
        padding-bottom:10px;
    } 
    .small-padding.left {
        padding-left:5px;
    }

    .small-padding.right {
        padding-right:5px;
    }

    .row [class*="col-"] {
      padding-left: 5px;
      padding-right: 5px;
    }

    .margin_bottom {
      margin-bottom: 10px;
    }
    .row [class*="col-"] {
      padding-right: 5px;
      padding-left: 5px;
    }
    .row {
      margin-left: -5px;
      margin-right: -5px;
    }
    .card-img-bottom {
      color: #fff;
      height: 20rem;
      background: url(images/img1.jpg) center no-repeat;
      background-size: cover;
    }
    .img-responsive { 
        height: 100%;
    }
    /* Button Position */
    .centered {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .bottom-right {
        position: absolute;
        bottom: 8px;
        right: 16px;
    }

    .bottom-left {
        position: absolute;
        bottom: 8px;
        left: 16px;
    }

    .inner-wrapper {
      text-align: center;
      background: none;
    }
    /* Set full width on columns */
    @media (max-width: 768px) {
        .img-responsive {
        width: 100%;
        }
    }

    /* GRID ELEMENTS MEDIA QUERIES */
    @media (min-width: 768px) {
      .card {
        position: relative;
      }
      .card-content {
        position: absolute;
        bottom: 0;
        width: 100%;
        background: rgba(0, 0, 0, 0.5);
      }
      .card-content h4,
      .card-content p {
        color: white;
        width: 100%;
        float: left;
        margin: 0 0 5px;
      }
      .card-content a {
        float: right;
      }
      .index-content .card h4,
      .index-content .card p {
        padding: 15px 20px;
        margin: 0;
      }
      .index-content .card p {
        padding: 0 20px 15px;
        margin: 0;
      }
      .card-content-textbox {
        position: absolute;
        top: 0;
        left: 0;
        background: rgba(255, 255, 255, 0.7);
        /*right: 0;*//* top position on right*/
        margin: 15px;
        max-width: 300px;
        height: 91%
      }
    }

/* Grid with different placement of position buttons */
.centered {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.bottom-right {
    position: absolute;
    bottom: 8px;
    right: 16px;
}

.bottom-left {
    position: absolute;
    bottom: 8px;
    left: 16px;
}

.inner-wrapper {
  text-align: center;
  background: none;
}
<div class="container">
    <!-- Full width Banner -->
    <div class="row">
      <a href="#">
        <div class="col-md-12 small-padding top bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/1200x500"></img>
                    <div class="card-content-textbox">
                        <h4>BMW & HEADLINE 2018</h4>
                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                        <a href="#" class="blue-button">BUTTON 1</a>
                    </div>
                </div>
            </div>
        </div>
      </a>
    </div>
    <!-- Col 4 - 8 -->
    <div class="row">
        <div class="col-sm-4 small-padding right bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/390x500"></img>
                    <div class="card-content">
                        <h4>BMW & HEADLINE 2018</h4>
                        <a href="#" class="blue-button">BUTTON 2</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-8 small-padding left bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/800x500"></img>
                    <div class="card-content">
                        <h4>BMW & HEADLINE 2018</h4>
                        <!-- <p>Brødtekst</p> -->
                        <a href="#" class="blue-button">BUTTON 2</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Upvotes: 1

Views: 58

Answers (2)

Razvan Zamfir
Razvan Zamfir

Reputation: 4704

Make use of flexbox:

body {
      background-color: #f5f5f5;
    }
    .flexbox-column {
      display: flex;
      flex-direction:column; /*Stack flex items verically*/
    }
    .flexbox-column .bottom-button {
      margin-top: auto !important /*Send button to bottom*/;
      margin-bottom: 10px;
    }
    div {
      background-color: #fff;
    }
    .index-content a:hover {
      color: black;
      text-decoration: none;
    }
    .index-content .row {
      margin-top: 20px;
    }
    .index-content a {
      color: black;
    }
    .index-content .card {
      background-color: #FFFFFF;
      padding: 0;
      -webkit-border-radius: 4px;
      -moz-border-radius: 4px;
      border-radius: 4px;
      box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    }
    .index-content .card:hover {
      box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
      color: black;
    }
    .index-content .card img {
      width: 100%;
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
      height: 350px;
    }
    .index-content .card h4 {
      margin: 20px;
    }
    .index-content .card p {
      margin: 20px;
      opacity: 0.65;
    }
    .index-content .blue-button {
      width: 100px;
      -webkit-transition: background-color 1s, color 1s;
      /* For Safari 3.1 to 6.0 */
      transition: background-color 0.5s, color 0.5s;
      min-height: 20px;
      background-color: #4CAF50;
      color: #ffffff;
      border-radius: 4px;
      text-align: center;
      font-weight: lighter;
      margin: 0px 20px 15px 20px;
      padding: 5px 0px;
      display: inline-block;
    }
    .index-content .blue-button:hover {
      background-color: #dadada;
      color: #002E5B;
    }
    /* Set width between block elements */
    .small-padding.top {
       padding-top:10px;
    }

    .small-padding.bottom {
        padding-bottom:10px;
    } 
    .small-padding.left {
        padding-left:5px;
    }

    .small-padding.right {
        padding-right:5px;
    }

    .row [class*="col-"] {
      padding-left: 5px;
      padding-right: 5px;
    }

    .margin_bottom {
      margin-bottom: 10px;
    }
    .row [class*="col-"] {
      padding-right: 5px;
      padding-left: 5px;
    }
    .row {
      margin-left: -5px;
      margin-right: -5px;
    }
    .card-img-bottom {
      color: #fff;
      height: 20rem;
      background: url(images/img1.jpg) center no-repeat;
      background-size: cover;
    }
    .img-responsive { 
        height: 100%;
    }
    /* Button Position */
    .centered {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .bottom-right {
        position: absolute;
        bottom: 8px;
        right: 16px;
    }

    .bottom-left {
        position: absolute;
        bottom: 8px;
        left: 16px;
    }

    .inner-wrapper {
      text-align: center;
      background: none;
    }
    /* Set full width on columns */
    @media (max-width: 768px) {
        .img-responsive {
        width: 100%;
        }
    }

    /* GRID ELEMENTS MEDIA QUERIES */
    @media (min-width: 768px) {
      .card {
        position: relative;
      }
      .card-content {
        position: absolute;
        bottom: 0;
        width: 100%;
        background: rgba(0, 0, 0, 0.5);
      }
      .card-content h4,
      .card-content p {
        color: white;
        width: 100%;
        float: left;
        margin: 0 0 5px;
      }
      .card-content a {
        float: right;
      }
      .index-content .card h4,
      .index-content .card p {
        padding: 15px 20px;
        margin: 0;
      }
      .index-content .card p {
        padding: 0 20px 15px;
        margin: 0;
      }
      .card-content-textbox {
        position: absolute;
        top: 0;
        left: 0;
        background: rgba(255, 255, 255, 0.7);
        /*right: 0;*//* top position on right*/
        margin: 15px;
        max-width: 300px;
        height: 91%
      }
    }

/* Grid with different placement of position buttons */
.centered {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.bottom-right {
    position: absolute;
    bottom: 8px;
    right: 16px;
}

.bottom-left {
    position: absolute;
    bottom: 8px;
    left: 16px;
}

.inner-wrapper {
  text-align: center;
  background: none;
}
<div class="container">
    <!-- Full width Banner -->
    <div class="row">
      <a href="#">
        <div class="col-md-12 small-padding top bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/1200x500"></img>
                    <div class="card-content-textbox flexbox-column">
                        <h4>BMW & HEADLINE 2018</h4>
                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                        <a href="#" class="blue-button bottom-button">BUTTON 1</a>
                    </div>
                </div>
            </div>
        </div>
      </a>
    </div>
    <!-- Col 4 - 8 -->
    <div class="row">
        <div class="col-sm-4 small-padding right bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/390x500"></img>
                    <div class="card-content">
                        <h4>BMW & HEADLINE 2018</h4>
                        <a href="#" class="blue-button">BUTTON 2</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-8 small-padding left bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/800x500"></img>
                    <div class="card-content">
                        <h4>BMW & HEADLINE 2018</h4>
                        <!-- <p>Brødtekst</p> -->
                        <a href="#" class="blue-button">BUTTON 2</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

You can use the .flexbox-column and .bottom-button classes anywhere on the site and place as many buttons at the bottom as you need.

Upvotes: 1

Chaska
Chaska

Reputation: 3205

How about adding

.top .index-content .blue-button {
  position: absolute;
  bottom: 0;
}

for screen width > 768 ?

body {
      background-color: #f5f5f5;
    }
    div {
      background-color: #fff;
    }
    .index-content a:hover {
      color: black;
      text-decoration: none;
    }
    .index-content .row {
      margin-top: 20px;
    }
    .index-content a {
      color: black;
    }
    .index-content .card {
      background-color: #FFFFFF;
      padding: 0;
      -webkit-border-radius: 4px;
      -moz-border-radius: 4px;
      border-radius: 4px;
      box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    }
    .index-content .card:hover {
      box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
      color: black;
    }
    .index-content .card img {
      width: 100%;
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
      height: 350px;
    }
    .index-content .card h4 {
      margin: 20px;
    }
    .index-content .card p {
      margin: 20px;
      opacity: 0.65;
    }
    .index-content .blue-button {
      width: 100px;
      -webkit-transition: background-color 1s, color 1s;
      /* For Safari 3.1 to 6.0 */
      transition: background-color 0.5s, color 0.5s;
      min-height: 20px;
      background-color: #4CAF50;
      color: #ffffff;
      border-radius: 4px;
      text-align: center;
      font-weight: lighter;
      margin: 0px 20px 15px 20px;
      padding: 5px 0px;
      display: inline-block;
    }
    .index-content .blue-button:hover {
      background-color: #dadada;
      color: #002E5B;
    }
    /* Set width between block elements */
    .small-padding.top {
       padding-top:10px;
    }

    .small-padding.bottom {
        padding-bottom:10px;
    } 
    .small-padding.left {
        padding-left:5px;
    }

    .small-padding.right {
        padding-right:5px;
    }

    .row [class*="col-"] {
      padding-left: 5px;
      padding-right: 5px;
    }

    .margin_bottom {
      margin-bottom: 10px;
    }
    .row [class*="col-"] {
      padding-right: 5px;
      padding-left: 5px;
    }
    .row {
      margin-left: -5px;
      margin-right: -5px;
    }
    .card-img-bottom {
      color: #fff;
      height: 20rem;
      background: url(images/img1.jpg) center no-repeat;
      background-size: cover;
    }
    .img-responsive { 
        height: 100%;
    }
    /* Button Position */
    .centered {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .bottom-right {
        position: absolute;
        bottom: 8px;
        right: 16px;
    }

    .bottom-left {
        position: absolute;
        bottom: 8px;
        left: 16px;
    }

    .inner-wrapper {
      text-align: center;
      background: none;
    }
    /* Set full width on columns */
    @media (max-width: 768px) {
        .img-responsive {
        width: 100%;
        }
    }

    /* GRID ELEMENTS MEDIA QUERIES */
    @media (min-width: 768px) {
    .top .index-content .blue-button {
      position: absolute;
      bottom: 0;
    }
      .card {
        position: relative;
      }
      .card-content {
        position: absolute;
        bottom: 0;
        width: 100%;
        background: rgba(0, 0, 0, 0.5);
      }
      .card-content h4,
      .card-content p {
        color: white;
        width: 100%;
        float: left;
        margin: 0 0 5px;
      }
      .card-content a {
        float: right;
      }
      .index-content .card h4,
      .index-content .card p {
        padding: 15px 20px;
        margin: 0;
      }
      .index-content .card p {
        padding: 0 20px 15px;
        margin: 0;
      }
      .card-content-textbox {
        position: absolute;
        top: 0;
        left: 0;
        background: rgba(255, 255, 255, 0.7);
        /*right: 0;*//* top position on right*/
        margin: 15px;
        max-width: 300px;
        height: 91%
      }
    }

/* Grid with different placement of position buttons */
.centered {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.bottom-right {
    position: absolute;
    bottom: 8px;
    right: 16px;
}

.bottom-left {
    position: absolute;
    bottom: 8px;
    left: 16px;
}

.inner-wrapper {
  text-align: center;
  background: none;
}
<div class="container">
    <!-- Full width Banner -->
    <div class="row">
      <a href="#">
        <div class="col-md-12 small-padding top bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/1200x500"></img>
                    <div class="card-content-textbox">
                        <h4>BMW & HEADLINE 2018</h4>
                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                        <a href="#" class="blue-button">BUTTON 1</a>
                    </div>
                </div>
            </div>
        </div>
      </a>
    </div>
    <!-- Col 4 - 8 -->
    <div class="row">
        <div class="col-sm-4 small-padding right bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/390x500"></img>
                    <div class="card-content">
                        <h4>BMW & HEADLINE 2018</h4>
                        <a href="#" class="blue-button">BUTTON 2</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-8 small-padding left bottom">
            <div class="index-content">
                <div class="card">
                    <img src="http://placehold.it/800x500"></img>
                    <div class="card-content">
                        <h4>BMW & HEADLINE 2018</h4>
                        <!-- <p>Brødtekst</p> -->
                        <a href="#" class="blue-button">BUTTON 2</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Upvotes: 1

Related Questions