html - Make divs same size as the biggest one inside the parent -
so have div
3 childs, 1 of them has less text others, image , button move, want position of image not dependent of size of text, can stay in same position biggest child image.
parent position: relative;
, child position: absolute;
doesn't work, because image , button traslape
html:
<div id="child"> <h5>about us</h5> <p>lorem ipsum dolor sit amet, consectetuer adipiscing elit. donec molestie. .</p> <img class="img-responsive" src="http://www.marijazaric.com/minimalism_responsive/images/picture1.jpg" alt=""/> <button>read more</button> </div>
sass:
.parent display: flex flex-wrap: wrap justify-content: center #child border-style: solid margin-left: 25px margin-right: 25px
if declare each of "child" elements flex container, can layout want.
this quick example assumes parent element 3 elements "child" class
value instead of id
value. in each "child" p
element allowed grow take of available vertical space. third "child" includes half-height image show how img
, button
stay pinned bottom.
.parent { display: flex; flex-direction: row; justify-content: center; } .child { border: 1px solid #000; display: flex; flex-direction: column; width: 30%; margin: 1em; padding: 1em; } .child h5 { } /* should replaced class selector */ .child p { flex-grow: 1; } .child img { } .child button { }
<div class="parent"> <div class="child"> <h5>about us</h5> <p> maecenas aliquet enim ut mi lobortis, faucibus orci interdum. suspendisse potenti. ut lobortis varius fringilla. nunc nec urna metus. ut vel ligula rhoncus nulla ultrices egestas ac ut arcu. cras eu odio est. in quis bibendum arcu. </p> <img src="http://placehold.it/326x290"> <button>read more</button> </div> <div class="child"> <h5>services</h5> <p> cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. ut dui risus, placerat non lorem vitae, laoreet imperdiet mauris. aenean eleifend augue vel purus tincidunt egestas. morbi sagittis neque efficitur posuere fermentum. fusce non lectus @ enim sodales dapibus. nam congue neque nunc, ut accumsan mauris ornare sit amet. nulla quis quam ut urna ullamcorper commodo. curabitur ac elit @ urna molestie pulvinar id @ nisi. cras in quam @ magna hendrerit fermentum. vestibulum vel nulla aliquet, molestie ante eu, laoreet quam. </p> <img src="http://placehold.it/326x290"> <button>read more</button> </div> <div class="child"> <h5>latest news</h5> <p> maecenas dolor pretium, maximus mi eu, molestie ligula. donec aliquam mollis eros @ sodales. pellentesque vitae dui feugiat, tempor eros eu, bibendum massa. nulla accumsan finibus leo, et pellentesque urna vestibulum ut. nullam arcu lectus, consectetur varius sed, finibus nec metus. morbi lorem nulla, maximus vitae mi in, efficitur elementum mi. praesent sit amet risus est. </p> <img src="http://placehold.it/326x145"> <button>read more</button> </div> </div>
sass version of code snippet's css:
.parent display: flex flex-direction: row justify-content: center .child border: 1px solid #000 display: flex flex-direction: column width: 30% margin: 1em padding: 1em h5 p flex-grow: 1 img, button
Comments
Post a Comment