<p> <font face="Arial">Welcome to Greasy Joe's.</font> You will <b>never</b>, <i>ever</i>, <u>EVER</u> beat <font size="+4" color="red">OUR</font> prices! </p>
b, i, u, y font no se aconsejan en HTML estricto
<link>
<head> ... <link href="filename" rel="stylesheet" /> ... </head>
<link href="style.css" rel="stylesheet" />
.css (preferido)style dentro del head (no recomendado)style en la etiqueta (no recomendado)<link>)<style> en el cabecero de la página)style de un elemento HTML )<style>
<head>
<style type="text/css">
p { font-family: sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>
head de una página HTMLstyle
<p style="font-family: sans-serif; color: red;"> This is a paragraph</p>
.css
selector {
property: value;
property: value;
...
property: value;
}
p {
font-family: sans-serif;
color: red;
}
* selecciona todos los elementosnth-child, inline-block, :not, +
body {
font-size: 16px;
}
body
body { color: green; }
p, h1, h2 { color: blue; font-style: italic; }
h2 { color: red; background-color: yellow; }
This paragraph uses the first style above.
/* ... */
/* Este es un comentario.
Puede estar en varias líneas del fichero CSS. */
p {
color: red;
background-color: aqua;
}
// NO es aceptado en CSS<!-- ... --> tampoco es aceptado en CSS
body { font-family: sans-serif; background-color: yellow; }
p { color: red; background-color: aqua; }
a { text-decoration: overline underline; }
h2 { font-weight: bold; text-align: center; }
A styled paragraph. Previous slides are available on the web site.
p {
color: red;
background-color: yellow;
}
Este párrafo usa el estilo anterior.
| propiedad | descripción |
|---|---|
color
|
color of the element's text |
background-color
|
color that will appear behind the element |
Una página de referencia de los diferentes colores en este enlace .
Chrome y otros navegadores tienen una utilidad (Color Picker) para seleccionar el color de manera interactiva
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
Este párrafo usa el primer estilo de arriba.
aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white (white), yellow| propiedad | descripción |
|---|---|
background-color
|
color to fill background |
background-image
|
image to place in background |
background-position
|
placement of bg image within element |
background-repeat
|
whether/how bg image should be repeated |
background-attachment
|
whether bg image scrolls with page |
background
|
shorthand to set all background properties |
background-image
body {
background-image: url("images/draft.jpg");
}
Este es el primer párrafo
Este es el segundo párrafo...
Ocupa dos líneas
background-repeat
body {
background-image: url("images/draft.jpg");
background-repeat: repeat-x;
}
Este es el primer párrafo
Este es el segundo párrafo...
Ocupa dos líneas
repeat (defecto), repeat-x, repeat-y, o no-repeatbackground-position
body {
background-image: url("images/draft.jpg");
background-repeat: no-repeat;
background-position: 370px 20px;
}
Este es el primer párrafo
Este es el segundo párrafo...
Ocupa dos líneas
top, left, right, bottom, center, un porcentaje, o el valor de longitud en px, pt, etc.| propiedad | descripción |
|---|---|
font-family
|
which font will be used |
font-size
|
how large the letters will be drawn |
font-style
|
used to enable/disable italic style |
font-weight
|
used to enable/disable bold style |
| Lista completa de propiedades font | |
font-family
p {
font-family: Georgia;
}
h2 {
font-family: "Courier New";
}
Este párrafo usa el primer estilo anterior.
font-family
p {
font-family: Garamond, "Times New Roman", serif;
}
Este párrafo usa el estilo anterior.
font-family value ensures that every computer will use a valid fontfont-size
p {
font-size: 14pt;
}
Este párrafo usa el estilo anterior.
px) vs. point (pt) vs. m-size (em)16px, 16pt,
1.16emxx-small,
x-small, small,
medium, large,
x-large, xx-large,
smaller, larger90%, 120%pt specifies number of point, where a point is 1/72 of an inch onscreenpx specifies a number of pixels on the screenem specifies number of m-widths, where 1 em is equal to the font's current sizefont-weight,
font-style
p {
font-weight: bold;
font-style: italic;
}
Este párrafo usa el estilo anterior.
normal para volver restituirlos (p.e. cabeceros)Google Fonts
MathJax - Fórmulas matemáticas
p, h1, h2 {
color: green;
}
h2 {
background-color: yellow;
}
Este párrafo usa el estilo anterior.
h2 arriba)| propiedad | descripción |
|---|---|
text-align
|
alignment of text within its element |
text-decoration
|
decorations such as underlining |
text-indent
|
indents the first letter of each paragraph |
text-shadow
|
a colored shadow near an existing piece of text
|
line-height, word-spacing, letter-spacing
|
gaps between the various portions of the text |
| Complete list of text properties | |
text-align
blockquote { text-align: justify; }
h2 { text-align: center; }
[TO LUKE SKYWALKER] The alliance... will die. As will your friends. Good, I can feel your anger. I am unarmed. Take your weapon. Strike me down with all of your hatred and your journey towards the dark side will be complete.
left, right, center, o justify (que ensancha todas las líneas completas del elemento de forma que ocupan todo su ancho) text-decoration
p {
text-decoration: underline;
}
This paragraph uses the style above.
overline, line-through, blink, o nonetext-decoration: overline underline;
text-shadow
p {
font-weight: bold;
text-shadow: -2px 5px gray;
}
This paragraph uses the style above.
list-style-type
ol { list-style-type: lower-roman; }
none : No markerdisc (default), circle, squaredecimal : 1, 2, 3, etc.decimal-leading-zero : 01, 02, 03, etc.lower-roman : i, ii, iii, iv, v, etc.upper-roman : I, II, III, IV, V, etc.lower-alpha : a, b, c, d, e, etc.upper-alpha : A, B, C, D, E, etc.lower-greek : alpha, beta, gamma, etc.hebrew, armenian, georgian, cjk-ideographic, hiragana, katakana, hiragana-iroha, katakana-iroha
a:link { color: #FF0000; } /* unvisited link */
a:visited { color: #00FF00; } /* visited link */
a:hover { color: #FF00FF; } /* mouse over link */
| class | description |
|---|---|
:active
|
an activated or selected element |
:focus
|
an element that has the keyboard focus |
:hover
|
an element that has the mouse over it |
:link
|
a link that has not been visited |
:visited
|
a link that has already been visited |
:first-letter
|
the first letter of text inside an element |
:first-line
|
the first line of text inside an element |
:first-child
|
an element that is the first one to appear inside another |
:nth-child(N)
|
applies to every Nth child of a given parent |
id
<p>Spatula City! Spatula City!</p> <p id="mission">Our mission is to provide the most spectacular spatulas and splurge on our specials until our customers <q>esplode</q> with splendor!</p>
<p>Visit <a href= "http://www.textpad.com/download/index.html#downloads"> textpad.com</a> to get the TextPad editor.</p> <p><a href="#mission">View our Mission Statement</a></p>
#
#mission {
font-style: italic;
font-family: "Garamond", "Century Gothic", serif;
}
Spatula City! Spatula City!
Our mission is to provide the most
spectacular spatulas and splurge on our specials until our
customers esplode
with splendor!
missionp#mission { class
<p class="shout">Spatula City! Spatula City!</p> <p class="special">See our spectacular spatula specials!</p> <p class="special">Today only: satisfaction guaranteed.</p>
id, una class se puede reutilizar tantas veces como se desee en una página
.special { /* any element with class="special" */
background-color: yellow;
font-weight: bold;
}
p.shout { /* only p elements with class="shout" */
color: red;
font-family: cursive;
}
Spatula City! Spatula City!
See our spectacular spatula specials!
Today only: satisfaction guaranteed.
special, o un p con clase shout
.special {
background-color: yellow;
font-weight: bold;
}
.shout {
color: red;
font-family: cursive;
}
<h2>Spatula City! Spatula City!</h2> <p class="special">See our spectacular spatula specials!</p> <p class="special shout">Satisfaction guaranteed.</p> <p class="shout">We'll beat any advertised price!</p>
See our spectacular spatula specials!
Satisfaction guaranteed.
We'll beat any advertised price!
<aside> <p> <em id="recent" class="awesome">The 5 stages of H.F.S.</em> </p> </aside>
aside { color: gray; }
p { color: green; }
em { color: yellow; }
.awesome { color: blue; }
em.awesome { color: red; }
#recent { color: black; }
em#recent.awesome { color: orange;}
The 5 stages of H.F.S.
Cuando se aplican múltiples estilos a un elemento y tienen la misma precedencia de origen. El más específico se aplica. Si tienen la misma especifidad, se usará el último.
<div>
una sección o división de una página HTML (block)
<div class="shout"> <h2>Spatula City! Spatula City!</h2> <p class="special">See our spectacular spatula specials!</p> <p>We'll beat any advertised price!</p> </div>
See our spectacular spatula specials!
We'll beat any advertised price!
<span>
elemento inline usado puramente como rango de aplicación de estilos
<h2>Spatula City! Spatula City!</h2> <p>See our <span class="special">spectacular</span> spatula specials!</p> <p>We'll beat <span class="shout">any advertised price</span>!</p>
See our spectacular spatula specials!
We'll beat any advertised price!
span
selector1 selector2 {
properties
}
selector1 > selector2 {
properties
}
<p>Shop at <strong>Hardwick's Hardware</strong>...</p> <ul> <li>The <strong>best</strong> prices in town!</li> <li>Act while supplies last!</li> </ul>
li strong { text-decoration: underline; }
<div id="ad"> <p>Shop at <strong>Hardwick's Hardware</strong>...</p> <ul> <li class="important">The <strong>best</strong> prices!</li> <li>Act <strong>while supplies last!</strong></li> </ul> </div>
#ad li.important strong { text-decoration: underline; }

h2 { border: 5px solid red; }
| property | description |
|---|---|
border
|
thickness/style/color of border on all 4 sides |
px, pt, em, or thin, medium, thick)none,
hidden,
dotted,
dashed,
double,
groove,
inset,
outset,
ridge,
solid)
| property | description |
|---|---|
border-color,
border-width, border-style
|
specific properties of border on all 4 sides |
border-bottom,
border-left, border-right,
border-top
|
all properties of border on a particular side |
border-bottom-color,
border-bottom-style, border-bottom-width,
border-left-color, border-left-style,
border-left-width, border-right-color,
border-right-style, border-right-width,
border-top-color, border-top-style,
border-top-width
|
properties of border on a particular side |
| Complete list of border properties | |
h2 {
border-left: thick dotted #CC0088;
border-bottom-color: rgb(0, 128, 128);
border-bottom-style: double;
}
border-bottom-width arriba)border-radius
p {
border: 3px solid blue;
border-radius: 12px;
padding: 0.5em;
}
This is a paragraph.
This is another paragraph.
It spans multiple lines.
| property | description |
|---|---|
padding
|
padding on all 4 sides |
padding-bottom
|
padding on bottom side only |
padding-left
|
padding on left side only |
padding-right
|
padding on right side only |
padding-top
|
padding on top side only |
| Complete list of padding properties | |
p { padding: 20px; border: 3px solid black; }
h2 { padding: 0px; background-color: yellow; }
This is the first paragraph
This is the second paragraph
p {
padding-left: 200px; padding-top: 30px;
background-color: fuchsia;
}
This is the first paragraph
This is the second paragraph
| property | description |
|---|---|
margin
|
margin on all 4 sides |
margin-bottom
|
margin on bottom side only |
margin-left
|
margin on left side only |
margin-right
|
margin on right side only |
margin-top
|
margin on top side only |
| Complete list of margin properties | |
p {
margin: 50px;
background-color: fuchsia;
}
This is the first paragraph
This is the second paragraph
p {
margin-left: 8em;
background-color: fuchsia;
}
This is the first paragraph
This is the second paragraph
p { width: 350px; background-color: yellow; }
h2 { width: 50%; background-color: aqua; }
This paragraph uses the first style above.
| property | description |
|---|---|
width,
height
|
how wide or tall to make this element (block elements only) |
max-width,
max-height, min-width,
min-height
|
max/min size of this element in given dimension |
auto margins
p {
margin-left: auto;
margin-right: auto;
width: 750px;
}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
width es asignado (de otra manera, puede ocupar el ancho entero de la página) text-align: center; float
(referencia)
| property | description |
|---|---|
float
|
side to hover on; can be left, right, or none (default)
|
un elemento flotante es eliminado del flujo normal del documento<img src="images/borat.jpg" alt="Borat" class="headericon" /> Borat Sagdiyev (born July 30, 1972) is a ...
img.headericon {
float: left;
}
Borat Sagdiyev (born July 30, 1972) is a fictional Kazakhstani journalist played by British-Jewish comedian Sacha Baron Cohen. He is the main character portrayed in the controversial and successful film Borat: Cultural Learnings of America for Make Benefit Glorious Nation of Kazakhstan ...
divs de estar alineados a flotantes... I am not floating, no width set
I am floating right, no width set
I am floating right, no width set, but my text is very long so this paragraph doesn't really seem like it's floating at all, darn
I am not floating, 45% width
I am floating right, 45% width
width
width, el contenido externo es incapaz de envolver el elemento flotanteclear
p { background-color: fuchsia; }
h2 { clear: right; background-color: yellow; }
Homestar Runner is a Flash animated Internet cartoon. It mixes surreal humour with ...
| property | description |
|---|---|
clear
|
disallows floating elements from overlapping this element; can be left, right, both, or none (default)
|
div#sidebar { float: right; }
p { clear: right; }
<p><img src="images/homestar_runner.png" alt="homestar runner" /> Homestar Runner is a Flash animated Internet cartoon. It mixes surreal humour with ....</p>
p { border: 2px dashed black; }
img { float: right; }
p que contiene la imagen se extienda hasta abajo tal que su borde encierre la imagen completa overflow
p { border: 2px dashed black; overflow: hidden; }
Homestar Runner is a Flash animated Internet cartoon. It mixes surreal humour with ....
| property | description |
|---|---|
overflow
|
specifies what to do if an element's content is too large; can be auto, visible, hidden, or scroll
|
<div> <p>the first paragraph</p> <p>the second paragraph</p> <p>the third paragraph</p> Some other text that is important </div>
p { float: right; width: 20%; margin: 0.5em;
border: 2px solid black; }
div { border: 3px dotted green; overflow: hidden; }
position
div#ad {
position: fixed;
right: 10%;
top: 45%;
}
| property | value | description |
|---|---|---|
position
|
static
|
default position |
relative
|
offset from its normal static position | |
absolute
|
a fixed position within its containing element | |
fixed
|
a fixed position within the browser window | |
top,
bottom, left,
right
|
positions of box's corners | |
#menubar {
position: absolute;
left: 400px;
top: 50px;
}
absolute o relative)top, bottom, left, right valueswidth
#area2 { position: relative; }
absolute en un elemento cuya position es relative
text-align
vertical-align
vertical-align | property | description |
|---|---|
vertical-align
|
specifies where an inline element should be aligned vertically, with respect to other content on the same line within its block element's box |
puede ser top, middle, bottom, baseline (default), sub, super, text-top, text-bottom, o un valor de longitud o %
baseline significa alineado con la parte inferior de letras que no sobresalen vertical-align<p style="background-color: yellow;"> <span style="vertical-align: top; border: 1px solid red;"> Don't be sad! Turn that frown <img src="images/sad.jpg" alt="sad" /> upside down! <img style="vertical-align: bottom" src="images/smiley.jpg" alt="smile" /> Smiling burns calories, you know. <img style="vertical-align: middle" src="images/puppy.jpg" alt="puppy" /> Anyway, look at this cute puppy; isn't he adorable! So cheer up, and have a nice day. The End. </span></p>
<p style="background-color: red; padding: 0px; margin: 0px"> <img src="images/smiley.png" alt="smile" /> </p>
padding y margin 0vertical-align a bottom arregla el problema (lo mismo ocurre con line-height a 0px)width, height, min-width, etc.) son ignorados por inline boxesmargin-top y margin-bottom se ignoran, pero margin-left y margin-right no text-align controla la posición horizontal de las cajas inline dentro de ella
vertical-align lo alinea verticalmente dentro de su block box display
h2 { display: inline; background-color: yellow; }
| property | description |
|---|---|
display
|
sets the type of CSS box model an element is displayed with |
none, inline, block, run-in, compact, ...Flexbox
<ul id="topmenu"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul>
#topmenu li {
display: inline;
border: 2px solid gray;
margin-right: 1em;
}
visibility
p.secret {
visibility: hidden;
}
Since nobody can see this anyway: ca-ca poo-poo pee-pee!!!
| property | description |
|---|---|
visibility
|
sets whether an element should be shown onscreen; can be visible (default) or hidden
|
hidden ocuparán espacio en la pantalla, pero no se mostrarán
display a noneopacity
body { background-image: url("images/marty-mcfly.jpg"); background-repeat: repeat; }
p { background-color: yellow; margin: 0; padding: 0.25em; }
p.mcfly1 { opacity: 0.75; }
p.mcfly2 { opacity: 0.50; }
p.mcfly3 { opacity: 0.25; }
Marty McFly in 1985
Marty McFly in 1955 fading away, stage 1
Marty McFly in 1955 fading away, stage 2
Marty McFly in 1955 fading away, stage 3
| property | description |
|---|---|
opacity
|
how not-transparent the element is; value ranges from 1.0 (opaque) to 0.0 (transparent) |
Animación
Esta es una tecnología experimental!
widget para ello.
Por ejemplo Facebook,
Instagram ,
Twitter ,
Pinterest .