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
- R1: 0, 0, 3
- R2: 0, 2, 0
- R3: 0, 0, 2
- R4: 0, 1, 3
- R5: 1, 2, 1
- R6: 0, 1, 1
3.2 Rules
What rules apply to each of the elements:
- section with id foo: none
- ul with class bar: none
- each one of the four list items: (R1, R6), (R1, R2, R4, R6), (R1, R4, R6), (R1, R4, R6)
- each one of the four links: (R3, R5), (R3, R5), (R3, R5), (R3, R5)
3.3 Selected Rule
What is the rule with the highest specificity for each element:
- section with id foo: none
- ul with class bar: none
- each one of the four list items: R6, R2, R4, R4
- each one of the four links: R5, R5, R5, R5
3.4 Color Value
What is the color value (including inherit) assigned to each element:
- section with id foo: inherit
- ul with class bar: inherit
- each one of the four list items: magenta, red, yellow, yellow
- each one of the four links: inherit, inherit, inherit, inherit
3.5 Final Color
What is the final color value presented in the browser:
- first link: magenta
- second link: red
- third link: yellow
- fourth link: yellow
4. Form
4.1 Main Design
@import url('https://fonts.googleapis.com/css2?family=Martel+Sans:wght@400;700&display=swap');
form {
display: grid;
font-family: 'Martel Sans', sans-serif;
grid-template-columns: repeat(3, auto);
grid-template-rows: repeat(4, auto) 10em auto;
gap: 1em;
width: 50em;
margin: 1em auto;
--label-optional: #333;
--label-required: #DC2626;
--field-color: #ECFCCB;
--field-focus: #D9F99D;
--field-border: #84CC16;
--error-color: #FECACA;
--error-border: #F87171;
--button-bgcolor: #84CC16;
}
label {
display: grid;
grid-template-rows: auto 1fr;
font-size: 0.8em;
line-height: 1em;
font-weight: bold;
}
#fname { grid-column: 1; grid-row: 1; }
#lname { grid-column: 2; grid-row: 1; }
#username { grid-column: 3; grid-row: 1; }
#email { grid-column: 1 / span 2; grid-row: 2; }
#address { grid-column: 1 / span 3; grid-row: 3; }
#bio { grid-column: 1 / span 3; grid-row: 5; }
#register { grid-column: 3; }
label {
color: var(--label-optional);
}
label.required {
color: var(--label-required);
}
button, input, select, textarea {
padding: 1em;
border-radius: 4px;
border: 1px solid var(--field-border);
background-color: var(--field-color);
}
button {
padding: 1em;
background-color: var(--button-bgcolor);
color: #fff;
font-weight: bold;
font-family: 'Martel Sans', sans-serif;
}
input:invalid, select:invalid, textarea:invalid {
background-color: var(--error-color);
border: 1px solid var(--error-border);
}
input:focus, select:focus, textarea:focus {
background-color: var(--field-focus);
border: 1px solid var(--field-border);
outline: none;
}
4.2 Responsive Design
Note: 50em
is the form's width in the main design; adding 2em
for the margin
, we get 52em
.
@media (max-width: 52em) {
form {
margin: 1em;
width: auto;
grid-template-columns: auto;
grid-template-rows: repeat(9, auto) 10em auto;
}
#fname { grid-column: 1; grid-row: 1; }
#lname { grid-column: 1; grid-row: 2; }
#username { grid-column: 1; grid-row: 3; }
#email { grid-column: 1; grid-row: 4; }
#email { grid-column: 1; grid-row: 5; }
#address { grid-column: 1; grid-row: 6; }
#bio { grid-column: 1; grid-row: 10; }
#register { grid-column: 1; }
}