Beginner's guide to learning CSS
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
selector {
property: value;
}
/* Ex */
p {
color: red;
}
<p>, <img>, <table>
font-size
, font-color
, font-family
...p {
font-family: Tahoma, Verdana, sans-serif;
}
You'll need to set 3 properties:
div {
background-color: red;
height: 100px;
width: 100px;
}
a {
text-decoration: none;
}
img {
height: 100px;
width: 100px;
border: 1px solid blue;
}
div {
/* Creates a box*/
height: 50px;
width: 120px;
border-color: grey;
background-color: blue;
/* Creates a rounder box*/
border-radius: 5px;
/* Positioning your button*/
margin: auto; /* Tells the browser to add equal margins on the LEFT & RIGHT sides of the HTML element
= object is centered*/
text-align: center; /* Centers the text within the element*/
}
<div>
<div>
<p>
</p>
</div>
</div>
div div p {
}
The outermost div is the parent, and the next div is a child of the 1st div
The p element is a child of the inner div
A shortcut to this approach is to use the '>' operator, which targets direct children without having to go through those other parent elements.
Universal style: that will apply styles to all elements on the page:
* {
}
ul li p /* is more specific than */
p
/* Meaning that when a p tag is nesed inside the ul li, that style will be applied to the element rather
than a style for just p elements = override
Classes and ID ARE MORE SPECIFIC than nested selectors!
. = class (used to style mutiple elements that should be styled together)
# = ID (used for when you want only 1 element to receive a certain style)
*/
<div id="hi" >
<p class="hello"></p>
</div>
#hi {
}
.hello {
}
#nav li {
} /* Will select all li element's that is nested under an element with an id of nav */
#list > li {
color: black;
}
h1, h2, #box {
/* apply styles */
}
selector:pseudo-class_selector {
property: value;
}
/* For links, there are a few pseudo class selectors for links
a:link (an unvisited link)
a:visted (a visited link)
a:hover (a link that is being hovered over)
*/
<div>
<p>1st child</p>
<p>Not first child </p>
</div>
p:first-child {
font-family: cursive;
}
/* nth-child selector*/
p:nth-child(2) { /*selects the 2nd child */
color: green;
}
img[alt=""] {
border =...
}
block
: makes the element a block box, it won't let anything sit next to it. It will take up the full width.inline-block
: makes the element a block but allows other elements to sit next to it on the same line.inline
: males elements sit next to each other on the same line, but without formatting it like a block.
Only takes up as much width as it needs (not the whole line)none
: makes the element and its content disappear from the page<p>
element, it is the text of the p element.