CSS Flashcards
Remove underline from links
text-decoration: none;
style selected link and hover
nav a.selected, nav a:hover {
color: #32673f;
}
Google fonts
google.com/fonts
remove bullet points from lists
list-style: none;
clear floats in the footer
footer {
clear: both;
}
display navigation links as an inline block
nav li {
display: inline-block;
}
add a phone link
<a> 567 - 3455</a>
</a>
add a background img next to the phone link
.contact-info li.phone a {
background-image: url(‘../img/phone.png’);
}
change background-repeat to none
background-repeat: no-repeat;
shorthand for commenting something out
CMD + SHIFT + /
clear left float from every 4th img
#gallery li:nth-child(4n) { clear: left; }
import an external CSS file
@import “import-styles.css“; (at the beginning of the css file)
how to convert px to em
divide width in px by 16
style links on hover with rgba color property
a: hover {
color: rgba (255, 169, 73, .4)
}
change text to uppercase
text-transform: uppercase;
lowercase
capitalise;
underline h2
h2 {
text-decoration: underline;
}
change vertical spacing between lines of text
body {
line-height: 1.5;
}
add a solid blue border 10px wide
border: 10px solid blue;
center a div
margin: 0 auto;
universal selector
{ * }
selector for a visited link
a:visited
white color
fff
black color
000
change color with rgba
40% transparency
color: rgba (255, 170, 65, .4);
capitalize all paragraphs
p {
text-transform: capitalize;
}
change h1 to uppercase
h1 {
text-transform: uppercase;
}
change vertical spacing between rows of text
body {
line-height: 1.5;
}
specify that a <div>’s padding and borders are included in the total width and height of the element</div>
div {
box-sizing: border-box;
}
repeat a background-image horizontally inside .main-header
.main-header {
background-repeat: repeat-x;
}
make a background image 40% of the .main-header
.main-header {
background-size: 40%;
}
change the position of the background image inside the .main-header to center bottom;
.main-header {
background-position: center bottom;
}
move the background image 20% to the left and 40% down inside the .main-header
.main-header {
background-position: 20% 40%;
}
float two columns (primary col, secondary col)
.col {
width: 46.5%;
}
.primary {
float: left;
}
secondary {
float: right;
}
clearfix .group (parent element)
.group::after { content: ""; display: table; clear: both; }
remove list indentation inside a ul
ul {
padding-left: 0;
}
move bullet points inside the li element
ul {
list-style-position: inside;
}
change bullet points to squares
ul {
list-style-type: square;
}
add 10px vertical space between li items
ul {
margin: 10px;
}
apply a text shadow to h1 (blur radius 12px, color green, 10px horizontal and 15px vertical offset)
h1 {
text-shadow: 10px 15px 12px green;
}
move the text shadow to the left inside h1
h1 {
text-shadow: -10px -15px 12px green;
}
create an inner shadow effect inside .wildlife
.wildlife {
box-shadow: inset 0 0 50px 10px rgba (0, 0, 0, 1);
}
create a smooth fade from red to orange inside the .main-header
.main-header {
background-image: linear gradient(red, orange);
use transparent gradient with multiple backgrounds
.main-header {
background: linear-gradient (#ffa949, transparent 90%),
linear-gradient(0deg, #fff, transparent), url(‘../img/mountains.jpg’) no-repeat center;
}
create two columns using inline-block
.col {
display: inline-block; width: 50%; margin-right: -4px; vertical-alignment: top; padding-left: 1em; padding-right: 1em; }
meta tag for responsive design
breakpoint for tablets
@media (min-width: 765px) { }
breakpoint for desktops
@media (min-width: 1025px) { }
max-width for desktops
.wrapper {
max-width: 1150px;
}
how do you fix collapsing margins of .main-header and ?
.main-header {
padding: 1em 0;
margin: 0;
}
create a sticky footer
- Create .wrap (below body and before footer )
- .wrap {
min-height: calc(100vh-82px);
}
get rid of the space between <li> items</li>
.main-nav li {
margin-right: -4px;
}
Add a fixed navigation screen (for desktops)
.main-header { position: fixed; width: 100%; top: 0; }
body {
padding-top: 15px; (compensates for the space covered by the bar)
}
make .profile-img 1.5 times larger on hover
.profile-img:hover {
transform: scale(1.5);
}
target all input fields of text type
input[type=”text”] {
}
change .btn cursor from arrow to pointer
.btn {
cursor: pointer;
}
target all links that are direct children of form
form > a {
color: pink;
}
target adjacent .btn, which is an immediate sibling of .btn
.btn + .btn {
margin-left: 20px;
}
target all label siblings of h1
h1 ~ label { }
target the first child of li
li::first-child { }
target the only child (with no siblings) of span
span::only-child { }
target all empty li fields
li::empty { }
target all links that start with http://
a[href^=”http://] { }
target all links that are pdf-files
a[href$=”.pdf”] { }
target all links that contain the word download in their filename
a[href*=”download”] { }
create a flex .container
.container {
display: flex;
}
change the background color of an input field and a text area when they get focus to yellow
input:focus,
textarea:focus {
background-color: yellow;
}
change the color of the disabled input field to light grey
input:disabled {
background: #ddd;
}
make the checkbox and the label bold when checked
input[type=”checkbox”]:checked + label {
font-weight: bold;
}
target all odd li items and make the background aqua green
li:nth-child(odd) {
background: #52bab3;
}
target every 2nd li item starting at the 3rd one and change the background color to aqua green
li:nth-child(2n+3) {
background: #52bab3;
}
select the first three li items
li:nth-child(-n+3) {
background: #52bab3;
}