08-XX-responsive-news-srcset.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Responsive news section with srcset attribute examples</title>
  6. <!-- the base styles and "housekeeping" styles are in here: -->
  7. <link rel="stylesheet" href="css/grid-base.css">
  8. <!-- Modernizr script to detect flexbox support,
  9. which also includes HTML5 shiv,
  10. to help older browsers understand styling
  11. on newer HTML5 elements: -->
  12. <script src="js/modernizr.min.js"></script>
  13. <!-- Meta viewport tag to enable correct viewport on mobile devices -->
  14. <meta name="viewport" content="width=device-width,initial-scale=1">
  15. <style>
  16. /* Wrapper styling with fallback: */
  17. .wrapper {
  18. max-width: 40em;
  19. width: 95%;
  20. margin: 0 auto;
  21. }
  22. @media only all {
  23. .wrapper {
  24. max-width: 76em;
  25. }
  26. }
  27. /* grid styling */
  28. /**
  29. * [1] Remove list-style and default padding, in case any
  30. * columns are actually <li> items.
  31. * [2] Negative margin equal to 1/2 gutter width.
  32. */
  33. .row {
  34. list-style: none; /* [1] */
  35. padding: 0; /* [1] */
  36. margin: 0 -.6875em; /* [2] */
  37. }
  38. /**
  39. * Make sure rows contain floats.
  40. */
  41. .row:after {
  42. content: '';
  43. display: block;
  44. clear: both;
  45. }
  46. /**
  47. * [1] Set font-size to 0 to counteract the white-space issue with
  48. * inline-block children.
  49. * [2] Set the negative margin in px as a "good-enough" fallback for IE8 (see 3)
  50. * [3] Set the negative margin in rems instead of ems as the font-size is 0.
  51. */
  52. .row-wrapping {
  53. font-size: 0; /* [1] */
  54. margin: 0 -11px; /* [2] */
  55. margin: 0 -.6875rem; /* [3] */
  56. }
  57. /**
  58. * Children of wrapping rows are inline blocks.
  59. * [1] Set the font-size in as a fallback for browsers without rem support
  60. * e.g. IE8. (see 2)
  61. * [2] Set the font size using rems since font-size on parent is 0.
  62. */
  63. .row-wrapping > .col {
  64. float: none;
  65. vertical-align: top;
  66. display: inline-block;
  67. font-size: 16px;
  68. font-size: 1rem;
  69. }
  70. /**
  71. * [1] Set columns to float/100% width by default, despite not needing to for
  72. * for single-column layouts. That way, we don't need to decide at which
  73. * breakpoint the column starts floating.
  74. */
  75. .col {
  76. -moz-box-sizing: border-box;
  77. box-sizing: border-box;
  78. padding: 0 .6875em 1.375em;
  79. float: left; /* [1] */
  80. width: 100%; /* [1] */
  81. }
  82. /**
  83. * If flexbox wrapping is supported, it will be automatically taken care of
  84. * at the various breakpoints.
  85. */
  86. .flexwrap .row {
  87. display: -webkit-flex;
  88. display: -ms-flexbox;
  89. display: flex;
  90. -webkit-flex-wrap: wrap;
  91. -ms-flex-wrap: wrap;
  92. flex-wrap: wrap;
  93. }
  94. /**
  95. * Set columns as flexbox column containers, to enable equal height columns
  96. * on wider screens later, if wrapping is supported.
  97. */
  98. .flexwrap .col {
  99. display: -webkit-flex;
  100. display: -ms-flexbox;
  101. display: flex;
  102. -webkit-flex-direction: column;
  103. -ms-flex-direction: column;
  104. flex-direction: column;
  105. }
  106. .flexwrap .col > * {
  107. -webkit-flex: 1;
  108. -ms-flex: 1 0 auto;
  109. flex: 1;
  110. }
  111. @media only screen and (min-width: 35em) {
  112. .row-quartet > * {
  113. width: 50%;
  114. }
  115. .subcategory-featured {
  116. width: 100%;
  117. }
  118. }
  119. @media only screen and (min-width: 50em) {
  120. .row-quartet > * {
  121. width: 25%;
  122. }
  123. .subcategory-featured {
  124. width: 50%;
  125. }
  126. }
  127. @media only screen and (min-width: 70em) {
  128. .subcategory-header {
  129. width: 20%;
  130. }
  131. .subcategory-content {
  132. width: 80%;
  133. }
  134. }
  135. .col:last-child {
  136. float: right;
  137. }
  138. /* content styling */
  139. .subcategory {
  140. margin-top: 1.5em;
  141. border-bottom: 1px solid #8e3339;
  142. }
  143. .story {
  144. padding: .6875em;
  145. background-color: #eee;
  146. }
  147. .story + .story {
  148. margin-top: 1.375em;
  149. }
  150. .story img {
  151. width: 100%;
  152. }
  153. </style>
  154. </head>
  155. <body>
  156. <header class="masthead">
  157. <div class="wrapper">
  158. <h1>Important News</h1>
  159. </div>
  160. </header>
  161. <nav role="navigation" class="navbar">
  162. <div class="wrapper">
  163. <ul class="navlist">
  164. <li><a href="#">Home</a></li>
  165. <li><a href="#">World</a></li>
  166. <li><a href="#">Local</a></li>
  167. <li><a href="#">Sports</a></li>
  168. </ul>
  169. </div>
  170. </nav>
  171. <main class="wrapper">
  172. <section class="subcategory">
  173. <div class="row">
  174. <header class="col subcategory-header">
  175. <h2>Lorem ipsum</h2>
  176. </header>
  177. <div class="col subcategory-content">
  178. <div class="row row-quartet">
  179. <div class="col subcategory-featured">
  180. <article class="story">
  181. <img src="img/300x150.png"
  182. srcset="img/300x150.png 300w,
  183. img/400x200.png 400w,
  184. img/600x300.png 600w,
  185. img/800x400.png 800w,
  186. img/1200x600.png 1200w"
  187. sizes="(min-width: 70em) 28em,
  188. (min-width: 50em) calc(50vw * 0.95 - 2.75em),
  189. calc(95vw - 1.375em)"
  190. alt="Dummy image">
  191. <h3><a href="#">Cras suscipit nec leo id.</a></h3>
  192. <p>Autem repudiandae aliquid tempora quos reprehenderit architecto, sequi repellat.</p>
  193. </article>
  194. </div>
  195. <div class="col">
  196. <article class="story">
  197. <img src="img/300x150.png"
  198. srcset="img/300x150.png 300w,
  199. img/400x200.png 400w,
  200. img/600x300.png 600w,
  201. img/800x400.png 800w,
  202. img/1200x600.png 1200w"
  203. sizes="(min-width: 70em) 12.6875em,
  204. (min-width: 50em) calc(25vw * 0.95 - 2.75em),
  205. (min-width: 35em) calc(95vw / 2 - 4.125em),
  206. calc(95vw - 1.375em)"
  207. alt="Dummy image">
  208. <h3><a href="#">Perferendis, ipsam!</a></h3>
  209. <p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
  210. </article>
  211. </div>
  212. <div class="col">
  213. <article class="story">
  214. <img src="img/300x150.png"
  215. srcset="img/300x150.png 300w,
  216. img/400x200.png 400w,
  217. img/600x300.png 600w,
  218. img/800x400.png 800w,
  219. img/1200x600.png 1200w"
  220. sizes="(min-width: 70em) 12.6875em,
  221. (min-width: 50em) calc(25vw * 0.95 - 2.75em),
  222. (min-width: 35em) calc(95vw / 2 - 4.125em),
  223. calc(95vw - 1.375em)"
  224. alt="Dummy image">
  225. <h3><a href="#">Curabitur mattis purus nec velit.</a></h3>
  226. <p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
  227. </article>
  228. </div>
  229. </div>
  230. <ul class="row row-quartet row-wrapping">
  231. <li class="col">
  232. <div class="story">
  233. <h3><a href="#">Perferendis, ipsam! Dolor sit amet consectetur</a></h3>
  234. </div>
  235. </li>
  236. <li class="col">
  237. <div class="story">
  238. <h3><a href="#">Aliquam mattis eros id posuere.</a></h3>
  239. </div>
  240. </li>
  241. <li class="col">
  242. <div class="story">
  243. <h3><a href="#">Proin leo felis, semper nec</a></h3>
  244. </div>
  245. </li>
  246. <li class="col">
  247. <div class="story">
  248. <h3><a href="#">Aliquam vitae risus tortor. Sed!</a></h3>
  249. </div>
  250. </li>
  251. <li class="col">
  252. <div class="story">
  253. <h3><a href="#">Perferendis, ipsam!</a></h3>
  254. </div>
  255. </li>
  256. <li class="col">
  257. <div class="story">
  258. <h3><a href="#">Aliquam mattis eros id posuere.</a></h3>
  259. </div>
  260. </li>
  261. <li class="col">
  262. <div class="story">
  263. <h3><a href="#">Proin leo felis, semper nec</a></h3>
  264. </div>
  265. </li>
  266. <li class="col">
  267. <div class="story">
  268. <h3><a href="#">Aliquam vitae risus tortor. Sed!</a></h3>
  269. </div>
  270. </li>
  271. </ul>
  272. </div>
  273. </div>
  274. </section>
  275. </main>
  276. </body>
  277. </html>