Centering Buttons From Different Divs
Solution 1:
UPDATE
You edited your question, so I updated my snippet. The principle is still the same as my original answer; you just need to apply the styles to the correct divs.
/* Begin changes */.box, .contentWrapper {
display: flex;
flex-direction: column;
}
.content {
flex-grow: 1;
display: flex;
}
.contentWrapper {
flex-grow: 1;
justify-content: space-between;
}
/* End changes */.container {
display: flex;
}
.container > div {
width: 200px;
}
.content {
padding: 6%8%;
}
.boxButton {
text-align: center;
}
.image {
margin-left: auto;
margin-right: auto;
}
<divclass="container"><divclass="box"><divclass="image"><imgsrc=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg></div><divclass="content"><divclass="contentWrapper"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sapien est, tempus eget aliquet nec, suscipit vitae lectus. Sed ut convallis lorem, non tincidunt sapien.</p><pclass="boxButton"><button>Button</button></p></div></div></div><divclass="box"><divclass="image"><imgsrc=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg></div><divclass="content"><divclass="contentWrapper"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sapien est, tempus eget aliquet nec, suscipit vitae lectus.</p><pclass="boxButton"><button>Button</button></p></div></div></div><divclass="box"><divclass="image"><imgsrc="http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg"></div><divclass="content"><divclass="contentWrapper"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><pclass="boxButton"><button>Button</button></p></div></div></div></div>
Original Answer
If you only need to support modern browsers, there is a flexbox solution.
.box {
/* The important stuff */display: flex;
flex-direction: column;
justify-content: space-between;
}
/* Not necessary for you; I did this to make the snippet look like your example. */.container {
display: flex;
}
.container > div {
width: 200px;
}
<divclass="container"><divclass="box"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sapien est, tempus eget aliquet nec, suscipit vitae lectus. Sed ut convallis lorem, non tincidunt sapien.</p><div><button>Button</button></div></div><divclass="box"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sapien est, tempus eget aliquet nec, suscipit vitae lectus.</p><div><button>Button</button></div></div><divclass="box"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><div><button>Button</button></div></div></div>
The important part is to have each .box
contain two elements. In this case, I put the text in a <p>
and the button in a <div>
. Then, use display: flex
. justify-content: space-between
pulls the <p>
towards the top and the <div>
towards the bottom.
Solution 2:
Absolutely positioning might be a good way to go, since all those elements are the same height (buttons, and the line of text after the buttons). Just add a container div around those elements.
wrapper {
postition: relative;
padding-bottom: 150px;
}
container {
position:absolute;
bottom: 40px;
}
The other option would be just setting a min-height on the paragraph tag before the button, so the elements above the button are all the same height.
Solution 3:
<html><head><linkrel="stylesheet"href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script></head><body><divclass="col-md-3 text-center"><ahref="#"class="btn btn-info"role="button">Link Button</a></div><divclass="col-md-3 text-center"><buttontype="button"class="btn btn-info">Button</button></div><divclass="col-md-3 text-center"><inputtype="button"class="btn btn-info"value="Input Button"></div><divclass="col-md-3 text-center"><inputtype="submit"class="btn btn-info"value="Submit Button"></div></body></html>
Solution 4:
just add this css to your button
button{ bottom: -40px position: relative;}
Post a Comment for "Centering Buttons From Different Divs"