{"id":191,"date":"2018-11-13T16:33:51","date_gmt":"2018-11-13T11:03:51","guid":{"rendered":"https:\/\/www.virtueinfo.com\/blog\/?p=191"},"modified":"2018-11-13T16:37:27","modified_gmt":"2018-11-13T11:07:27","slug":"css-tricks-how-to-get-equal-height-of-box-in-a-row","status":"publish","type":"post","link":"https:\/\/www.virtueinfo.com\/blog\/css-tricks-how-to-get-equal-height-of-box-in-a-row\/","title":{"rendered":"CSS Tricks &#8211; How to Get Equal height of box in a row"},"content":{"rendered":"<p>Website designing has evolved considerably which enables us to create many new and innovative designs if done right. One of the website design trends is having equal heights of box in a row.<\/p>\n<p>When designing box view HTML, the same height box often requires the attention of web designers.<\/p>\n<p>Equal height columns with background box have been a need of web designers everywhere while building HTML. If all the inner box have the same background, equal height is irrelevant because you can set that background on a parent element. But if one or more columns need to have their own background, it becomes very important to the visual integrity of the design.<\/p>\n<h5>How does it work?<\/h5>\n<h6 class=\"steps\"><span>Step 1:<\/span> Markup<\/h6>\n<p>I&#8217;ve created a <code>.flex-row<\/code> container with a items of <code>.flex-column<\/code> elements inside. Each list <code>.items<\/code> contains some content elements such as <code>&lt;img&gt;<\/code>, <code>&lt;a&gt;<\/code>, <code>&lt;h1&gt;<\/code> and <code>&lt;p&gt;<\/code>.<\/p>\n<pre class=\"lang:xhtml decode:true \" title=\"HTML\" ><div class=\"flex-row\">\r\n\t<div class=\"flex-column\">\r\n\t\t<div class=\"items\">\r\n\t\t\t<h2>What is Lorem Ipsum?<\/h2>\r\n\t\t\t<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.<\/p>\r\n\t\t<\/div>\r\n\t<\/div>\r\n\t<div class=\"flex-column\">\r\n\t\t<div class=\"items\">\r\n\t\t\t<h2>Why do we use it?<\/h2>\r\n\t\t\t<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.<\/p>\r\n\t\t<\/div>\r\n\t<\/div>\r\n\t<div class=\"flex-column\">\r\n\t\t<div class=\"items\">\r\n\t\t\t<h2>Where does it come from?<\/h2>\r\n\t\t\t<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.<\/p>\r\n\t\t<\/div>\r\n\t<\/div>\r\n<\/div><\/pre>\n<h6 class=\"steps\"><span>Step 2:<\/span> Create a flexbox container<\/h6>\n<p>First let&#8217;s use the <code>display:flex;<\/code> value to be declared on the containing element <code>.flex-row<\/code>, which as a result makes it&#8217;s direct children flex elements <code>.flex-column<\/code>. Flex-wrap means that items will move to new row when the horizontal space is empty. <\/p>\n<pre class=\"lang:css decode:true \" title=\"CSS\" >.flex-row {\r\n  display: -ms-flexbox;\r\n  display: flex;\r\n  -ms-flex-wrap: wrap;\r\n  flex-wrap: wrap;\r\n  margin-right: -15px;\r\n  margin-left: -15px;\r\n}<\/pre>\n<h6 class=\"steps\"><span>Step 3:<\/span> Add flex to column<\/h6>\n<p>The flex property is shorthand for flex grow, flex shrink and flex basis. I have used <code>flex: 0 0 100%;<\/code> which means:<br \/>\n<code>flex-grow: 0;<\/code><br \/>\n<code>flex-shrink: 0;<\/code><br \/>\n<code>flex-basis: 100%;<\/code><br \/>\nHere, Flex-basis is set to 100%, so the free space is used based on the flex-grow value.<\/p>\n<pre class=\"lang:css decode:true \" title=\"CSS\" >.flex-column {\r\n  width: 100%;\r\n  padding: 15px;\r\n  -ms-flex: 0 0 100%;\r\n  flex: 0 0 100%;\r\n  max-width: 100%;\r\n}<\/pre>\n<h6 class=\"steps\"><span>Step 4:<\/span> Add media queries for column width<\/h6>\n<p>Here I&#8217;ve added some media queries. My layout will start with one item per row until the screen size reaches 768px. Then it will fit two items into each row until the screen size gets to 992px, Then it will fit three items into each row until the screen size gets to 1200px, when it switches to four items per row. <\/p>\n<pre class=\"lang:css decode:true \" title=\"@Media CSS\" >@media (min-width: 768px) {\r\n  .flex-column {\r\n    -ms-flex: 0 0 50%;\r\n    flex: 0 0 50%;\r\n    max-width: 50%;\r\n  }\r\n}\r\n\r\n@media (min-width: 992px) {\r\n  .flex-column {\r\n    -ms-flex: 0 0 33.333333%;\r\n    flex: 0 0 33.333333%;\r\n    max-width: 33.333333%;\r\n  }\r\n}\r\n\r\n@media (min-width: 1200px) {\r\n  .flex-column {\r\n    -ms-flex: 0 0 25%;\r\n    flex: 0 0 25%;\r\n    max-width: 25%;\r\n  }\r\n}<\/pre>\n<h6 class=\"steps\"><span>Step 5:<\/span> Set height to items<\/h6>\n<p>I&#8217;ve added <code>height: 100%;<\/code> to the <code>.items<\/code> so that <code>.items<\/code> element will equal heights as <code>.flex-column<\/code> element.<\/p>\n<pre class=\"lang:css decode:true \" title=\"CSS\" >.items {\r\n  background: #ddd;\r\n  padding: 15px 20px;\r\n  height: 100%;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Website designing has evolved considerably which enables us to create many new and innovative designs if done right. One of the website design trends is having equal heights of box in a row. When designing box view HTML, the same height box often requires the attention of web designers. Equal height columns with background box &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.virtueinfo.com\/blog\/css-tricks-how-to-get-equal-height-of-box-in-a-row\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;CSS Tricks &#8211; How to Get Equal height of box in a row&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":192,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-all"],"acf":{"short_description":"Website designing has evolved considerably which enables us to create many new and innovative designs if done right. One of the website design trends is having equal heights of box in a row.","section_heading_description":"","author_photo":{"ID":111,"id":111,"title":"Virtueinfo","filename":"logo-icon-512x512.jpg","filesize":26093,"url":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512.jpg","link":"https:\/\/www.virtueinfo.com\/blog\/virtueinfo-included-in-leading-development-research\/logo-icon-512x512-2\/","alt":"Virtueinfo","author":"1","description":"","caption":"Virtueinfo","name":"logo-icon-512x512-2","status":"inherit","uploaded_to":107,"date":"2018-10-11 13:48:29","modified":"2018-10-11 13:48:53","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/www.virtueinfo.com\/blog\/wp-includes\/images\/media\/default.png","width":512,"height":512,"sizes":{"thumbnail":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512-150x150.jpg","thumbnail-width":150,"thumbnail-height":150,"medium":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512-300x300.jpg","medium-width":300,"medium-height":300,"medium_large":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512.jpg","medium_large-width":512,"medium_large-height":512,"large":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512.jpg","large-width":512,"large-height":512,"1536x1536":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512.jpg","1536x1536-width":512,"1536x1536-height":512,"2048x2048":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512.jpg","2048x2048-width":512,"2048x2048-height":512,"twentyseventeen-featured-image":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512.jpg","twentyseventeen-featured-image-width":512,"twentyseventeen-featured-image-height":512,"twentyseventeen-thumbnail-avatar":"https:\/\/www.virtueinfo.com\/blog\/wp-content\/uploads\/2018\/10\/logo-icon-512x512-100x100.jpg","twentyseventeen-thumbnail-avatar-width":100,"twentyseventeen-thumbnail-avatar-height":100}}},"_links":{"self":[{"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/posts\/191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":2,"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":194,"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/posts\/191\/revisions\/194"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/media\/192"}],"wp:attachment":[{"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virtueinfo.com\/blog\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}