March 26, 201511 yr Does any one have any good explanations for creating responsive websites from scratch for beginners. I know about media queries. I am just confused with em's, rem's, % (mostly), etc. Can someone help me with the maths? I am trying to teach myself this and I just cannot get my head around what those do. Also if I did go into frameworks which is the easiest to pick up out of Bootstrap or Foundation?
March 26, 201511 yr % is self explanitory, 50% of something is half right? em and rem are based on font size, but the difference is that rem is based on the root font size while em is based on the parent's font size. I wrote a pretty bad article about this. http://cibgraphics.com/blog/working-with-rem-and-viewport-sized-typography I actually prefer to use rem over em because it is easier to work with. I also wrote a scss mixin to make it easier. $font-size: 14px; // What ever you want but this variable is required. @function strip-unit($num) { @return $num / ($num * 0 + 1); } @mixin rem-size($value, $property: font-size) { $pxValue: strip-unit($value); $baseValue: strip-unit($font-size); $remValue: ($pxValue / $baseValue); #{$property}: $value; #{$property}: $remValue + rem; } You use it like: (include is lowercase, the forum is messing it up) @[member="Include"] rem-size(14px); Edited March 27, 201511 yr by cibgraphics
March 26, 201511 yr Author Okay many thanks. I think I have the picture. Do you think I should look into either Bootstrap or Foundation for responsive design? If so which do you think is the easiest to use. Or do you think its best to create something from scratch?
March 26, 201511 yr I also love to work with rem. Em is very hard to work with because they are relative to all the parent elements as cibgraphics already has explained. But the real problem with ems is that they are not just relative to the first parent but to the entire hierarchy of ancestors. Example: You have an article inside a div element with a font-size of 0.5 em. It will be half the size specified for your html. Later on you decide to change the font-size of the parent div to 0.9 em. The text in your article is now half of 90% of the html specified size (rather confusing). So my advice is to stick to rem. they are always relative to the root size. A tip for responsive design is to set a px value for the html in every media query. If all your other elements values are in rem you only need to change this root value one place in every media query and all other elements will automatically adjust to the html elements value. Edited March 26, 201511 yr by Nillervision
March 27, 201511 yr In terms of using Bootstrap or Foundation. I opt for neither especially if you want to learn responsive design. These frameworks do most of the work for you, and if you want to learn how it works, don't have it do it for you so you understand how things are workings. You will be smarter for it, and will know how to troubleshoot issues down the road better. You also come off with a much lighter and cleaner CSS file in the end (because you don't have to overwrite stuff already written to theme your site). Bootstrap or Foundation are a bit bloated though they have trimmed down in size in recent years. The way that I work is using my Vanilla5 project (see link below) as a starter, and integrate NEAT (http://neat.bourbon.io/) for my grid system as well as other plugins for Grunt (http://gruntjs.com/) that help my workflow. Everyone has their own workflow and preferences, this is just mine. If you want to try them, go ahead and use Bootstrap and Foundation. See how you like them. I find them too much trouble for their worth, but thats just me. You may find it really helpful, but when you are learning, I suggest staying away from them so you get an idea how how responsive design works in its raw form. Thats my suggestion. Edited March 27, 201511 yr by cibgraphics
March 27, 201511 yr In terms of using Bootstrap or Foundation. I opt for neither especially if you want to learn responsive design. These frameworks do most of the work for you, and if you want to learn how it works, don't have it do it for you so you understand how things are workings. You will be smarter for it, and will know how to troubleshoot issues down the road better. You also come off with a much lighter and cleaner CSS file in the end (because you don't have to overwrite stuff already written to theme your site). Bootstrap or Foundation are a bit bloated though they have trimmed down in size in recent years. The way that I work is using my Vanilla5 project (see link below) as a starter, and integrate NEAT (http://neat.bourbon.io/) for my grid system as well as other plugins for Grunt (http://gruntjs.com/) that help my workflow. Everyone has their own workflow and preferences, this is just mine. If you want to try them, go ahead and use Bootstrap and Foundation. See how you like them. I find them too much trouble for their worth, but thats just me. You may find it really helpful, but when you are learning, I suggest staying away from them so you get an idea how how responsive design works in its raw form. Thats my suggestion. I agree with this. The big frameworks in my opinion make way too many design decisions for you. I prefer to just have a library of layout abstractions that I can then extend and style, that way each project looks unique, and you don't have to override styles like you would have to do with Bootstrap to make things Unique. I also agree that REM's are generally better to work with than EM's while EM's work find if you are careful where you use them, it's easy for a junior dev to change a unit higher up the tree and cause havoc with the descedant font-sizes. With REMs this issue is mitigated and just keeps things more simple. Simplicity is a good thing. Task runners like Grunt, I think are the best addition to our workflow since jQuery came along and gave us a sane, cross-browser API to access the DOM. I would find it very frustrating now to work without an automated task runner.
March 27, 201511 yr Author Many thanks for the comment! So I should make font size rem, size of div's px's and % for main content area such as wrapper, main content and aside?
March 27, 201511 yr There is no hard and fast rule for which units to use, it depends entirely on the context, some divs I set as percentages, some I leave to their default sizing (100%) some I set as pixels / REMs if I want a fixed width. I suggest you go and learn the CSS box model, positioning etc and then move into responsive design and responsive grid systems. Don't fall into the trap of using grid for all layout instances, a responsive grid wont work where you have say a small image of fixed dimensions on the left and text on the right taking up remaining space. I wrote a blog post about a css construct coined the flag object that does exactly that. I provide a load of examples of layouts using this abstraction and none of the dimensions are in % yet they're all fully responsive http://rbrtsmith.com/2015/02/developing-the-flag-object/ Same goes for fonts, usually I use REMs, occasionaly I use viewport units (vw) again, depends on the context. Ideally you should learn all the fundamentals of css layout before you tackle responsive design. Treehouse is a good place to learn these fundamentals. Edited March 27, 201511 yr by rbrtsmith
March 27, 201511 yr Author Thank you for you comments, I have started to have a play around. Is there a tutorial on making responsive nav menu like the BootStrap one? (I'm not using bootstrap framework)
March 27, 201511 yr I wrote a simple nav system that I beleive is more powerful that Bootsraps fixed-width breakpoint solution: I wrote about it here http://rbrtsmith.com/2014/12/handling-responsive-navigation/
March 27, 201511 yr Author Thank you http://codepen.io/anon/pen/OPqRmP Any idea why I cant get the NAVIGATION toggle working?
March 27, 201511 yr Author Oh yeah! woops Thanks Now trying to embed it to what I have so far.... bit tricky. Edited March 27, 201511 yr by Vulcan
Create an account or sign in to comment