08-XX-responsive-news-picture.html 9.0 KB

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