External block unknown width. It has 2 pictures of equal width and height. It is necessary to make so that both pictures occupy the entire effective area in width inside the block, but have an indent of exactly 8px between themselves and from the edges of the parent block. Support for older browsers is not needed.
3 answers
Wrap pictures in 50% wide blocks. Pictures stretch to 100%. We register
box-sizing: border-box;so that thewidthproperty determines the width of the blocks themselves, not their contents .Put blocks next to each other using
float: left;. To prevent the parent block from collapsing, assign itoverflow: hidden;. In this case, the height of the parent is calculated taking into account the descendants floating in it.We set the blocks and container
paddingto half the required 8 pixels. In order to avoid indenting from the bottom edge of the pictures, we add thedisplay: block;propertydisplay: block;.
Result: https://jsfiddle.net/glebkema/0u4caqud/
* { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .container { border: 1px solid #999; margin: 20px auto; overflow: hidden; padding: 4px; width: 80%; } .half { float: left; padding: 4px; width: 50%; } .half > img { display: block; width: 100%; } <div class="container"> <div class="half"><img src="//placehold.it/600x300/c69/f9c/?text=Left" alt=""></div> <div class="half"><img src="//placehold.it/600x300/69f/9cf/?text=Right" alt=""></div> </div> Made an option using display: inline-block
*{ padding: 0; margin: 0; box-sizing: border-box; } .b-unknown-width{ text-align: center; font-size: 0; /* убираем отступы */ } .b-unknown__pict-container{ display: inline-block; vertical-align: top; width: calc(50% - 12px); margin: 0 4px; font-size: 16px; } .b-unknown__pict-container:first-of-type{ margin-left: 8px; } .b-unknown__pict-container:last-of-type{ margin-right: 8px; } .b-unknown__pict{ padding-bottom: 100%; position: relative; } .b-unknown__pict > img{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; } <div class="b-unknown-width"> <div class="b-unknown__pict-container"> <div class="b-unknown__pict"> <img src="http://placehold.it/150x150"> </div> </div> <div class="b-unknown__pict-container"> <div class="b-unknown__pict"> <img src="http://placehold.it/150x150"> </div> </div> </div> 1 demo: http://codepen.io/Geyan/pen/Gqyvzk?editors=110
*{ margin:0; padding:0; } .image_wrap{ display:table; margin:auto; } .image_wrap p{ display:table-cell; height:120px; border:4px double #eee; } .image_wrap p img{ display:table-cell; width:200px; height:inherit; margin:8px; } <div class="image_wrap"> <p> <img src="http://www.citylaserclinic.com.au/wp-content/uploads/2015/07/city-laser-clinics-banner.jpg" alt="" /> </p> <p> <img src="http://luxfon.com/pic/201207/2560x1600/luxfon.com-13334.jpg" alt="" /> </p> </div> 