André Restivo

CSS Solutions

1. Online Newspaper Design

You can also download the complete solution.

1.1 Main Style

/* header */

body > header {
  background-color: #046dd5;
  color: white;

  padding: 1em;
}

body > header h1, body > header h2{
  margin: 0;
}

body > header a {
  color: white;
  text-decoration: none;  
}

body > header #signup a:first-child {
  border-right: 1px solid white;
}

body > header #signup {
  margin-top: 1em;
}

body > header #signup a {
  padding: 0 1em;
}

body > header #signup a:first-child {
  padding-left: 0;
}

/* navigation */

#menu ul {
  margin: 0;
  padding: 0;
}

#menu li {
  background-color: white;
  text-align: center;

  list-style-type: none;

  padding: 1em 0;
}

#menu li a{
  color: black;
  text-decoration: none;
}

#menu li:hover {
  background-color: #2a2f33;
}

#menu li:hover a{
  color: white;
}

#hamburger, .hamburger {
  display: none;
}

/* article */

#news header {
  max-width: 10em;
  padding: 1em;
  position: absolute;
}

#news header h1{
  margin: 0;

  text-shadow: .2em .2em .2em black;
}

#news header a{
  color: white;
  text-decoration: none;
}

#news img {
  width: 100%;
}

#news > article {
  background-color: white;

  margin: 1em 0;
}

#news > article > p{
  padding: 0 1em;
}

#news > article > p:first-of-type:first-letter{
  font-size: 2em;
}

#news footer {
  color: white;
  background-color: #f4655f;

  padding: 1em;
}

#news footer a{
  color: white;
  text-decoration: none;
  border-bottom: 1px solid white;
  padding-bottom: 2px;
}

#news footer .tags {
  margin-right: 1em;
}

#news footer .comments {
  margin-left: 1em;
}

#news footer .comments:after {
  content: ' comments';
}

#news footer .author:before{
  content: "By ";
}

/* related */

#related {
  background-color: #2a2f33;

  padding: 1em;
}

#related h1 a {
  color: white;
  text-decoration: none;
}

#related p {
  color: white;
}

/* footer */

body > footer {
  background-color: #2a2f33;
  color: white;

  padding: 1em;

  height: 1em;
}

body > footer p {
  margin: 0;
}

/* fonts */ 

@import url('https://fonts.googleapis.com/css?family=Lora:400,700|Poppins:400,700');

body {
  font-family: "Poppins", sans-serif;
}

p {
  font-family: "Lora", serif;
  line-height: 1.4em;
}

body > header h2 {
  font-weight: normal;
}

#news header {
  font-size: 1.5em;
}

#news footer {
  font-size: 0.8em;
}

/* section colors */

#menu li:nth-child(1) {
  border-top: 5px solid #e1493e;
}

#menu li:nth-child(2) {
  border-top: 5px solid #8aba56;
}

#menu li:nth-child(3) {
  border-top: 5px solid #5b4282;
}

#menu li:nth-child(4) {
  border-top: 5px solid #ff8932;
}

#menu li:nth-child(5) {
  border-top: 5px solid #19b6e9;
}

#menu li:nth-child(6) {
  border-top: 5px solid #e84c8b;
}

1.2 Positioning

/* main layout */

body {
  background-color: #edeff0;

  margin: 0 auto;
  width: 60em;

  display: grid;
  grid-template-columns: [start] 4fr [middle] 1fr [end];
  grid-template-rows: [start] auto [nav] auto [news] 1fr [footer] auto [end];
}

body > header {
  grid-column: start / end;
}

#menu {
  grid-column: start;
}

aside {
  grid-column: middle;
  grid-row: nav / end;
}

#news {
  grid-column: start;
}

body > footer {
  align-self: end;
}

/* header layout */

body > header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
}

body > header h1 {
  grid-column: 1;
  grid-row: 1;
}

body > header h2 {
  grid-column: 1;
  grid-row: 2;
}

body > header #signup {
  grid-column: 2;
  grid-row: 2;
}

/* navigation layout */

#menu ul {
  display: flex;
  flex-direction: row;
}

#menu li {
  display: block;
  flex: 1;
}

/* article footer layout */

#news footer {
  display: flex;
}

#news footer .author {
  flex-grow: 1;
}

1.3 Responsive Design

/* responsive */

@media (max-width: 60em) {
  body{ 
    width: 100%;
    grid-template-columns: [start] 4fr [end];
    grid-template-rows: [start] auto [nav] auto [news] auto [footer] auto [end];
  }

  #news article {
    margin: 0 0 1em;
  }

  #related {
    display: none;  
  }

  body > footer {
    margin: 0;  
  }
}

@media (max-width: 30em) {
  body > header {
    display: block;
  }

  body > header h1 {
    font-size: 1.5em;  
  } 

  body > header h2 {
    display: none;
  }

  #menu .hamburger {
    display: block;
    background-color: #2a2f33;
    color: white;
    padding: 1em;
  }

  #menu .hamburger:before {
    content:'\2630';
  }

  #menu ul {
    flex-direction: column;
    margin: 0;
    padding: 0;
    color: white;
  }

  #hamburger:checked + .hamburger + ul li{
    max-height: 1em;
    padding: 1em;
    opacity: 1;
  }

  #hamburger:checked + .hamburger:before {
    content:'\2715';
  }

  #menu li {
    max-height: 0;
    padding: 0 1em;
    background-color: #edeff0;
    text-align: left;
    opacity: 0;
    transition: all .3s ease-in-out;
  }
  
  #menu li:nth-child(1) {
    border-top: none;
    border-left: 5px solid #e1493e;
  }

  #menu li:nth-child(2) {
    border-top: none;
    border-left: 5px solid #8aba56;
  }

  #menu li:nth-child(3) {
    border-top: none;
    border-left: 5px solid #5b4282;
  }

  #menu li:nth-child(4) {
    border-top: none;
    border-left: 5px solid #ff8932;
  }

  #menu li:nth-child(5) {
    border-top: none;
    border-left: 5px solid #19b6e9;
  }

  #menu li:nth-child(6) {
    border-top: none;
    border-left: 5px solid #e84c8b;
  }

  #news .tags {
    display: none;  
  }

  #news header {
    color: black;
    max-width: 100%;
    font-size: 1em;
    padding: 1em;
    position: static;
  }

  #news header h1 {
    text-shadow: none;
  }

  #news header a{
    color: black;
  }
}

1.4 Comments Design

#comments {
  margin: 1em;
}


#comments .user {
  font-style: italic;
}

#comments .user:after {
  font-style: normal;
  content: ' said:';
}

#comments .date {
  float: right;
}

#comments p {
  background-color: #edeff0;
  padding: 1em;
}

#comments p:before {
  content: '\201C';
  font-size: 3em;
  position: relative;
  top: 15px;
  color: #ccc;
}

#comments form {
  display: grid;

  padding: 1em;
  gap: 1em;

  grid-template-columns: 1fr 1fr 1fr 1fr;

  background-color: #edeff0;
}

#comments form h2 {
  font-size: 1em;
  grid-column-end: span 4;
}

#comments form input {
  background-color: white;
  height: 2em;
}

#comments form textarea {
  display: block;
  width: 100%;

  margin: 0 auto;
  padding: 0;

  height: 6em;
}

#comments form label {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-column-end: span 2;
  gap: 1em;
  align-items: center;
}

#comments form label:last-of-type {
  grid-column-end: span 4;
  grid-template-columns: auto 1fr;
}

#comments form button {
  width: auto;

  grid-column-start: 4;

  background-color: black;
  color: white;

  border: none;
  padding: 1em;
}

1.5 Register Design

#register form {
  background-color: white;
  color: black;
  margin: 2em auto;
  width: 20em;
  padding: 1em;
}

#register label {
  padding: 1em;
}

#register label, #register input {
  display: block;
}

#register input {
  border: none;
  background-color: white;
  color: black;
  border-bottom: 1px solid black;
  margin-top: 1em;
  width: 100%;
  font-size: 0.9em;
}

#register button {
  width: auto;

  background-color: black;
  color: white;

  border: none;
  margin: 1em;
  padding: 1em;
}

#register input:focus {
  outline: none;
  border-bottom: 1px solid #046dd5;
}

#register h1, #login h1 {
  text-align: center;
}

@media (max-width: 30em) {
  #register, #login {
    background-color: white;
  }
}

2. No Flexbox/Grid Design

You can also download the complete solution.

Style 1

main {
  width: 38em;
  border-right: 22em solid #f9c74f;
}

body > aside {
  float: right;
  width: 20em;
}

Style 2

main {
  width: 38em;
  border-right: 22em solid #f9c74f;
}

body > aside {
  float: right;
  width: 20em;
}

main > section article {
  width: 8em;
  float: left;
}

main > section::after {
  content: "\00a0";
  clear:both;
  display: block;
  height: 0;
}

Style 3

body > header {
  position: absolute;
  float: left;
  width: 38em;
  height: 2em;
}

body > nav {
  position: absolute;
  width: 38em;
  height: 2em;
  margin-top: 4em;
}

body > aside {
  float: right;
  width: 18em;
  height: 6em;
}

main {
  position: absolute;
  margin-top: 13em;
  width: 60em;
}

body {
  height: 100%;
}

body > footer {
  position: absolute;
  margin-top: 8em;
  width: 58em;
}

Style 4

body {
  position: relative;
}

main {
  position: relative;
  width: 38em;
}

main #s1 {
  width: 18em;
  position: absolute;
  top: 0; left: 0;
}

main #s2 {
  width: 18em;
  position: absolute;
  top: 0; right: 0;
}

body > aside {
  width: 20em;
  position: absolute;
  right: 0;
  height: 6em;
}

body > footer {
  width: 20em;
  position: absolute;
  right: 0;
  margin-top: 8em;
}

3. Cascading

3.1 Specificity

3.2 Rules

What rules apply to each of the elements:

  1. section with id foo: none
  2. ul with class bar: none
  3. first list item: R1, R6
  4. second list item: R1, R2, R4, R6
  5. third list item: R1, R4, R6
  6. fourth list item: R1, R4, R6
  7. first link: R3, R5
  8. second link: R3, R5
  9. third link: R3, R5
  10. fourth link: R3, R5

3.3 Selected Rule

What is the rule with the highest specificity for each element:

  1. section with id foo: none
  2. ul with class bar: none
  3. first list item: R6
  4. second list item: R2
  5. third list item: R4
  6. fourth list item: R4
  7. first link: R5
  8. second link: R5
  9. third link: R5
  10. fourth link: R5

3.4 Color Value

What is the color value (including inherit) assigned to each element:

  1. section with id foo: inherit
  2. ul with class bar: inherit
  3. first list item: magenta
  4. second list item: red
  5. third list item: yellow
  6. fourth list item: yellow
  7. first link: inherit
  8. second link: inherit
  9. third link: inherit
  10. fourth link: inherit

3.5 Final Color

What is the final color value presented in the browser:

  1. section with id foo: black
  2. ul with class bar: black
  3. first list item: magenta
  4. second list item: red
  5. third list item: yellow
  6. fourth list item: yellow