html - Flexbox configuration -
i have following html markup. h1 tag take full of page (100%) , 3 articles appear in 1 row using flexbox. image should shrink fit row if needed.
#content { margin: 0; padding: 0; display: flex; flex-direction: row; flex-wrap: wrap; } #content>h2 { flex: 0 1 100%; } #content>article { padding: 5px; border: 1px solid #cccc33; background: #dddd88; flex: 1 0 50%; } <section id="content"> <h2>featured work</h2> <article> <img src="http://placehold.it/450x450"> </article> <article> <img src="http://placehold.it/450x450"> </article> <article> <img src="http://placehold.it/450x450"> </article> </section> here jsfiddle: https://jsfiddle.net/fejt3m1s/
#content { display: flex; flex-wrap: wrap; align-content: flex-start; /* 1 */ min-height: 800px; margin: 0; padding: 0; } #content>h2 { flex: 0 0 100%; /* 2 */ } #content>article { flex: 1 0 30%; /* 3 */ text-align: center; padding: 5px; border: 1px solid #cccc33; background: #dddd88; } img { max-width: 100%; /* 4 */ } <section id="content"> <h2>featured work</h2> <article> <img src="http://placehold.it/350x350"> </article> <article> <img src="http://placehold.it/350x350"> </article> <article> <img src="http://placehold.it/350x350"> </article> </section> notes:
- pack flex lines top of container (otherwise may gap between lines).
- make
h1consume entire line, forces subsequent items create new lines. - allow 3
articleelements per line. each takes equal width. - keep image inside flex item.
Comments
Post a Comment