{"id":3447,"date":"2012-12-18T15:51:45","date_gmt":"2012-12-18T12:51:45","guid":{"rendered":"http:\/\/railsware.com\/blog\/?p=3447"},"modified":"2021-08-16T15:33:22","modified_gmt":"2021-08-16T12:33:22","slug":"ui-library-layouts","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/ui-library-layouts\/","title":{"rendered":"UI Library: effective way to organize interface components. Layouts"},"content":{"rendered":"\n<p><a href=\"https:\/\/railsware.com\/blog\/ui-library\/\" target=\"_blank\" rel=\"noreferrer noopener\">UI Library: Preface<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/railsware.com\/blog\/ui-library-writing-css\/\" target=\"_blank\" rel=\"noreferrer noopener\">UI Library: Writing CSS<\/a><\/p>\n\n\n\n<p>We&#8217;re already familiar with Modules, but they don&#8217;t fit when dealing with\u00a0a\u00a0site\u00a0layout. When <a href=\"https:\/\/railsware.com\/blog\/ui-library-writing-css\/\" target=\"_blank\" rel=\"noreferrer noopener\">explaining Modules<\/a> we&#8217;ve learned to think component-based.<\/p>\n\n\n\n<p>Now, let&#8217;s add one&nbsp;more&nbsp;rule&nbsp;\u2014 Grids&nbsp;control&nbsp;width. It means that all Modules should be designed not to depend on width that gives more flexibility when placing them anywhere&nbsp;you&nbsp;need.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a grid<\/h2>\n\n\n\n<p>Let&#8217;s take a closer look at a primitive layout example we&nbsp;see&nbsp;every&nbsp;day:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/\/railsware.com\/blog\/wp-content\/uploads\/2012\/11\/default-layout2.png\" alt=\"Complicated user profile layout\"\/><\/figure>\n\n\n\n<p>The Grid classes should be made&nbsp;location-free. Note a block with the class <code>row<\/code> that clears all the&nbsp;floats&nbsp;properly. Don&#8217;t forget about&nbsp;it.<\/p>\n\n\n\n<div class=\"mbm\">\n<div class=\"row\">\n<p>&nbsp;<\/p>\n<div class=\"col1of3\">Navigation<\/div>\n<p>&nbsp;<\/p>\n<div class=\"col2of3\">Content<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n\n\n\n<div class=\"mbm\">\n<pre lang=\"css\">\/* The clearfix hack is a popular way to contain floats without resorting \n * to using presentational markup.\n * Credits: http:\/\/nicolasgallagher.com\/micro-clearfix-hack *\/\n.row {\n  *zoom: 1;\n}\n\n.row:before,\n.row:after {\n  display: table;\n  content: \"\";\n  line-height: 0;\n}\n\n.row:after {\n  clear: both;\n}\n\n\/* Reserved classes for columns *\/\n.col1of3, .col2of3 {\n  float: left;\n}\n\n.col1of3 {\n  width: 33.33333%;\n}\n\n.col2of3 {\n  width: 66.66666%;\n}\n<\/pre>\n<\/div>\n\n\n\n<p>We&#8217;ve reserved some unique classes for the columns: <code>.col1of3<\/code>, <code>.col2of3<\/code>. All of them have <em>float: left<\/em> to behave like floats and <em>width: xx%<\/em> where <em>xx<\/em> is a percentage value from&nbsp;0&nbsp;to&nbsp;100.<\/p>\n\n\n\n<p>We&#8217;ve also reserved <code>.row<\/code>(clearfix hack) which is a popular way to contain floats without resorting to using presentational&nbsp;markup.<\/p>\n\n\n\n<p>After inserting some test data inside, let&#8217;s take a look at\u00a0the\u00a0<a href=\"http:\/\/jsfiddle.net\/iurevych\/ykrnF\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">result<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Organizing more complex grids<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/\/railsware.com\/blog\/wp-content\/uploads\/2012\/11\/user-profile-layout.png\" alt=\"Default site layout in 2 columns\"\/><\/figure>\n\n\n\n<p>Using grids with percentage width allows us to build quite complex\u00a0layout.<br>Don&#8217;t forget to wrap columns with\u00a0<code>.row<\/code>.<br><a href=\"http:\/\/jsfiddle.net\/iurevych\/ykrnF\/2\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Let&#8217;s take a\u00a0look<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Spaces<\/h2>\n\n\n\n<p>Now we know how to create fluid layouts, but usually you need to add some space between columns or blocks inside&nbsp;each&nbsp;column. Use spaces for&nbsp;that.<\/p>\n\n\n\n<div class=\"mbm\">\n<div class=\"mbl\">Block with margin-bottom of the large size.<\/div>\n<\/div>\n\n\n\n<div class=\"mbm\">\n<pre lang=\"css\">\/* Should be used to modify the default spacing between objects \n(not between nodes of the same object)\n * a, t, r, b, l, h, v = all, top, right, bottom, left, horizontal, vertical\n * x, s, m, l, n       = 3px, 5px, 10px, 20px, none\n * p, m                = padding, margin *\/\n\n.mbl {\n  margin-bottom: 20px;\n}\n<\/pre>\n<\/div>\n\n\n\n<p><a href=\"http:\/\/jsfiddle.net\/iurevych\/ykrnF\/3\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Here&#8217;s an example<\/a>.<\/p>\n\n\n\n<p>As you can see in the comment line above, we can define paddings\/margins for&nbsp;each&nbsp;side. Also, we can set&nbsp;the&nbsp;size. Let&#8217;s see how&nbsp;it&#8217;s&nbsp;made:<\/p>\n\n\n\n<div class=\"mbm\">\n<pre lang=\"css\">\/* Large Padding size for all sides *\/\n.ptl, .pvl, .pal { padding-top:    20px; }\n.prl, .phl, .pal { padding-right:  20px; }\n.pbl, .pvl, .pal { padding-bottom: 20px; }\n.pll, .phl, .pal { padding-left:   20px; }\n\n\/* Large Margin size for all sides *\/\n.mtl, .mvl, .mal { margin-top:    20px; }\n.mrl, .mhl, .mal { margin-right:  20px; }\n.mbl, .mvl, .mal { margin-bottom: 20px; }\n.mll, .mhl, .mal { margin-left:   20px; }\n<\/pre>\n<\/div>\n\n\n\n<p>Take a look at the <a href=\"https:\/\/github.com\/railsware\/scaffy.railsware.com\/blob\/master\/sass\/scaffy\/_spaces.sass\" target=\"_blank\" rel=\"noreferrer noopener\">Sass based version<\/a> with 4\u00a0different\u00a0sizes.<\/p>\n\n\n\n<p>Use spaces to modify default spacing between objects (not between nodes of&nbsp;the&nbsp;same&nbsp;object).<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>TIP: <a href=\"https:\/\/railsware.com\" target=\"_blank\" rel=\"noreferrer noopener\">Railsware site<\/a> is based on a such grids\u00a0+\u00a0spaces\u00a0system. Feel free to go and inspect the source and learn how we\u00a0built\u00a0it.<\/p><\/blockquote>\n\n\n\n<p>We&#8217;re not going to cover responsive layouts here since it&#8217;s worth writing additional post&nbsp;about&nbsp;it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UI Library: Preface UI Library: Writing CSS We&#8217;re already familiar with Modules, but they don&#8217;t fit when dealing with\u00a0a\u00a0site\u00a0layout. When explaining Modules we&#8217;ve learned to think component-based. Now, let&#8217;s add one&nbsp;more&nbsp;rule&nbsp;\u2014 Grids&nbsp;control&nbsp;width. It means that all Modules should be designed not to depend on width that gives more flexibility when placing them anywhere&nbsp;you&nbsp;need. Creating a&#8230;<\/p>\n","protected":false},"author":29,"featured_media":3448,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[],"coauthors":["Sergii Iurevych"],"class_list":["post-3447","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"aioseo_notices":[],"categories_data":[{"name":"Engineering","link":"https:\/\/railsware.com\/blog?category=development"}],"post_thumbnails":"\/\/railsware.com\/blog\/wp-content\/uploads\/2012\/11\/default-layout2.png","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/3447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=3447"}],"version-history":[{"count":98,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/3447\/revisions"}],"predecessor-version":[{"id":14138,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/3447\/revisions\/14138"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/3448"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=3447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=3447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=3447"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=3447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}