08-20-responsive-news-srcset-x.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Responsive news section example with srcset and x descriptor</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/600x300.png" srcset="img/1200x600.png 1.5x" alt="Dummy image">
  182. <h3><a href="#">Cras suscipit nec leo id.</a></h3>
  183. <p>Autem repudiandae aliquid tempora quos reprehenderit architecto, sequi repellat.</p>
  184. </article>
  185. </div>
  186. <div class="col">
  187. <article class="story">
  188. <img src="img/300x150.png" srcset="img/600x300.png 1.5x" alt="Dummy image">
  189. <h3><a href="#">Perferendis, ipsam!</a></h3>
  190. <p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
  191. </article>
  192. </div>
  193. <div class="col">
  194. <article class="story">
  195. <img src="img/300x150.png" srcset="img/600x300.png 1.5x" alt="Dummy image">
  196. <h3><a href="#">Curabitur mattis purus nec velit.</a></h3>
  197. <p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
  198. </article>
  199. </div>
  200. </div>
  201. <ul class="row row-quartet row-wrapping">
  202. <li class="col">
  203. <div class="story">
  204. <h3><a href="#">Perferendis, ipsam! Dolor sit amet consectetur</a></h3>
  205. </div>
  206. </li>
  207. <li class="col">
  208. <div class="story">
  209. <h3><a href="#">Aliquam mattis eros id posuere.</a></h3>
  210. </div>
  211. </li>
  212. <li class="col">
  213. <div class="story">
  214. <h3><a href="#">Proin leo felis, semper nec</a></h3>
  215. </div>
  216. </li>
  217. <li class="col">
  218. <div class="story">
  219. <h3><a href="#">Aliquam vitae risus tortor. Sed!</a></h3>
  220. </div>
  221. </li>
  222. <li class="col">
  223. <div class="story">
  224. <h3><a href="#">Perferendis, ipsam!</a></h3>
  225. </div>
  226. </li>
  227. <li class="col">
  228. <div class="story">
  229. <h3><a href="#">Aliquam mattis eros id posuere.</a></h3>
  230. </div>
  231. </li>
  232. <li class="col">
  233. <div class="story">
  234. <h3><a href="#">Proin leo felis, semper nec</a></h3>
  235. </div>
  236. </li>
  237. <li class="col">
  238. <div class="story">
  239. <h3><a href="#">Aliquam vitae risus tortor. Sed!</a></h3>
  240. </div>
  241. </li>
  242. </ul>
  243. </div>
  244. </div>
  245. </section>
  246. </main>
  247. </body>
  248. </html>