-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.html
More file actions
executable file
·163 lines (136 loc) · 7.4 KB
/
notes.html
File metadata and controls
executable file
·163 lines (136 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Responsive Notes</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/vendor/modernizr-2.6.2.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
<div id="page-wrapper">
<header>
<div id="mobile-menu-trigger">Menu</div>
<h1 id="logo">Bōwst</h1>
<ul id="main-nav">
<li><a href="basics.html" target="_blank">The Basics</a></li>
<li><a href="notes.html" target="_blank">Techniques</a></li>
<li><a href="index.html" target="_blank">Example: Responsive Kittens</a></li>
</ul>
</header>
<div id="main">
<h1>Responsive Layout Techniques</h1>
<p>Below are some notes about specific techniques used in the <a href="index.html" target="_blank">Responsive Kittens</a> example.</p>
<h2>Percentage Widths & Box Sizing</h2>
<p>The easiest way to make a website "responsive" is to simply define all widths as percentages instead of fixed pixel sizes. This will allow content to naturally fill the width of the page, now matter what size the window is.</p>
<p>With the standard box-model, creating percentage width columns can be annoying. If you have 2 columns of 50% width then try to add padding to them, the overall width of each column will be 50% plus the padding instead of the width you want. Setting the box-sizing on all elements to "border-box" will solve this issue. <a href="http://paulirish.com/2012/box-sizing-border-box-ftw/" target="_blank">Paul Irish wrote an article about this technique.</a></p>
<pre class="prettyprint lang-css">
/* apply a natural box layout model to all elements */
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
</pre>
<h2>Media Queries</h2>
<p>CSS media queries can be used to define different styles based on window width.</p>
<p>The following example will display columns side-by-side on larger screens, but allow them to collapse into a single column on smaller screens.</p>
<pre class="prettyprint lang-css">
.columns {
@extend .clearfix;
.column1, .column2 {
float: left;
width: 49.9%; /* Less than 50%, because of IE bug. */
}
.column1 {
padding-right: 10px;
}
.column2 {
padding-left: 10px;
}
img {
max-width: 100%; /* Fit images to column width */
}
img.half {
max-width: 48%;
}
}
@media (max-width: 570px) {
.columns {
.column1, .column2 {
float: none;
width: 100%;
padding: 0;
}
}
}
</pre>
<h2>Responsive Height</h2>
<p>Sometimes it is necessary to set a fixed height on elements. For example, the jQuery Cycle plugin uses absolute positioning on slides within a slideshow, so the parent slide element must have a specific height to push down content below it. This can be problematic if you want the height to scale proportionally as the page gets narrower.</p>
<p>The following example applies a proportional height to the slideshow instead of a fixed height. The <code>!important</code> rule is used to override inline styles added by the plugin.</p>
<pre class="prettyprint lang-css">
.slideshow {
width: 100% !important;
height: 0 !important;
padding-bottom: 41.67%;
img {
width: 100% !important;
height: auto !important;
}
}
</pre>
<h2>Javascript Manipulation</h2>
<p>When styles are not enough to achieve the desired functionality differences between large and small displays, you can used javascript to detect the page width and make additional modifications.</p>
<p>The following example uses the "destroy" method of the jQuery Cycle plugin to disassemble the slideshow when the browser is resized to a smaller width.</p>
<pre class="prettyprint">
// Initialize slideshow, but not for mobile.
if ($(window).width() >= 570) {
$('.slideshow').cycle().addClass('enabled');
}
// Display slideshow as individual images on mobile.
$(window).resize(function () {
var siteWidth = $(window).width();
if (siteWidth < 570 && $('.slideshow').hasClass('enabled')) {
$('.slideshow').cycle('destroy')
.removeAttr('style')
.removeClass('enabled')
.find('img').removeAttr('style');
} else if (siteWidth >= 570 && ! $('.slideshow').hasClass('enabled')) {
$('.slideshow').cycle().addClass('enabled');
}
});
</pre>
<h2>Additional Resources</h2>
<ul>
<li>Core HTML from HTML5 Boilerplate. <a href="http://html5boilerplate.com/" target="_blank">http://html5boilerplate.com/</a></li>
<li>SASS <a href="http://sass-lang.com/" target="_blank">http://sass-lang.com/</a></li>
<li>Fonts from Google Web Fonts <a href="http://www.google.com/fonts/" target="_blank">http://www.google.com/fonts/</a></li>
<li>jQuery Cycle plugin for slideshow <a href="http://www.malsup.com/jquery/cycle/" target="_blank">http://www.malsup.com/jquery/cycle/</a></li>
<li>Placeholder cupcake text <a href="http://cupcakeipsum.com/" target="_blank">http://cupcakeipsum.com/</a></li>
<li>Placeholder kitten images <a href="http://placekitten.com/" target="_blank">http://placekitten.com/</a></li>
<li>Examples <a href="http://mediaqueri.es/" target="_blank">http://mediaqueri.es/</a></li>
</ul>
</div><!-- / #main -->
</div><!-- / #page-wrapper -->
<footer>
<p><a href="http://www.bowst.com/" target="_blank">Bōwst</a> | T: 603-766-8600 | [email protected]</p>
</footer>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.0.min.js"><\/script>')</script>
<script src="js/vendor/jquery.cycle.all.js"></script>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<script src="js/vendor/google-code-prettify/lang-css.js"></script>
<script src="js/main.js"></script>
</body>
</html>