CSS Curso
CSS Curso
CSS Indice
CONCEPTO
SINTAXIS Y SELECTORES
- Selector de elementos
- Selector por id
- Selector por clases
COMENTARIOS CSS
ENLACES DE HOJA DE ESTILOS CSS
- Hoja de estilo externa
- Hoja de estilo interna
- Hoja de estilo en línea
COLORES CSS
- Por nombre
- Sistema hexadecimal
- Sistema RGB
- Sistema RGBA
- Sistema HSL
BACKGROUND O FONDOS
- Colocar fondos unicolores
- Colocar imágenes de fondos, cuadrarlas y repetir o no repetir las mismas en el fondo.
BORDE O BORDER
- Colocar el estilo del borde
- Establecer el ancho o grosor del borde
- Establecer el color del borde
- Configurar bordes individuales
MARGIN O MARGENES
- Establecer el tamaño de los márgenes de un elemento con respecto a su padre.
PADDING O RELLENO
- Configurar los padding individuales
WIDTH & HEIGHT O ALTO Y ANCHO
- Establecer el alto y el ancho de elementos.
- Establecer el alto y ancho minimo y máximo de un elemento.
CALCULO DEL MODELO DE CAJA
OUTLINE O BORDE DE AFUERA
- Establecer el estilo del borde de afuera.
- Establecer el color del borde de afuera.
- Establecer el ancho o el grosor del borde de afuera.
TEXTO
- Establecer el color del texto.
- Establecer el tamaño del texto.
- Establecer la alineación del texto.
- Establecer la decoración del texto como subrayado o resaltado.
- Establecer si el texto debe estar en mayúscula o minúscula.
- Establecer la sangría del texto.
- Establecer el espaciado entre letras de un texto.
- Establecer la altura de cada línea en un texto.
- Establecer la dirección del texto.
- Establecer el espaciado entre palabras de un texto.
- Establecer la sombra de un texto.
FUENTES O FONT
- Establecer la fuente de un texto
ICONOS
- Colocar iconos awesome
- Colocar iconos de bootstrap
- Colocar iconos de google
ENLACES O LINKS
- Establecer el color del texto de un enlace
- Personalizar los cuatro estados de un link
- Cambiar la decoración del texto de un enlace como subrayado o resaltado.
- Colocar un color de fondo de un enlace
- Creación de enlace como cajas
LISTAS O LIST
- Establecer el estilo o marcador de una lista desordenada.
- Establecer una imagen como marcador de una lista.
- Establecer la posición de los elementos de una lista.
- Quitar el marcador y la configuración básica de una lista.
- Personalizar una lista.
TABLAS O TABLES
- Configurar los bordes de una tabla.
- Configurar el alto y el ancho de una tabla.
- Alineación horizontal y vertical del texto de una tabla.
- Relleno de una tabla.
- Hover de una tabla para tablas interactivas.
- Colores en las tablas.
- Tablas con overflow.
DISPLAY O PRESENTACION DE ELEMENTOS
- Presentación bloque, línea y línea-bloque de un elemento.
- Ocultar la presentación de un elemento.
- Uso de visibility para ocultar elementos.
ALTURA Y ANCHO MAXIMO Y MINIMO
MAQUETACION Y POSICION DE UNA PAGINA WEB
- Uso de la posición static.
- Uso de la posición relative.
- Uso de la posición fixed.
- Uso de la posición absolute.
- Uso de la posición z de elementos.
- Uso de float para corrimiento de elementos.
- Colocar texto sobre una imagen.
DESBORDAMIENTO O OVERFLOW
- Overflow horizontal y vertical visible, hidden, scroll, auto y especificado .
FLOAT O FLOTADOR DE ELEMENTOS
- Uso de float y clear.
- Uso de clearfix para creación de maquetación web de pagina tipo 1.
LAYOUT INLINE-BLOCK
ENFOQUE DE CURSOR
- Cambiar el estilo del cursor sobre los elementos.
ALINEACION VERTICAL Y HORIZONTAL DE CAJAS Y ELEMENTOS
- Alineación al centro de cajas y elementos.
- Alineación centrar de texto.
- Alineación de elementos y texto en izquierda y derecha.
- Alineación vertical de cajas, elementos y texto.
COMBINADORES
- Uso de combinador de espacio, +, > y -.
PSEUDO CLASES
- El uso de los estados de un link o enlace.
- Configurar un elemento cuando se pasa el mouse sobre el mismo mediante el hover.
- Uso del first-child.
- Uso del lang.
- Uso de focus para cambiar las características de los formularios al ingresar datos en
ellos.
- Uso de last-child.
PSEUDO ELEMENTOS
- Uso de first-line para cambiar el estilo de la primera línea de un texto.
- Uso de first-letter para cambiar el estilo de la primera letra de un elemento.
- Uso de before para colocar contenido antes de un elemento.
- Uso de after para colocar contenido despues de un elemento.
- Uso de content para colocar contenido antes o después de un elemento.
- Uso de selection.
TRANSPARENCIA Y OPACIDAD
- Uso de opacity para establecer la opacidad o transparencia de un elemento.
- Cambiar la transparencia de un elemento mediante el hover.
- Uso de RGBA.
- Caja de texto trasparente dentro de un fondo o imagen.
MENU O BARRA DE NAVEGACION
- Barra de navegación simple.
- Barra de navegación vertical, colocar el activo de la barra de navegación, colocar
bordes y personalizar la barra, colocar la barra pegajosa y fija en la pantalla, hover
sobre una barra.
- Barra de navegación horizontal, colocar el activo, colocar bordes y personalizar la
barra, colocar la barra fija o pegajosa y colocar hover a la barra de navegación.
- Uso de topnav adaptativa para paginas y teléfonos.
- Uso de sidenav adaptativa para web y teléfonos.
- Barra de navegación con menú desplegable.
MENUS DESPLEGABLES
- Colocar textos con información o menú desplegables.
- Menú de navegación desplegable.
- Caja de imagen imagen desplegable.
- Menu de navegación desplegable y personalizado.
TOOLTIP O INFORMACION DESPLEGABLE
- Uso de básico del tooltip.
- Posición de un tooltip sobre un elemento.
- Uso de flecha en el tooltip.
- Tooltip con efecto de transición cuando aparece.
GALERIA DE IMÁGENES
- Como hacer una galería de imágenes para descargar y ver las imágenes adaptativa a
teléfono.
SPRITES IMAGES O IMÁGENES SPRITES
SELECTORES DE ATRIBUTOS
- Seleccionar un elemento o elementos y aplicar CSS por medio un atributo especifico.
- Seleccionar un elemento o elementos con un atributo y valor especifico y aplicar CSS.
- Seleccionar un elemento o elementos con un atributo y valor especifico sin importar
si esta un espacio en el texto o el mismo esta compuesto de varias palabras y aplicar
CSS.
- Seleccionar un elemento o elementos con un nombre de clase un – texto y aplicar CSS.
- Seleccionar un elementos o elementos que comuencen con un nombre de clase
especifico y aplicar CSS.
- Seleccionar un elemento o elementos que terminen con un nombre de clase
específico y aplicar CSS.
- Seleccionar un elemento o elementos que contengan un palabra o texto específico sin
importar como en la clase y alicar CSS.
FORM O FORMULARIOS
- Ajustar el ancho de entrada del campo del formulario.
- Ajustar el margen entre el formulario y ajustar el relleno de los mismos.
- Colocar borde a los formularios ajustar el ancho de los mismo, color, estilo y darle
redondeado a las esquinas.
- Colocar un color de fondo a las entradas y cambiar el color y la fuente de las letras.
- Configurar el enfoque de las entradas del formulario al darle click sobre las mismas.
- Configurar el color de fondo de las entradas de un formulario al darle click al mismo
para ingresar información.
- Colocar un icono antes de la entrada de un formulario y darle transición o retardo al
mismo.
- Reajustar los textareas para poder dar información larga de manera eficiente.
- Personalizar y editar los formularios de selección.
- Personalizar y editar los botones.
CONTADORES
- Colocar contadores para agrupar secciones, capítulos o índices en una pagina web.
CSS3 Indice
ESQUINAS REDONDEADAS
- Como colocar esquinas redondeadas a los bordes de los elementos.
- Como colocar esquinas elípticas en los bordes de los elementos.
IMAGEN COMO BORDE
- Como colocar una imagen como borde de los elementos y editar el aspecto de las
mismas.
FONDOS O BACKGROUND CSS3
- Agregar varias imágenes de fondo a los elementos.
- Ajustar el tamaño de la imagen o las imágenes de fondo en CSS3.
- Colocar una imagen de fondo de tamaño completo para toda una pagina web o una
sección de la misma.
- Especificar el origen de la imagen de fondo en la pantalla con respecto al contenido,
relleno o caja completa.
- Especificar el origen de un color de fondo en la pantalla con respecto al contenido,
relleno o caja completa.
COLORES CSS3
- Establecer colores por RGBA, HSL y HSLA.
- Establecer la opacidad o la transparencia de los elementos.
GRADIENTES
- Establecer los distintos tipos de gradientes lineales.
- Establecer gradientes lineales diagonales.
- Establecer el angulo de los gradientes lineales.
- Establecer varios colores en un gradiente lineal y la proporción de los mismos.
- Establecer transparencia en los gradientes.
- Establecer los distintos tipos de gradientes radiales.
- Establecer la repetición en los gradientes lineales y radiales.
SHADOW O SOMBRAS CSS3
- Aplicar sombras a un texto.
- Aplicar una sombra con color a un texto.
- Aplicar efecto de desenfoque a la sombra de un texto.
- Crear bordes dimples de color sobre un texto.
- Aplicar sombra a los elementos de una pagina web.
- Agregar un color a la sombra de los elementos.
- Aplicar efecto de desenfoque a la sombra de los elementos.
- Crear tarjetas o imágenes con efecto de sombra como si fueran papeles.
TEXT O TEXTO EN CSS3
- Como indicar o señalar un texto desbordado.
- Como completar un texto incompleto al pasar el cursor por el mismo.
- Romper una palabra muy larga y que aparezca en la siguiente línea.
FONT O FUENTES CSS3
- Agregar y emplear fuentes de texto externas.
TRANSFORMACIONES 2D
- Método translate: permite cambiar de posicion un elemento.
- Método rótate: permite rotar un elemento una cierta cantidad de grados.
- Método scale: permite aumentar o decrementar el tamaño de un elemento.
- Método skewX: permite inclinar horizontalmente un elemento.
- Método skewY: permite inclinar verticalmente un elemento.
- Método skew: permite inclinar tanto verticalmente como horizontalmente un
elemento.
- Método matrix: permite aplicar todas las transformaciones 2D a un elemento.
TRANSFORMACIONES 3D
- Método rotateX: permite rotar en el eje X un elemento.
- Método rotateY: permite rotar en el eje Y un elemento.
- Método rotateZ: permite rotar en el eje Z un elemento.
TRANSICIONES CSS3
- Cambiar el ancho o el alto de un elemento al posar el cursor sobre el mismo.
- Cambiar alguna de las propiedades de un elemento al posar el cursor sobre el mismo.
- Cambiar los efectos de la curva de transición.
- Agregar retardo a las transiciones.
- Agregar transformaciones a las transiciones.
ANIMACIONES CSS3
- Realizar animaciones CSS3.
- Cambiar el color de los elementos mediante una animación.
- Fragmentar los cambios en una animación o realizar animaciones por partes.
- Cambiar la posicion de un elemento de manera animada.
- Ejecutar un retardo antes de comenzar una animación.
- Ejecutar una animación un número de veces.
- Ejecutar una animación de manera infinita.
- Ejecutar una animación en dirección inversa o alternada.
- Especificar la curva de velocidad de una animación.
- Cambiar cualquier atributo de un elemento mediante una animación.
IMÁGENES CSS3
- Aplicar bordes redondeados a las imágenes.
- Aplicar bordes a las imágenes.
- Crear imágenes en miniatura.
- Crear imágenes sensibles o adaptables a los navegadores.
- Centrar una imagen.
- Ajustar la opacidad o transparencia de las imágenes.
- Colocar texto dentro de las imágenes.
- Aplicar filtros a las imágenes.
- Crear imágenes con hover de superposición.
- Crear imágenes sensibles con javascript.
BOTONES CSS3
- Ajustar el color de los botones.
- Ajustar el tamaño de los botones.
- Bordes redondeados en los botones.
- Borde de colores en los botones.
- Botones hoverables.
- Sombra en los botones y creacion de efectos de sombra.
- Efecto de opacidad en los botones.
- Ancho de un botón.
- Como hacer un grupo de botones apilados de manera horizontal.
- Como hacer un grupo de botones apilados de manera vertical.
- Efectos en los botones.
PAGINACION CSS3
- Como hacer una paginación simple.
- Como hacer una paginación activa y hoverable.
- Efectos de transición en la paginación.
- Agregar bordes a la paginación.
- Paginacion con espaciado entre los números.
- Cambiar el tamaño de la paginación.
- Centrar la paginación.
MULTIPLES COLUMNAS CCS3
- Como hacer multiples o varias columnas de un mismo texto o contenido.
- Colocar espacio entre las columnas.
- Colocar barras divisoras entre las columnas.
- Hacer que un elemento abarque varias columnas.
- Especificar el ancho de las columnas.
INTERFAZ DE USUARIO
- Redimensionar el ancho de un elemento o su tamaño horizontal en la pantalla.
- Redimesionar el alto de un elemento o su tamaño vertical en la pantalla.
- Redimensionar el ancho y el alto de un elemento en la pantalla.
- Agregar un espacio entre el outline o el contorno de un elemento y su borde.
TAMAÑO DE CAJA CONTENEDORA EN CSS3
- Incluir el relleno y el borde dentro del alto y ancho de un elemento.
FLEXBOX
- Crear un contenedor flexbox y sus elementos flexbox para emplear la disposición de
los elementos.
- Establecer la dirección de las flexbox.
- Justificar o alinear horizontalmente las flexbox dentro de un contenedor de flexbox.
- Justificar o alinear verticalmente las flexbox dentro de un contenedor de flexbox.
- Envolver o flotar de manera automática las flexbox.
- Justificar los envoltorios de las flexbox.
- Establecer el orden de las flexbox dentro de un contenedor.
- Colocar margin a las flexbox.
- Alinear verticalmente cada una de las flexbox individuales.
- Espeificar el ancho de las flexbox en un contenedor.
- Crear una pagina web empleando flexbox.
CONSULTA DE MEDIOS Y WEB RESPONSIVE DEVICE
- Tipos de consulta de medio CSS3.
- Como hacer una consulta de medio y la tabla de interfaces.
- Como hacer un diseño responsive para computadora.
- Como hacer un diseño responsive para tabñet.
- Como hacer un diseño responsive para Smartphone.
VIEWPORT
- Como emplear el metadato viewport
DISEÑO RESPONSIVE DE CUADRICULA
- Como emplear el método de diseño de cuadricula de 12 columnas.
- Hacer una pagina web responsive adaptable para distintos dispositivos.
- Hacer un diseño de web responsive para Smartphone y tablet con cambio de
orientación de pantalla.
IMÁGENES RESPONSIVE CCS3
- Agregar imágenes en el diseño web responsive.
- Agregar imágenes de fondo en el diseño web responsive.
- Cambiar imagen de uso de acuerdo al dispositivo.
- Uso de la etiqueta <picture>
VIDEOS RESPONSIVE CSS3
- Emplear un video responsive.
CSS Introducción
¿Qué es CSS?
CSS significa C ascading S tyle S heets
CSS describe cómo los elementos HTML se van a mostrar en la
pantalla, papel, o en otros medios
CSS ahorra mucho trabajo . Se puede controlar el diseño de varias
páginas web a la vez
Estilo externas se almacenan en archivos CSS
HTML fue creado para describir el contenido de una página web, como:
Para resolver este problema, el World Wide Web Consortium (W3C) creado
CSS.
Con una hoja de estilos externa, puede cambiar el aspecto de un sitio web
completo cambiando un archivo!
Una declaración CSS siempre termina con un punto y coma, y los bloques
de declaraciones están rodeados por llaves.
Ejemplo
p {
color: red;
text-align: center;
}
El selector de elementos
El selector de elementos selecciona elementos basados en el nombre del
elemento.
Puede seleccionar todos los elementos <p> en una página como esta (en
este caso, todos los elementos <p> serán centro alineado, con un color
rojo texto):
p {
text-align: center;
color: red;
}
El selector de ID
El selector de ID utiliza el atributo id de un elemento HTML para seleccionar
un elemento específico.
#para1 {
text-align: center;
color: red;
}
El selector de clase
El selector de clase selecciona elementos con un atributo de clase
específica.
Para seleccionar elementos con una clase específica, escriba un punto (.)
Carácter, seguido del nombre de la clase.
.center {
text-align: center;
color: red;
}
p.center {
text-align: center;
color: red;
}
La agrupación de selectores
Si tiene elementos con las mismas definiciones de estilo, como este:
h1 {
text-align: center;
color: red;
}
h2 {
text-align: center;
color: red;
}
p {
text-align: center;
color: red;
}
h1, h2, p {
text-align: center;
color: red;
}
Comentarios CSS
Los comentarios se utilizan para explicar el código, y puede ayudar al editar
el código fuente en una fecha posterior.
p {
color: red;
/* This is a single-line comment */
text-align: center;
}
/* This is
a multi-line
comment */
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
estilos en línea
Un estilo en línea se puede utilizar para aplicar un estilo único para un solo
elemento.
Ejemplo
Supongamos que una hoja de estilo externa tiene la siguiente estilo para el
elemento <h1>:
h1 {
color: navy;
}
a continuación, se supone que una hoja de estilo interna también tiene la
siguiente estilo para el elemento <h1>:
h1 {
color: orange;
}
<head>6bch7koo
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
h1 {
color: orange;
}
</style>
</head>
<head>
<style>
h1 {
color: orange;
}
</style>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
Solicitar en cascada
Qué estilo se utilizará cuando no se especifica más de un estilo de un
elemento HTML?
En términos generales se puede decir que todos los estilos voluntad "en
cascada" en una nueva hoja de estilos "virtual" por las siguientes reglas,
donde el número uno tiene la más alta prioridad:
CSS Colores
Los colores en CSS son más a menudo especificados por:
Cada parámetro (rojo, verde, azul) define la intensidad del color entre 0 y
255.
Tonos de gris a menudo se definen mediante valores iguales para todas las
3 fuentes de luz:
Colores hexadecimales
Valores RGB también pueden ser especificados
usando hexadecimales valores de color en la forma: # RRGGBB , donde
RR (rojo), GG (verde) y BB (azul) son valores hexadecimales entre 00 y FF
(igual que decimal 0-255).
Tonos de gris a menudo se definen mediante valores iguales para todas las
3 fuentes de luz:
Nombres de colores HTML
Los nombres de color compatibles con
todos los navegadores
Todos los navegadores modernos soportan los siguientes 140 nombres de
colores (haga clic en un nombre de color, o un valor hexadecimal, para ver
el color que el color de fondo, junto con diferentes colores del texto):
Pink Colors
Color Name HEX Color Shades Mix
Purple Colors
Color Name HEX Color Shades Mix
Orange Colors
Color Name HEX Color Shades Mix
Yellow Colors
Color Name HEX Color Shades Mix
Cyan Colors
Color Name HEX Color Shades Mix
Blue Colors
Color Name HEX Color Shades Mix
Brown Colors
Color Name HEX Color Shades Mix
White Colors
Color Name HEX Color Shades Mix
Grey Colors
Color Name HEX Color Shades Mix
Para hacer más fácil para usted para seleccionar un color gris hemos
compilado una tabla de tonos grises para usted:
#000000 rgb(0,0,0)
#080808 rgb(8,8,8)
#101010 rgb(16,16,16)
#181818 rgb(24,24,24)
#202020 rgb(32,32,32)
#282828 rgb(40,40,40)
#303030 rgb(48,48,48)
#383838 rgb(56,56,56)
#404040 rgb(64,64,64)
#484848 rgb(72,72,72)
#505050 rgb(80,80,80)
#585858 rgb(88,88,88)
#606060 rgb(96,96,96)
#686868 rgb(104,104,104)
#696969 rgb(105,105,105)
#707070 rgb(112,112,112)
#787878 rgb(120,120,120)
#888888 rgb(136,136,136)
#909090 rgb(144,144,144)
#989898 rgb(152,152,152)
#A0A0A0 rgb(160,160,160)
#A8A8A8 rgb(168,168,168)
HTML DarkGray !!! #A9A9A9 rgb(169,169,169)
#B0B0B0 rgb(176,176,176)
#B8B8B8 rgb(184,184,184)
#C8C8C8 rgb(200,200,200)
#D0D0D0 rgb(208,208,208)
#D8D8D8 rgb(216,216,216)
#E0E0E0 rgb(224,224,224)
#E8E8E8 rgb(232,232,232)
#F0F0F0 rgb(240,240,240)
#F8F8F8 rgb(248,248,248)
Una anomalía en la tabla anterior es que el HTML gris es más oscuro que el
gris oscuro.
X11 define gris a ser (190,190,190); que está más cerca a la plata HTML.
Tonos de rojo
Si nos fijamos en la tabla de colores a continuación, podrás ver el resultado
de la variación de la luz roja de 0 a 255, mientras se mantiene la luz verde
y azul en cero.
#000000 rgb(0,0,0)
#080000 rgb(8,0,0)
#100000 rgb(16,0,0)
#180000 rgb(24,0,0)
#200000 rgb(32,0,0)
#280000 rgb(40,0,0)
#300000 rgb(48,0,0)
#380000 rgb(56,0,0)
#400000 rgb(64,0,0)
#480000 rgb(72,0,0)
#500000 rgb(80,0,0)
#580000 rgb(88,0,0)
#600000 rgb(96,0,0)
#680000 rgb(104,0,0)
#700000 rgb(112,0,0)
#780000 rgb(120,0,0)
#800000 rgb(128,0,0)
#880000 rgb(136,0,0)
#900000 rgb(144,0,0)
#980000 rgb(152,0,0)
#A00000 rgb(160,0,0)
#A80000 rgb(168,0,0)
#B00000 rgb(176,0,0)
#B80000 rgb(184,0,0)
#C00000 rgb(192,0,0)
#C80000 rgb(200,0,0)
#D00000 rgb(208,0,0)
#D80000 rgb(216,0,0)
#E00000 rgb(224,0,0)
#E80000 rgb(232,0,0)
#F00000 rgb(240,0,0)
#F80000 rgb(248,0,0)
#FF0000 rgb(255,0,0)
Esta paleta de colores multi-navegador 216 valores hex fue creado para
asegurar que todos los equipos se mostrará correctamente los colores
cuando se ejecuta una paleta de 256 colores:
colores HSL
HSL Colores
valores de color HSL son compatibles con IE9 +, Firefox, Chrome, Safari y
Opera en 10+.
Matiz
Hue es una medida de la rueda de color de 0 a 360. 0 es el rojo, el verde
es de 120, 240 es azul.
Saturación
La saturación es un valor de porcentaje; 0% significa un tono de gris y el
100% es el color.
Ligereza
La ligereza es también un porcentaje; 0% es negro, 100% es de color
blanco.
Ejemplo
<style>
div {
background-color: hsl(180, 50%, 50%);
color: hsl(0, 0%, 100%);
}
</style>
colores HWB
HWB (Hue, blancura, negrura) es un estándar propuesto para CSS4.
Soporte HTML
HWB no es compatible con HTML (aún), pero se sugiere como un nuevo
estándar en CSS4.
Ejemplo
<div data-w3-color="hwb(60, 50%, 0)">
</div>
<script src="/lib/w3color.js"></script>
Colores CMYK
CMYK es un estándar sugerido para CSS4. Colores
CMYK
Colores CMYK es una combinación de cian, magenta, amarillo y NEGRO.
Ejemplo
<div data-w3-color="cmyk(100%, 0%, 0%, 0%)">
</div>
<script src="/lib/w3color.js"></script>
colores nCol
Colores Naturales (nCol)
Los colores naturales (nCol) es una iniciativa de W3Schools.
El sistema está diseñado para que sea más fácil para seleccionar colores
HTML.
NCol especifica colores usando una carta de color con un número para
especificar la distancia (en porcentaje) por el color.
R Rojo R
R25
R50
R75
Y Amarillo Y
Y25
Y50
Y75
G50
G75
do Cian do
C25
C50
C75
B25
B50
B75
M25
M50
M75
Soporte HTML
NCol no es compatible con HTML (aún), pero es muy cerca del nuevo
sistema de color HWB se sugiere en CSS4.
</div>
<script src="/lib/w3color.js"></script>
https://www.w3schools.com/lib/w3color.js
¿Por nCol?
Tratando de explicar los colores RGB o utilizando la notación hexadecimal
es muy difícil.
Debido a esto, nCol hace que sea mucho más fácil para describir colores.
Los colores naturales fueron descritos por primera vez por Karl Ewald
Konstantin Hering (Alemania 1834-1918).
Gradiente de color
Código CSS:
div {
background: linear-gradient(to bottom, #33ccff 0%, #ff99cc 100%);
}
Color Brands
The hex values below are approximate values intended to simulate
branded colors.
HEX: #4285F4
HEX: #FBBC05
HEX: #34A853
HEX: #EA4335
Twitter
HEX: #55ACEE
HEX: #292F33
HEX: #66757F
HEX: #CCD6DD
HEX: #E1E8ED
HEX: #FFFFFF
HEX: #3B5998
HEX: #8B9DC3
HEX: #DFE3EE
HEX: #F7F7F7
HEX: #FFFFFF
HEX: #F65314
HEX: #7CBB00
HEX: #00A1F1
HEX: #FFBB00
Intel
HEX: #0F7DC2
Instagram
HEX: #3F729B
IBM
HEX: #006699
Yahoo!
HEX: #7B0099
Amazon
HEX: #FF9900
HEX: #146EB4
Netflix
HEX: #221F1F
HEX: #E50914
Coca-Cola
HEX: #ED1C16
Pepsi
HEX: #E32934
HEX: #004883
IKEA
HEX: #FFCC00
HEX: #003399
Android
HEX: #A4C639
Color Trends
Color of the Year 2017
Greenery
HEX: #92B558
Pantone 15-0343
The HEX values are non official approximate values intended to simulate
the colors in HTML.
Pantone 17-1558
Tawny Port
HEX: #672E3B
Pantone 19-1725
Ballet Slipper
HEX: #F3D6E4
Pantone 13-2808
Butterum
HEX: #C48F65
Pantone 16-1341
Navy Peony
HEX: #223A5E
Pantone 19-4029
Neutral Gray
HEX: #898E8C
Pantone 17-4402
Shaded Spruce
HEX: #005960
Pantone 19-4524
Golden Lime
HEX: #9C9A40
Pantone 16-0543
Marina
HEX: #4F84C4
Pantone 17-4041
Autumn Maple
HEX: #D2691E
Pantone 17-1145
The 2016 spring hues also reflect our access to modern art and a desire for
natural surroundings.
Rose Quartz
HEX: #F7CAC9
Peach Echo
HEX: #F7786B
Snorkel Blue
HEX: #034F84
Limpet Shell
HEX: #98DDDE
Lilac Grey
HEX: #9896A4
Iced Coffee
HEX: #B18F6A
Fiesta
HEX: #DD4132
Buttercup
HEX: #FAE03C
Green Flash
HEX: #79C753
Pantone 15-0343
Pantone 13-1520
2016 Serenity
Hex #92A8D1
Pantone 15-3919
2015 Marsala
Hex #955251
Pantone 18-1438
Pantone 18-3224
2013 Emerald
Hex #009B77
Pantone 17-5641
2012 Tangerine Tango
Hex #DD4124
Pantone 17-1463
2011 Honeysucle
Hex #D65076
Pantone 18-2120
2010 Turquoise
Hex #45B8AC
Pantone 15-5510
2009 Mimosa
Hex #EFC050
Pantone 14-0848
Pantone 19-1557
Pantone 13-1106
Pantone 15-5217
2004 Tigerlily
Hex #E15D44
Pantone 17-1456
Pantone 14-4811
Pantone 19-1664
Pantone 17-2031
Pantone 15-4020
Green has healing power. It is the most restful color for the human eye.
CSS Fondos
Color de fondo
La background-color propiedad especifica el color de fondo de un
elemento.
h1 {
background-color: green;
}
div {
background-color: lightblue;
}
p {
background-color: yellow;
}
Imagen de fondo
La background-image propiedad especifica una imagen para usar como el
fondo de un elemento.
body {
background-image: url("paper.gif");
}
body {
background-image: url("bgdesert.jpg");
}
Nota: Cuando se utiliza una imagen de fondo, utilice una imagen que no
perturbe el texto. La imagen debe estar en la carpeta del CSS.
body {
background-image: url("gradient_bg.png");
}
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x;
}
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
}
En el ejemplo anterior, la imagen de fondo se muestra en el mismo lugar
que el texto. Queremos cambiar la posición de la imagen, de manera que
no perturbe el texto demasiado.
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
background-attachment: fixed;
}
background-color
background-image
background-repeat
background-attachment
background-position
CSS fronteras
Propiedades de borde CSS
Los CSS border propiedades le permiten especificar el estilo, el ancho y el
color del borde de un elemento.
Estilo de borde
La border-style propiedad especifica qué tipo de frontera que se vea.
Resultado:
La anchura se puede establecer como un tamaño específico (en px, pt, cm,
em, etc) o mediante el uso de uno de los tres valores predefinidos: fino,
medio o grueso.
p.two {
border-style: solid;
border-width: medium;
}
p.three {
border-style: solid;
border-width: 2px 10px 4px 20px;
}
Ejemplo
p.one {
border-style: solid;
border-color: red;
}
p.two {
border-style: solid;
border-color: green;
}
p.three {
border-style: solid;
border-color: red green blue yellow;
}
En CSS, también hay propiedades para especificar cada uno de los bordes
(superior, derecho, inferior e izquierda):
Ejemplo
p {
border-top-style: dotted;
border-right-style: solid;
border-bottom-style: dotted;
border-left-style: solid;
}
Ejemplo
p {
border-style: dottedsolid;
}
border-width
border-style (necesario)
border-color
Ejemplo
p {
border: 5px solid red;
}
Resultado:
Borde izquierdo
p {
border-left: 6px solid red;
background-color: lightgrey;
}
Borde inferior
p {
border-bottom: 6px solid red;
background-color: lightgrey;
}
Resultado:
redondeada Fronteras
La border-radius propiedad se utiliza para añadir bordes redondeados a
un elemento:
Ejemplo
p {
border: 2px solid red;
border-radius: 5px;
}
Property Description
border-radius Sets all the four border-*-radius properties for rounded corners
CSS márgenes
márgenes CSS
Los CSS margin propiedades se utilizan para generar el espacio alrededor
de los elementos.
margin-top
margin-right
margin-bottom
margin-left
Ejemplo
p {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
margin-top
margin-right
margin-bottom
margin-left
Ejemplo
p {
margin: 100px 150px 100px 80px;
}
margen: 25px;
o los cuatro márgenes son 25px
El valor auto
Puede establecer la propiedad de margen para auto centrar
horizontalmente el elemento en su contenedor.
Ejemplo
div {
width: 300px;
margin: auto;
border: 1px solid red;
}
El valor hereda
En este ejemplo se deja el margen izquierdo se hereda del elemento padre:
Ejemplo
div.container {
border: 1px solid red;
margin-left: 100px;
}
p.one {
margin-left: inherit;
}
Reducir el margen
Márgenes superior e inferior de los elementos a veces se derrumbó en un
solo margen que es igual a la mayor de las dos márgenes.
h2 {
margin: 20px 0 0 0;
}
Property Description
margin A shorthand property for setting the margin properties in one declarati
CSS Relleno
Relleno CSS
Los CSS padding propiedades se utilizan para generar el espacio alrededor
del contenido.
Con CSS, usted tiene el control total sobre el relleno. Hay propiedades CSS
para establecer el relleno para cada lado de un elemento (arriba, derecha,
abajo, e izquierda).
padding-top
padding-right
padding-bottom
padding-left
Todas las propiedades del relleno pueden tener los siguientes valores:
Ejemplo
p {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
padding-top
padding-right
padding-bottom
padding-left
Ejemplo
p {
padding: 50px 30px 50px 80px;
}
padding: 25px;
o los cuatro rellenos son 25px
Ejemplo
div.ex1 {
padding: 25px 50px 75px 100px;
}
div.ex2 {
padding: 25px 50px 75px;
}
div.ex3 {
padding: 25px 50px;
}
div.ex4 {
padding: 25px;
}
Todas las propiedades CSS de relleno
Property Description
padding A shorthand property for setting all the padding properties in one decla
Ejemplo
div {
height: 200px;
width: 50%;
background-color: powderblue;
}
Ejemplo
div {
height: 100px;
width: 500px;
background-color: powderblue;
}
Consejo: Arrastre la ventana del navegador para menor que 500 píxeles
de ancho, para ver la diferencia entre los dos divs!
Ejemplo
div {
max-width: 500px;
height: 100px;
background-color: powderblue;
}
Todas las propiedades CSS de dimensiones
Property Description
Ejemplo
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
Esta es la matemática:
320px (anchura)
+ 20 píxeles (izquierda + derecha relleno)
+ 10px (izquierda + derecha frontera)
+ 0px (margen izquierdo + derecho)
= 350 píxeles
La anchura total de un elemento debe calcularse así:
CSS Esquema
Esquema CSS
Los CSS outline propiedades especifican el estilo, color y ancho de un
esquema.
Ejemplo
p {
border: 1px solid black;
outline-color: red;
}
contorno color
La outline-color propiedad se utiliza para establecer el color del
contorno.
Esquema Ancho
La outline-width propiedad especifica el ancho del contorno.
La anchura se puede establecer como un tamaño específico (en px, pt, cm,
em, etc) o mediante el uso de uno de los tres valores predefinidos: fino,
medio o grueso.
Ejemplo
p {border: 1px solid black;}
p.one {
outline-style: double;
outline-color: red;
outline-width: thick;
}
p.two {
outline-style: double;
outline-color: green;
outline-width: 3px;
}
p {
border: 1px solid black;
outline: 5px dotted red;
}
Property Description
Color de texto
La color propiedad se utiliza para establecer el color del texto.
Ejemplo
body {
color: blue;
}
h1 {
color: green;
}
Ejemplo
p {
font-size: 30px;
}
Ejemplo
h1 {
text-align: center;
}
h2 {
text-align: left;
}
h3 {
text-align: right;
}
Ejemplo
div {
text-align: justify;
}
Decoración de texto
La text-decoration propiedad se utiliza para establecer o eliminar
decoraciones de texto.
Ejemplo
a {
text-decoration: none;
}
Ejemplo
h1 {
text-decoration: overline;
}
h2 {
text-decoration: line-through;
}
h3 {
text-decoration: underline;
}
Transformación de texto
La text-transform propiedad se utiliza para especificar letras mayúsculas
y minúsculas en un texto.
Ejemplo
p.uppercase {
text-transform: uppercase;
}
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}
La sangría de texto
La text-indent propiedad se utiliza para especificar la sangría de la
primera línea de un texto:
Ejemplo
p {
text-indent: 50px;
}
Espaciado de letras
La letter-spacing propiedad se utiliza para especificar el espacio entre
los caracteres de un texto.
Ejemplo
h1 {
letter-spacing: 3px;
}
h2 {
letter-spacing: -3px;
}
Altura de la línea
La line-height propiedad se utiliza para especificar el espacio entre
líneas:
Ejemplo
p.small {
line-height: 0.8;
}
p.big {
line-height: 1.8;
}
Ejemplo
h1 {
word-spacing: 10px;
}
h2 {
word-spacing: -5px;
}
Sombra de texto
El text-shadow establecimiento tiene sombra al texto.
Ejemplo
h1 {
text-shadow: 3px 2px red;
}
Todas las propiedades CSS de texto
Property Description
CSS Fuentes
Familia tipográfica
La familia de fuentes de un texto se establece con la font-family
propiedad.
La font-family propiedad debe contener varios nombres de fuentes como
un sistema de "retroceso". Si el navegador no es compatible con la primera
fuente, se intenta con el siguiente tipo de letra, y así sucesivamente.
Comenzar con la fuente que desea, y terminar con una familia genérica,
para permitir que el navegador recoger una fuente similar en la familia
genérica, si no hay otras fuentes están disponibles.
Ejemplo
p {
font-family: "Times New Roman", Times, serif;
}
Comenzar con la fuente que desea, y terminar con una familia genérica,
para permitir que el navegador recoger una fuente similar en la familia
genérica, si no hay otras fuentes están disponibles:
Ejemplo
p {
font-family: "Times New Roman", Times, serif;
}
serif Fuentes
font-family Exampletext
Sans-serif Fuentes
font-family Exampletext
heading
This is a paragraph
This is a heading
"Comic Sans MS", cursive, sans-serif
This is a paragraph
This is a heading
Impact, Charcoal, sans-serif
This is a paragraph
This is a heading
Tahoma, Geneva, sans-serif
This is a paragraph
This is a heading
Verdana, Geneva, sans-serif
This is a paragraph
Fuentes de espacio sencillo
font-family Exampletext
CSS iconos
Cómo agregar iconos
La forma más sencilla de añadir un icono a su página HTML, es con una
biblioteca de iconos, tales como la fuente impresionante.
Todos los iconos en las librerías de iconos abajo, son vectores escalables
que pueden ser personalizados con CSS (tamaño, color, sombra, etc.)
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/4.7.0/css/font-awesome.min.css">
Ejemplo
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<i class="fafa-cloud"></i>
<i class="fafa-heart"></i>
<i class="fafa-car"></i>
<i class="fafa-file"></i>
<i class="fafa-bars"></i>
</body>
</html>
Iconos de arranque
Para utilizar las glyphicons archivos de inicio, añada la siguiente línea
dentro de la <head> sección de su página HTML:
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootst
rap.min.css">
Ejemplo
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3
.7/css/bootstrap.min.css">
</head>
<body>
<i class="glyphiconglyphicon-cloud"></i>
<i class="glyphiconglyphicon-remove"></i>
<i class="glyphiconglyphicon-user"></i>
<i class="glyphiconglyphicon-envelope"></i>
<i class="glyphiconglyphicon-thumbs-up"></i>
</body>
</html>
Iconos de Google
Para utilizar los iconos de Google, añada la siguiente línea dentro de la
<head> sección de su página HTML:
<link rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons">
Ejemplo
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"href="https://fonts.googleapis.com/icon?family=Mate
rial+Icons">
</head>
<body>
<i class="material-icons">cloud</i>
<i class="material-icons">favorite</i>
<i class="material-icons">attachment</i>
<i class="material-icons">computer</i>
<i class="material-icons">traffic</i>
</body>
</html>
CSS Enlaces
Con CSS, enlaces pueden ser de estilo de diferentes maneras.
Enlaces de estilo
Los enlaces pueden ser de estilo con cualquier propiedad CSS (por
ejemplo color, font-family, background, etc.).
Ejemplo
a {
color: hotpink;
}
Ejemplo
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
Decoración de texto
La text-decoration propiedad se ha utilizado para eliminar los
subrayados de enlaces:
Ejemplo
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
Color de fondo
La background-color propiedad se puede utilizar para especificar un color
de fondo para los enlaces:
Ejemplo
a:link {
background-color: yellow;
}
a:visited {
background-color: cyan;
}
a:hover {
background-color: lightgreen;
}
a:active {
background-color: hotpink;
}
Ejemplo
a:link, a:visited {
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: red;
}
CSS Listas
Ejemplo
ul.a {
list-style-type: circle;
}
ul.b {
list-style-type: square;
}
ul.c {
list-style-type: none;
}
ol.c {
list-style-type: upper-roman;
}
ol.d {
list-style-type: lower-alpha;
}
Nota: Algunos de los valores son para listas desordenadas, y algunas de las
listas ordenadas. Otros de los valores para las lista desordenadas son:
lower-roman, upper-alpha, upper-greek, lower-greek, lower-latin, upper-
latin.
Ejemplo
ul {
list-style-image: url('sqpurple.gif');
}
Ejemplo
ul {
list-style-position: inside;
}
Ejemplo
ul {
list-style: square inside url("sqpurple.gif");
}
Ejemplo
ol {
background: #ff9999;
padding: 20px;
}
ul {
background: #3399ff;
padding: 20px;
}
ol li {
background: #ffe5e5;
padding: 5px;
margin-left: 35px;
}
ul li {
background: #cce5ff;
margin: 5px;
}
CSS Tablas
El aspecto de una tabla HTML se puede mejorar en gran medida con CSS:
Los bordes de tabla
Para especificar bordes de la tabla en CSS, utilice la border propiedad.
Ejemplo
table, th, td {
border: 1px solid black;
}
Ejemplo
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
Ejemplo
table {
border: 1px solid black;
}
Ejemplo
table {
width: 100%;
}
th {
height: 50px;
}
Alineación horizontal
La text-align propiedad establece la alineación horizontal (como
izquierda, derecha o centro) parte del contenido de <th> o <td>.
Alineamiento vertical
La vertical-align propiedad establece la alineación vertical (como
superior, inferior, o media) del contenido en <th> o <td>.
Por defecto, la alineación vertical del contenido de una tabla es medio (por
tanto <th> y <td> elementos).
Ejemplo
td {
height: 50px;
vertical-align: bottom;
}
Relleno de mesa
Para controlar el espacio entre el borde y el contenido de una tabla, utilice
la padding propiedad en <td> y <th> elementos:
Ejemplo
th, td {
padding: 15px;
text-align: left;
}
Ejemplo
th, td {
border-bottom: 1px solid #ddd;
}
Tabla Hoverable
Utilice el :hover selector de <tr> para resaltar filas de la tabla en el
mouse:
Ejemplo
tr:hover {background-color: #f5f5f5}
Tablas rayas
Ejemplo
tr:nth-child(even) {background-color: #f2f2f2}
Tabla de colores
El ejemplo siguiente se especifica el color de fondo y el color del texto de
los elementos <th>:
Ejemplo
th {
background-color: #4CAF50;
color: white;
}
Tabla de respuesta
Una tabla de respuesta se mostrará una barra de desplazamiento horizontal
si la pantalla es demasiado pequeña para mostrar el contenido completo:
Ejemplo
<div style="overflow-x: auto;">
<table>
... table content ...
</table>
</div>
La propiedad de presentación
La display propiedad especifica si / cómo se muestra un elemento.
<Div>
<H1> - <h6>
<P>
<Form>
<Header>
<Pie de página>
<Sección>
Elementos en línea
Un elemento en línea no se inicia en una nueva línea y sólo ocupa el mismo
ancho que sea necesario.
<Span>
<a>
<Img>
Display: none;
display: none; se utiliza comúnmente con JavaScript para ocultar y
mostrar elementos sin borrar y volver a crearlos. Echar un vistazo a
nuestro último ejemplo de esta página si quieres saber cómo esto se puede
lograr.
El <script> elemento utiliza display: none; por defecto.
Ejemplo
li {
display: inline;
}
Ejemplo
span {
display: block;
}
Ejemplo
h1.hidden {
display: none;
}
Sin embargo, el elemento aún llevará hasta el mismo espacio que antes. El
elemento se oculta, pero aún afecta a la disposición:
Ejemplo
h1.hidden {
visibility: hidden;
}
Más ejemplos
Las diferencias entre display: none; y la visibilidad: oculto;
Este ejemplo demuestra display: none; frente a la visibilidad: oculto;
Ejemplo 1
<!DOCTYPE html>
<html>
<head>
<style>
.imgbox {
float: left;
text-align: center;
width: 120px;
margin: 4px;
padding: 6px;
button {
width: 100%;
}
</style>
</head>
<body>
<p><strong>display:none</strong> removes the element from the document. It does not take up
any space.</p>
<button onclick="removeElement()">Remove</button>
</div>
<button onclick="changeVisibility()">Hide</button>
</div>
</div>
<script>
function removeElement() {
document.getElementById("imgbox1").style.display = "none";
function changeVisibility() {
document.getElementById("imgbox2").style.visibility = "hidden";
function resetElement() {
document.getElementById("imgbox1").style.display = "block";
document.getElementById("imgbox2").style.visibility = "visible";
</script>
</body>
</html>
Ejemplo 2
<!DOCTYPE html>
<html>
<head>
<style>
#panel, .flip {
font-size: 16px;
padding: 10px;
text-align: center;
background-color: #4CAF50;
color: white;
margin: auto;
#panel {
display: none;
</style>
</head>
<body>
<div id="panel">
<p>This panel contains a div element, which is hidden by default (display: none).</p>
<p>It is styled with CSS and we use JavaScript to show it (display: block).</p>
<p>How it works: Notice that the p element with class="flip" has an onclick attribute attached to
it. When the user clicks on the p element, a function called myFunction() is executed, which
changes the style of the div with id="panel" from display:none (hidden) to display:block
(visible).</p>
</div>
<script>
function myFunction() {
document.getElementById("panel").style.display = "block";
</script>
</body>
</html>
CSS visualización / propiedades de
visibilidad
Property Description
<!DOCTYPE html>
<html>
<head>
<style>
#panel, .flip {
font-size: 16px;
padding: 10px;
text-align: center;
background-color: #4CAF50;
color: white;
margin: auto;
#panel {
display: none;
</style>
</head>
<body>
<div id="panel">
<p>This panel contains a div element, which is hidden by default (display: none).</p>
<p>It is styled with CSS and we use JavaScript to show it (display: block).</p>
<p>How it works: Notice that the p element with class="flip" has an onclick attribute attached to
it. When the user clicks on the p element, a function called myFunction() is executed, which
changes the style of the div with id="panel" from display:none (hidden) to display:block
(visible).</p>
</div>
<script>
function myFunction() {
document.getElementById("panel").style.display = "block";
</script>
</body>
</html>
CSS Layout - anchura y ancho
máximo
Uso de anchura, max-anchura y el margen:
auto;
Como se mencionó en el capítulo anterior; un elemento en bloque siempre
ocupa todo el ancho disponible (se extiende hacia la izquierda y la derecha
tanto como sea posible).
div.ex2 {
max-width: 500px;
margin: auto;
border: 3px solid #73AD21;
}
La posición de la Propiedad
La position propiedad especifica el tipo de método de posicionamiento
utilizado para un elemento.
static
relative
fixed
absolute
Ejemplo
div.static {
position: static;
border: 3px solid #73AD21;
}
position: relative;
Un elemento con position: relative; se coloca en relación a su posición
normal.
posición: fijo;
Un elemento que se position: fixed; está posicionado en relación con el
área de visualización, lo que significa que siempre permanece en el mismo
lugar, incluso si la página se desplaza. La parte superior, derecho, inferior,
y las propiedades de izquierda se utilizan para posicionar el elemento.
Ejemplo
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 300px;
border: 3px solid #73AD21;
}
position: absolute;
Un elemento con position: absolute; está posicionado con relación al
antepasado posicionado más cercano (en lugar de en relación posicionada
para la ventana gráfica, como fija).
Sin embargo; si un elemento posicionado absoluto no tiene antepasados
posicionado, que utiliza el cuerpo del documento, y se mueve junto con la
página de desplazamiento.
Ejemplo
div.relative {
position: relative;
width: 400px;
height: 200px;
border: 3px solid #73AD21;
}
div.absolute {
position: absolute;
top: 80px;
right: 0;
width: 200px;
height: 100px;
border: 3px solid #73AD21;
}
La superposición de elementos
Cuando se colocan los elementos, que se pueden superponer otros
elementos.
Ejemplo
img {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
Más ejemplos
Todas las propiedades CSS de
posicionamiento
Property Description
overflow: visible
Por defecto, el desbordamiento es visible, lo que significa que no se
recorta y se hace fuera de la caja del elemento:
Ejemplo
div {
width: 200px;
height: 50px;
background-color: #eee;
overflow: visible;
}
overflow: hidden
Con el hidden valor, el desbordamiento se recorta, y el resto del contenido
es oculto:
Ejemplo
div {
overflow: hidden;
}
overflow: scroll
Al establecer el valor scroll, el desbordamiento se recorta y se agrega una
barra de desplazamiento para desplazarse dentro de la caja. Tenga en
cuenta que esto añadirá una barra de desplazamiento horizontal y vertical
(incluso si usted no lo necesita):
Ejemplo
div {
overflow: scroll;
}
overflow: auto
El auto valor es similar a scroll, sólo que añadir barras de
desplazamiento cuando sea necesario:
Puede utilizar la propiedad de desbordamiento cuando se desea tener un
mejor control de la disposición. La propiedad de desbordamiento especifica
qué ocurre si el contenido desborda la caja de un elemento.
Ejemplo
div {
overflow: auto;
}
overflow-x y el desbordamiento-y
El overflow-x y overflow-y propiedades especifica si se debe cambiar el
desbordamiento del contenido simplemente horizontal o verticalmente (o
ambos):
overflow-x especifica qué hacer con los bordes izquierdo / derecho del
contenido.
overflow-y especifica qué hacer con los bordes superior / inferior del
contenido.
Ejemplo
div {
overflow-x: hidden; /* Hide horizontal scrollbar */
overflow-y: scroll; /* Add vertical scrollbar */
}
Property Description
overflow Specifies what happens if content overflows an element's box
La propiedad float
En su uso más sencillo, la float propiedad se puede utilizar para ajustar el
texto alrededor de las imágenes.
Ejemplo
img {
float: right;
margin: 0 0 10px 10px;
}
La clara Propiedad
La clear propiedad se utiliza para controlar el comportamiento de los
elementos flotantes.
Ejemplo
div {
clear: left;
}
El clearfix Hack
Si un elemento es más alto que el elemento que lo contiene, y que se flota,
se desborde fuera de su contenedor.
Ejemplo
.clearfix {
overflow: auto;
}
Ejemplo
.clearfix::after {
content: "";
clear: both;
display: table;
}
.column {
float: left;
padding: 15px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
.menu {
width: 25%;
}
.content {
width: 75%;
}
Más ejemplos
Una imagen con la frontera y márgenes que flota hacia la derecha en un
párrafo
Deje un flotador de imagen a la derecha en un párrafo. Añadir a la frontera
y los márgenes de la imagen.
EJEMPLO 1
<!DOCTYPE html>
<html>
<head>
<style>
img {
float: right;
</style>
</head>
<body>
<p>In the paragraph below, the image will float to the right. A dotted black border is added to the
image.
We have also added margins to the image to push the text away from the image:
0 px margin on the top and right side, 15 px margin on the bottom, and 20 px margin on the left
side of the image.
</p>
</p>
</body>
</html>
EJEMPLO 2
<!DOCTYPE html>
<html>
<head>
<style>
div {
float: right;
width: 120px;
padding: 15px;
text-align: center;
</style>
</head>
<body>
<div>
</div>
<p>
</p>
<p>
In the paragraph above, the div element is 120 pixels wide and it contains the image.
The div element will float to the right. Margins are added to the div to push the text away from the
div.
Borders and padding are added to the div to frame in the picture and the caption.
</p>
</body>
</html>
EJEMPLO 3
<!DOCTYPE html>
<html>
<head>
<style>
span {
float: left;
width: 0.7em;
font-size: 400%;
line-height: 80%;
}
</style>
</head>
<body>
<p>
</p>
<p>
In the paragraph above, the first letter of the text is embedded in a span element.
The span element has a width that is 0.7 times the size of the current font.
The font-size of the span element is 400% (quite large) and the line-height is 80%.
</p>
</body>
</html>
EJEMPLO 4
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
li {
float: left;
li a {
display: inline-block;
color: white;
text-align: center;
text-decoration: none;
li a:hover {
background-color: #111;
}
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</body>
</html>
EJEMPLO 6
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
body {
margin: 0;
.header {
background-color: #2196F3;
color: white;
text-align: center;
padding: 15px;
.footer {
background-color: #444;
color: white;
padding: 15px;
.topmenu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #777;
.topmenu li {
float: left;
.topmenu li a {
display: inline-block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
.topmenu li a:hover {
background-color: #222;
.topmenu li a.active {
color: white;
background-color: #4CAF50;
.column {
float: left;
padding: 15px;
.clearfix::after {
content: "";
clear: both;
display: table;
.sidemenu {
width: 25%;
.content {
width: 75%;
.sidemenu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.sidemenu li a {
margin-bottom: 4px;
display: block;
padding: 8px;
background-color: #eee;
text-decoration: none;
color: #666;
.sidemenu li a:hover {
background-color: #555;
color: white;
.sidemenu li a.active {
background-color: #008CBA;
color: white;
</style>
</head>
<body>
<ul class="topmenu">
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
<div class="clearfix">
<ul>
</ul>
</div>
<div class="header">
<h1>The City</h1>
</div>
<h1>Chania</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
<p>You will learn more about responsive web pages in a later chapter.</p>
</div>
</div>
<div class="footer">
<p>Footer Text</p>
</div>
</body>
</html>
Property Description
Ejemplos
La vieja manera - con ayuda de float (nótese que también tenemos que
especificar una clear propiedad para el elemento después de que las cajas
flotantes):
Ejemplo
.floating-box {
float: left;
width: 150px;
height: 75px;
margin: 10px;
border: 3px solid #73AD21;
}
.after-box {
clear: left;
}
<!DOCTYPE html>
<html>
<body>
<span style="cursor:auto">auto</span><br>
<span style="cursor:crosshair">crosshair</span><br>
<span style="cursor:default">default</span><br>
<span style="cursor:e-resize">e-resize</span><br>
<span style="cursor:help">help</span><br>
<span style="cursor:move">move</span><br>
<span style="cursor:n-resize">n-resize</span><br>
<span style="cursor:ne-resize">ne-resize</span><br>
<span style="cursor:nw-resize">nw-resize</span><br>
<span style="cursor:pointer">pointer</span><br>
<span style="cursor:progress">progress</span><br>
<span style="cursor:s-resize">s-resize</span><br>
<span style="cursor:se-resize">se-resize</span><br>
<span style="cursor:sw-resize">sw-resize</span><br>
<span style="cursor:text">text</span><br>
<span style="cursor:w-resize">w-resize</span><br>
<span style="cursor:wait">wait</span><br>
</body>
</html>
Ejemplo
.center {
margin: auto;
width: 50%;
border: 3px solid green;
padding: 10px;
}
Centrar texto
Para simplemente centrar el texto dentro de un elemento, el uso text-
align: center;
Ejemplo
.center {
text-align: center;
border: 3px solid green;
}
Ejemplo
img {
display: block;
margin: auto;
width: 40%;
}
Ejemplo
body {
margin: 0;
padding: 0;
}
.container {
position: relative;
width: 100%;
}
.right {
position: absolute;
right: 0px;
width: 300px;
background-color: #b0e0e6;
}
Ejemplo
.right {
float: right;
width: 300px;
border: 3px solid #73AD21;
padding: 10px;
}
Ejemplo
body {
margin: 0;
padding: 0;
}
.right {
float: right;
width: 300px;
background-color: #b0e0e6;
}
Ejemplo
.center {
padding: 70px 0;
border: 3px solid green;
}
Para centrar tanto vertical como horizontalmente, utilizar padding y text-
align: center:
Ejemplo
.center {
padding: 70px 0;
border: 3px solid green;
text-align: center;
}
Ejemplo
.center {
height: 200px;
position: relative;
border: 3px solid green;
}
.center p {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
CSS combinadores
CSS combinadores
Un combinador es algo que explica la relación entre los selectores.
Selector descendiente
El selector descendiente coincide con todos los elementos que son
descendientes de un elemento especificado.
Selector de niño
El selector niño selecciona todos los elementos que son los hijos inmediatos
de un elemento especificado.
El siguiente ejemplo selecciona todos los <p> elementos que son hijos
inmediatos de un elemento <div>:
Ejemplo
div> p {
background-color: yellow;
}
Ejemplo
div + p {
background-color: yellow;
}
Selector general entre hermanos
El interruptor general de hermanos selecciona todos los elementos que son
hermanos de un elemento especificado.
El ejemplo siguiente selecciona todos <p> elementos que son los hermanos
de los elementos <div>:
Ejemplo
div ~ p {
background-color: yellow;
}
CSS pseudo-clases
¿Cuáles son pseudo-clases?
Un pseudo-clase se utiliza para definir un estado especial de un elemento.
Sintaxis
La sintaxis de pseudo-clases:
selector:pseudo-class {
property:value;
}
Ancla pseudo-clases
Enlaces se pueden mostrar de distintas maneras:
Ejemplo
/* unvisited link */
a:link {
color: #FF0000;
}
/* visited link */
a:visited {
color: #00FF00;
}
/* selected link */
a:active {
color: #0000FF;
}
Ejemplo
div:hover {
background-color: blue;
}
Ejemplo
p {
display: none;
background-color: yellow;
padding: 20px;
}
div:hover p {
display: block;
}
CSS - El: first-child pseudo-clase
El :first-child pseudo-clase coincide con un elemento especificado que
es el primer hijo de otro elemento.
Ejemplo
p:first-child {
color: blue;
}
Ejemplo
p i:first-child {
color: blue;
}
En el siguiente ejemplo, :lang define las comillas para <q> elementos con
lang = "no":
Ejemplo
<html>
<head>
<style>
q:lang(no) {
quotes: "~" "~";
}
</style>
</head>
<body>
<p>Some text <q lang="no">A quote in a paragraph</q> Some text.</p>
</body>
</html>
CSS - El:focus
La :focus pseudo-clase le permite definir reglas especiales para diferentes
ingreso de dato en formularios, de manera que al ingresar el dato en los
mismo se permita cambiar el color de la casilla.
Más ejemplos
Añadir diferentes estilos de hipervínculos
Este ejemplo muestra cómo agregar otros estilos de hipervínculos.
Ejemplo 1
<!DOCTYPE html>
<html>
<head>
<style>
a.one:link {color:#ff0000;}
a.one:visited {color:#0000ff;}
a.one:hover {color:#ffcc00;}
a.two:link {color:#ff0000;}
a.two:visited {color:#0000ff;}
a.two:hover {font-size:150%;}
a.three:link {color:#ff0000;}
a.three:visited {color:#0000ff;}
a.three:hover {background:#66ff66;}
a.four:link {color:#ff0000;}
a.four:visited {color:#0000ff;}
a.four:hover {font-family:monospace;}
a.five:link {color:#ff0000;text-decoration:none;}
a.five:visited {color:#0000ff;text-decoration:none;}
a.five:hover {text-decoration:underline;}
</style>
</head>
<body>
</body>
</html>
Ejemplo 2
<!DOCTYPE html>
<html>
<head>
<style>
input:focus {
background-color: yellow;
</style>
</head>
<body>
</form>
</body>
</html>
CSS pseudo-elemento
¿Cuáles son los pseudo-elementos?
Un pseudo-elemento CSS se utiliza para estilo especificado partes de un
elemento.
selector::pseudo-element {
property:value;
}
Ejemplo
p::first-line {
color: #ff0000;
font-variant: small-caps;
}
Nota: El ::first-line pseudo-elemento sólo se puede aplicar a los
elementos a nivel de bloque.
propiedades de la fuente
propiedades de color
propiedades de fondo
word-spacing
espaciado de letras
text-decoration
vertical-align
text-transform
altura de la línea
claro
La :: pseudo-elemento first-letter
El ::first-letter pseudo-elemento se utiliza para añadir un estilo
especial a la primera letra de un texto.
Ejemplo
p::first-letter {
color: #ff0000;
font-size: xx-large;
}
propiedades de la fuente
propiedades de color
propiedades de fondo
propiedades de los márgenes
propiedades de relleno
propiedades de borde
text-decoration
vertical-align (sólo si "flotar" es "ninguna")
text-transform
altura de la línea
flotador
claro
Ejemplo
p.intro::first-letter {
color: #ff0000;
font-size:200%;
}
Múltiples pseudo-elementos
Varios pseudo-elementos también se pueden combinar.
Ejemplo
p::first-letter {
color: #ff0000;
font-size: xx-large;
}
p::first-line {
color: #0000ff;
font-variant: small-caps;
}
Ejemplo
h1::before {
content: url(smiley.gif);
}
Ejemplo
h1::after {
content: url(smiley.gif);
}
CSS - La selección :: pseudo-elemento
El ::selection pseudo-elemento coincide con la porción de un elemento
que es seleccionado por un usuario.
Ejemplo
::selection {
color: red;
background: yellow;
}
imagen transparente
La opacity propiedad puede tener valor comprendido entre 0,0 - 1,0. El
valor más bajo, el más transparente:
Nota: IE8 y uso anterior filter:alpha(opacity=x). La x puede tomar un
valor de 0 - 100. Un valor más bajo hace que el elemento más
transparente.
Ejemplo
img {
opacity: 0.5;
filter: alpha(opacity=50); /* For IE8 and earlier */
}
Ejemplo
img {
opacity: 0.5;
filter: alpha(opacity=50); /* For IE8 and earlier */
}
img:hover {
opacity: 1.0;
filter: alpha(opacity=100); /* For IE8 and earlier */
}
Ejemplo explicó
Ejemplo
img:hover {
opacity: 0.5;
filter: alpha(opacity=50); /* For IE8 and earlier */
}
Caja transparente
Cuando se utiliza la opacity propiedad para añadir transparencia al fondo
de un elemento, todos sus elementos hijos heredan la misma
transparencia. Esto puede hacer que el texto dentro de un elemento
totalmente transparente difícil de leer:
Ejemplo
div {
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
}
Ejemplo
div {
background: rgba(76, 175, 80, 0.3) /* Green background with 30%
opacity */
}
Ejemplo
<html>
<head>
<style>
div.background {
background: url(klematis.jpg) repeat;
border: 2px solid black;
}
div.transbox {
margin: 30px;
background-color: #ffffff;
border: 1px solid black;
opacity: 0.6;
filter: alpha(opacity=60); /* For IE8 and earlier */
}
div.transbox p {
margin: 5%;
font-weight: bold;
color: #000000;
}
</style>
</head>
<body>
<div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.</p>
</div>
</div>
</body>
</html>
Ejemplo
<ul>
<li><a href="default.asp">Home</a></li>
<li><a href="news.asp">News</a></li>
<li><a href="contact.asp">Contact</a></li>
<li><a href="about.asp">About</a></li>
</ul>
Ejemplo
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
Ejemplo explicó:
list-style-type: none;- Elimina las balas. Una barra de
navegación no necesita marcadores de lista
Establecer margin: 0;y padding: 0; quitar la configuración por
defecto del navegador
Ejemplo
li a {
display: block;
width: 60px;
}
Ejemplo explicó:
Ejemplo
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 60px;
}
li a {
display: block;
}
Ejemplo
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: #f1f1f1;
}
li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
Añadir una clase de "activo" para el enlace actual para que el usuario sepa
qué página que él / ella está en:
Ejemplo
.active {
background-color: #4CAF50;
color: white;
}
li {
text-align: center;
border-bottom: 1px solid #555;
}
li:last-child {
border-bottom: none;
}
Ejemplo
li {
display: inline;
}
Ejemplo explicó:
Otra forma de crear una barra de navegación horizontal es flotar los <li>
elementos, y especificar un diseño para el menú de navegación:
Ejemplo
li {
float: left;
}
a {
display: block;
padding: 8px;
background-color: #dddddd;
}
Ejemplo explicó:
Ejemplo
ul {
background-color: #dddddd;
}
Ejemplo
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
Ejemplo
.active {
background-color: #4CAF50;
}
Ejemplo
/* Add a gray right border to all list items, except the last item (last-
child) */
li {
border-right: 1px solid #bbb;
}
li:last-child {
border-right: none;
}
fondo fijo
ul {
position: fixed;
bottom: 0;
width: 100%;
}
li a {
color: #666;
}
Más ejemplos
topnav sensible
Cómo utilizar CSS3 preguntas de los medios para crear una barra de
navegación superior sensible.
Ejemplo 1
<!DOCTYPE html>
<html>
<head>
<style>
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
ul.topnav li a {
display: block;
color: white;
text-align: center;
text-decoration: none;
ul.topnav li.right,
</style>
</head>
<body>
<ul class="topnav">
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<p>This example use media queries to stack the topnav vertically when the screen size is 600px or
less.</p>
<p>You will learn more about media queries and responsive web design later in our CSS
Tutorial.</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
ul.sidenav {
list-style-type: none;
margin: 0;
padding: 0;
width: 25%;
background-color: #f1f1f1;
position: fixed;
height: 100%;
overflow: auto;
ul.sidenav li a {
display: block;
color: #000;
text-decoration: none;
ul.sidenav li a.active {
background-color: #4CAF50;
color: white;
ul.sidenav li a:hover:not(.active) {
background-color: #555;
color: white;
div.content {
margin-left: 25%;
padding: 1px 16px;
height: 1000px;
ul.sidenav {
width: 100%;
height: auto;
position: relative;
ul.sidenav li a {
float: left;
padding: 15px;
ul.sidenav li a {
text-align: center;
float: none;
</style>
</head>
<body>
<ul class="sidenav">
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
<div class="content">
<p>This example use media queries to transform the sidenav to a top navigation bar when the
screen size is 900px or less.</p>
<p>We have also added a media query for screens that are 400px or less, which will vertically
stack and center the navigation links.</p>
<p>You will learn more about media queries and responsive web design later in our CSS
Tutorial.</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
li {
float: left;
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
text-decoration: none;
background-color: red;
li.dropdown {
display: inline-block;
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
.dropdown:hover .dropdown-content {
display: block;
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li class="dropdown">
<div class="dropdown-content">
</div>
</li>
</ul>
</body>
</html>
Ejemplo
<style>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<style>
.dropdown {
position: relative;
display: inline-block;
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
.dropdown:hover .dropdown-content {
display: block;
</style>
</head>
<body>
<h2>Hoverable Dropdown</h2>
<p>Move the mouse over the text below to open the dropdown content.</p>
<div class="dropdown">
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
</body>
</html>
ejemplo Explicación
HTML) Usar cualquier elemento para abrir el contenido desplegable, por
ejemplo, un <span> o un <button> elemento.
Menú desplegable
Crear un menú desplegable que permite al usuario elegir una opción de una
lista:
/* Change the background color of the dropdown button when the dropdown
content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
.dropdown {
position: relative;
display: inline-block;
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
.dropdown:hover .dropdown-content {
display: block;
.dropdown:hover .dropbtn {
background-color: #3e8e41;
</style>
</head>
<body>
<h2>Dropdown Menu</h2>
<p>Move the mouse over the button to open the dropdown menu.</p>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
</div>
</div>
<p><strong>Note:</strong> We use href="#" for test links. In a real web site this would be
URLs.</p>
</body>
</html>
Alineado a la derecha-contenido
desplegable
Ejemplo
.dropdown-content {
right: 0;
}
<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
.dropdown {
position: relative;
display: inline-block;
.dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
</style>
</head>
<body>
<p>Determine whether the dropdown content should go from left to right or right to left with the
left and right properties.</p>
<button class="dropbtn">Left</button>
</div>
</div>
<button class="dropbtn">Right</button>
<div class="dropdown-content">
</div>
</div>
</body>
</html>
Más ejemplos
<!DOCTYPE html>
<html>
<head>
<style>
.dropdown {
position: relative;
display: inline-block;
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
.dropdown:hover .dropdown-content {
display: block;
.desc {
padding: 15px;
text-align: center;
</style>
</head>
<body>
<h2>Dropdown Image</h2>
<p>Move the mouse over the image below to open the dropdown content.</p>
<div class="dropdown">
<div class="dropdown-content">
<img src="img_fjords.jpg" alt="Trolltunga Norway" width="300" height="200">
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
li {
float: left;
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
text-decoration: none;
background-color: red;
li.dropdown {
display: inline-block;
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
text-align: left;
.dropdown:hover .dropdown-content {
display: block;
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li class="dropdown">
<div class="dropdown-content">
</div>
</li>
</ul>
</body>
</html>
CSS TooltipSiguiente ❯
Crear información sobre herramientas con CSS.
Ejemplo
<style>
/* Tooltip container */
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black; /* If you want dots under the
hoverable text */
}
/* Tooltip text */
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
padding: 5px 0;
border-radius: 6px;
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
<!DOCTYPE html>
<html>
<style>
.tooltip {
position: relative;
display: inline-block;
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
</style>
<body style="text-align:center;">
</div>
<p>Note that the position of the tooltip text isn't very good. Go back to the tutorial and continue
reading on how to position the tooltip in an desirable way.</p>
</body>
</html>
ejemplo Explicación
HTML) Use un elemento de contenedor (como <div>) y añadir la
"tooltip" clase a la misma. Cuando el puntero del ratón sobre este
usuario <div>, se mostrará el texto de sugerencia.
derecha Tooltip
.tooltip .tooltiptext {
top: -5px;
left: 105%;
}
izquierda Tooltip
.tooltip .tooltiptext {
top: -5px;
right: 105%;
}
Si desea que aparezca la información sobre herramientas en la parte
superior o en la parte inferior, ver ejemplos a continuación. En cuenta que
utilizamos la margin-left propiedad con un valor de menos de 60
píxeles. Esta es centrar la descripción encima / debajo del texto
hoverable. Se establece en la media del ancho de la información de
herramienta (120/2 = 60).
Top Tooltip
.tooltip .tooltiptext {
width: 120px;
bottom: 100%;
left: 50%;
margin-left: -60px; /* Use half of the width (120/2 = 60), to center
the tooltip */
}
Flecha abajo
.tooltip .tooltiptext::after {
content: " ";
position: absolute;
top: 100%; /* At the bottom of the tooltip */
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: black transparent transparent transparent;
}
ejemplo Explicación
Coloque la flecha dentro de la descripción: top: 100% se coloque la flecha
en la parte inferior de la descripción. left: 50% se centrará en la flecha.
Top flecha
.tooltip .tooltiptext::after {
content: " ";
position: absolute;
bottom: 100%; /* At the top of the tooltip */
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent black transparent;
}
Resultado:
Flecha correcta
.tooltip .tooltiptext::after {
content: " ";
position: absolute;
top: 50%;
left: 100%; /* To the right of the tooltip */
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent transparent black;
}
.tooltip:hover .tooltiptext {
opacity: 1;
}
<!DOCTYPE html>
<html>
<style>
.tooltip {
position: relative;
display: inline-block;
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 100%;
left: 50%;
margin-left: -60px;
opacity: 0;
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
</style>
<body style="text-align:center;">
<p>When you move the mouse over the text below, the tooltip text will fade in and take 1 second
to go from completely invisible to visible.</p>
</div>
</body>
</html>
CSS Galería de imágenes
CSS se puede utilizar para crear una galería de imágenes.
Galería de imágenes
La siguiente galería de imágenes se crea con CSS:
Ejemplo
<html>
<head>
<style>
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
</style>
</head>
<body>
<div class="gallery">
<a target="_blank" href="fjords.jpg">
<img src="fjords.jpg" alt="Fjords" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="forest.jpg">
<img src="forest.jpg" alt="Forest" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="lights.jpg">
<img src="lights.jpg" alt="Northern Lights" width="300"height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="mountains.jpg">
<img src="mountains.jpg" alt="Mountains" width="300"height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</body>
</html>
Ejemplo
<!DOCTYPE html>
<html>
<head>
<style>
div.gallery {
div.gallery:hover {
div.gallery img {
width: 100%;
height: auto;
div.desc {
padding: 15px;
text-align: center;
*{
box-sizing: border-box;
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
.responsive {
width: 49.99999%;
margin: 6px 0;
.responsive {
width: 100%;
.clearfix:after {
content: "";
display: table;
clear: both;
</style>
</head>
<body>
<h2>Responsive Image Gallery</h2>
<div class="responsive">
<div class="gallery">
</a>
</div>
</div>
<div class="responsive">
<div class="gallery">
</a>
</div>
</div>
<div class="responsive">
<div class="gallery">
</a>
</div>
</div>
<div class="responsive">
<div class="gallery">
</a>
</div>
</div>
<div class="clearfix"></div>
<div style="padding:6px;">
<p>This example use media queries to re-arrange the images on different screen sizes: for
screens larger than 700px wide, it will show four images side by side, for screens smaller than
700px, it will show two images side by side. For screens smaller than 500px, the images will stack
vertically (100%).</p>
<p>You will learn more about media queries and responsive web design later in our CSS
Tutorial.</p>
</div>
</body>
</html>
Una página web con muchas imágenes puede tardar mucho tiempo en
cargar y genera múltiples peticiones al servidor.
Ejemplo
#home {
width: 46px;
height: 44px;
background: url(img_navsprites.gif) 0 0;
}
<!DOCTYPE html>
<html>
<head>
<style>
#home {
width: 46px;
height: 44px;
background: url(img_navsprites.gif) 0 0;
#next {
width: 43px;
height: 44px;
</style>
</head>
<body>
</body>
</html>
Ejemplo explicó:
Vamos a utilizar una lista HTML, ya que puede ser un enlace y también es
compatible con una imagen de fondo:
Ejemplo
#navlist {
position: relative;
}
#navlist li {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
top: 0;
}
#home {
left: 0px;
width: 46px;
background: url('img_navsprites.gif') 0 0;
}
#prev {
left: 63px;
width: 43px;
background: url('img_navsprites.gif') -47px 0;
}
#next {
left: 129px;
width: 43px;
background: url('img_navsprites.gif') -91px 0;
}
<!DOCTYPE html>
<html>
<head>
<style>
#navlist {
position: relative;
#navlist li {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
top: 0;
height: 44px;
display: block;
#home {
left: 0px;
width: 46px;
background: url('img_navsprites.gif') 0 0;
#prev {
left: 63px;
width: 43px;
#next {
left: 129px;
width: 43px;
</style>
</head>
<body>
<ul id="navlist">
</ul>
</body>
</html>
Ejemplo explicó:
Ejemplo
#home a:hover {
background: url('img_navsprites_hover.gif') 0 -45px;
}
#prev a:hover {
background: url('img_navsprites_hover.gif') -47px -45px;
}
#next a:hover {
background: url('img_navsprites_hover.gif') -91px -45px;
}
<!DOCTYPE html>
<html>
<head>
<style>
#navlist {
position: relative;
#navlist li {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
top: 0;
height: 44px;
display: block;
#home {
left: 0px;
width: 46px;
background: url('img_navsprites_hover.gif') 0 0;
#prev {
left: 63px;
width: 43px;
#next {
left: 129px;
width: 43px;
#home a:hover {
#prev a:hover {
#next a:hover {
</style>
</head>
<body>
<ul id="navlist">
<li id="home"><a href="default.asp"></a></li>
</ul>
</body>
</html>
Ejemplo explicó:
<!DOCTYPE html>
<html>
<head>
<style>
a[target] {
background-color: yellow;
</style>
</head>
<body>
<a href="https://www.w3schools.com">w3schools.com</a>
</body>
</html>
CSS [atributo = "valor"] Selector
El [attribute="value"] selector se utiliza para seleccionar elementos con
un atributo y valor especificado.
El ejemplo siguiente selecciona todos los elementos <a> con a = "_ blank"
atributo de destino:
Ejemplo
a[target="_blank"] {
background-color: yellow;
}
<!DOCTYPE html>
<html>
<head>
<style>
a[target=_blank] {
background-color: yellow;
</style>
</head>
<body>
<a href="https://www.w3schools.com">w3schools.com</a>
</body>
</html>
Ejemplo
[title~="flower"] {
border: 5px solid yellow;
}
<!DOCTYPE html>
<html>
<head>
<style>
[title~=flower] {
</style>
</head>
<body>
<p>All images with the title attribute containing the word "flower" get a yellow border.</p>
<img src="klematis.jpg" title="klematis flower" width="150" height="113">
</body>
</html>
Nota: El valor tiene que ser una palabra completa, ya sea solo, como class
= "top", o seguido por un guión (-), como class = "top-texto"!
Ejemplo
[class|="top"] {
background: yellow;
}
<!DOCTYPE html>
<html>
<head>
<style>
[class|=top] {
background: yellow;
</style>
</head>
<body>
<h1 class="top-header">Welcome</h1>
</body>
</html>
Ejemplo
[class^="top"] {
background: yellow;
}
<!DOCTYPE html>
<html>
<head>
<style>
[class^="top"] {
background: yellow;
</style>
</head>
<body>
<h1 class="top-header">Welcome</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
[class$="test"] {
background: yellow;
</style>
</head>
<body>
</body>
</html>
Ejemplo
[class*="te"] {
background: yellow;
}
<!DOCTYPE html>
<html>
<head>
<style>
[class*="te"] {
background: yellow;
</style>
</head>
<body>
</body>
</html>
Formas de estilo
Los selectores de atributos pueden ser útiles para las formas de peinado sin
clase o ID:
Ejemplo
input[type="text"] {
width: 150px;
display: block;
margin-bottom: 10px;
background-color: yellow;
}
input[type="button"] {
width: 120px;
margin-left: 35px;
display: block;
}
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 150px;
display: block;
margin-bottom: 10px;
background-color: yellow;
input[type=button] {
width: 120px;
margin-left: 35px;
display: block;
</style>
</head>
<body>
</form>
</body>
</html>
CSS Formas
El aspecto de un formulario HTML se puede mejorar en gran medida con
CSS:
El estilo de los campos de entrada
Usar la width propiedad para determinar la anchura del campo de entrada:
Ejemplo
input {
width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<style>
input {
width: 100%;
</style>
</head>
<body>
<form>
</form>
</body>
</html>
Entradas acolchados
Usar la padding propiedad de añadir espacio dentro del campo de texto.
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
margin: 8px 0;
box-sizing: border-box;
</style>
</head>
<body>
<p>Padded text fields:</p>
<form>
</form>
</body>
</html>
Entradas confinadas
Utilice la border propiedad para cambiar el tamaño y color del borde, y el
uso de la border-radius propiedad para añadir esquinas redondeadas:
Ejemplo
input[type=text] {
border: 2px solid red;
border-radius: 4px;
}
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
margin: 8px 0;
box-sizing: border-box;
border-radius: 4px;
</style>
</head>
<body>
<form>
</form>
</body>
</html>
Si sólo desea un borde inferior, utilice la border-bottom propiedad:
Ejemplo
input[type=text] {
border: none;
border-bottom: 2px solid red;
}
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
margin: 8px 0;
box-sizing: border-box;
border: none;
</style>
</head>
<body>
<p>Text fields with only a bottom border:</p>
<form>
</form>
</body>
</html>
Entradas de colores
Utilice la background-color propiedad para añadir un color de fondo a la
entrada, y la color propiedad para cambiar el color del texto:
Ejemplo
input[type=text] {
background-color: #3CBC8D;
color: white;
}
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
margin: 8px 0;
box-sizing: border-box;
border: none;
background-color: #3CBC8D;
color: white;
</style>
</head>
<body>
<form>
</form>
</body>
</html>
Entradas enfocadas
Por defecto, algunos navegadores añaden un borde azul alrededor de la
entrada cuando obtiene foco (clic en). Puede eliminar este comportamiento
mediante la adición outline: none; a la entrada.
Utilice el :focus selector para hacer algo con el campo de entrada cuando
se pone centrarse:
Ejemplo
input[type=text]:focus {
background-color:lightblue;
}
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid #555;
outline: none;
}
input[type=text]:focus {
background-color: lightblue;
}
</style>
</head>
<body>
<p>In this example, we use the :focus selector to add a background color to the text field when it
gets focused (clicked on):</p>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" value="John">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname" value="Doe">
</form>
</body>
</html>
Ejemplo
input[type=text]:focus {
border: 3px solid #555;
}
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: 3px solid #ccc;
-webkit-transition: 0.5s;
transition: 0.5s;
outline: none;
}
input[type=text]:focus {
border: 3px solid #555;
}
</style>
</head>
<body>
<p>In this example, we use the :focus selector to add a black border color to the text field when it
gets focused (clicked on):</p>
<p>Note that we have added the CSS3 transition property to animate the border color (takes 0.5
seconds to change the color on focus).</p>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" value="John">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname" value="Doe">
</form>
</body>
</html>
Entrada icono / imagen con
Si quieres un icono dentro de la entrada, utilice la background-image
propiedad y posicionarlo con la background-position propiedad. También
notamos que añadimos un gran relleno a la izquierda para reservar el
espacio del icono:
Ejemplo
input[type=text] {
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding-left: 40px;
}
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 100%;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
}
</style>
</head>
<body>
</body>
</html>
Ejemplo
input[type=text] {
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
</style>
</head>
<body>
<form>
<input type="text" name="search" placeholder="Search..">
</form>
</body>
</html>
Styling Textareas
Consejo: Utilice la resize propiedad para evitar áreas de texto sea
reducida (desactivar el "capturador" en la esquina inferior derecha):
Ejemplo
textarea {
width: 100%;
height: 150px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
resize: none;
}
<!DOCTYPE html>
<html>
<head>
<style>
textarea {
width: 100%;
height: 150px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
font-size: 16px;
resize: none;
}
</style>
</head>
<body>
<p><strong>Tip:</strong> Use the resize property to prevent textareas from being resized (disable
the "grabber" in the bottom right corner):</p>
<form>
<textarea>Some text...</textarea>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
select {
width: 100%;
padding: 16px 20px;
border: none;
border-radius: 4px;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<form>
<select id="country" name="country">
<option value="au">Australia</option>
<option value="ca">Canada</option>
<option value="usa">USA</option>
</select>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
input[type=button], input[type=submit], input[type=reset] {
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body>
</body>
</html>
CSS Contadores
Ejemplo
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
<!DOCTYPE html>
<html>
<head>
<style>
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
</style>
</head>
<body>
</body>
</html>
Contadores de anidación
El ejemplo siguiente crea un contador para la página (sección) y un
contador para cada <h1> elemento (subsección). La "sección" contador se
cuenta para cada elemento <h1> con "Sección < valor de la sección de
contador >.", Y el contador "subsección" se contará para cada uno <h2>
elemento con "< valor de la sección de contador >. < valor del contador de
la subsección > ":
Ejemplo
body {
counter-reset: section;
}
h1 {
counter-reset: subsection;
}
h1::before {
counter-increment: section;
content: "Section " counter(section) ". ";
}
h2::before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
<!DOCTYPE html>
<html>
<head>
<style>
body {
counter-reset: section;
}
h1 {
counter-reset: subsection;
}
h1::before {
counter-increment: section;
content: "Section " counter(section) ". ";
}
h2::before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
</style>
</head>
<body>
<h1>HTML tutorials:</h1>
<h2>HTML Tutorial</h2>
<h2>CSS Tutorial</h2>
<h1>Scripting tutorials:</h1>
<h2>JavaScript</h2>
<h2>VBScript</h2>
<h1>XML tutorials:</h1>
<h2>XML</h2>
<h2>XSL</h2>
</body>
</html>
Un contador también puede ser útil para hacer listas descritas porque una
nueva instancia de un contador se crea automáticamente en elementos
secundarios. Aquí se utiliza la counters() función para insertar una
cadena entre los diferentes niveles de contadores anidados:
Ejemplo
ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
}
<!DOCTYPE html>
<html>
<head>
<style>
ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
}
</style>
</head>
<body>
<ol>
<li>item</li>
<li>item
<ol>
<li>item</li>
<li>item</li>
<li>item
<ol>
<li>item</li>
<li>item</li>
<li>item</li>
</ol>
</li>
<li>item</li>
</ol>
</li>
<li>item</li>
<li>item</li>
</ol>
<ol>
<li>item</li>
<li>item</li>
</ol>
</body>
</html>
Property Description
content Used with the ::before and ::after pseudo-elements, to
insert generated content
Módulos CSS3
CSS3 se ha dividido en "módulos". Contiene la "antigua especificación CSS"
(que se ha dividido en piezas más pequeñas). Además, se agregan nuevos
módulos.
Selectores
Modelo de caja
Fondos y fronteras
Valores de imagen y contenido reemplazado
Efectos de texto
Transformaciones 2D / 3D
Animaciones
Múltiples Columnas
Interfaz de usuario
Ejemplo
#rcorners1 {
border-radius: 25px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners2 {
border-radius: 25px;
border: 2px solid #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners3 {
border-radius: 25px;
background: url(paper.gif);
background-position: left top;
background-repeat: repeat;
padding: 20px;
width: 200px;
height: 150px;
}
<!DOCTYPE html>
<html>
<head>
<style>
#rcorners1 {
border-radius: 25px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
#rcorners2 {
border-radius: 25px;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners3 {
border-radius: 25px;
background: url(paper.gif);
background-repeat: repeat;
padding: 20px;
width: 200px;
height: 150px;
</style>
</head>
<body>
</body>
</html>
Consejo: La border-radius propiedad es en realidad una propiedad
resumida de los border-top-left-radius, border-top-right-
radius, border-bottom-right-radius y border-bottom-left-radius
propiedades.
Sin embargo, puede especificar cada esquina por separado si lo desea. Aquí
están las reglas:
Ejemplo
#rcorners4 {
border-radius: 15px 50px 30px 5px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners5 {
border-radius: 15px 50px 30px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners6 {
border-radius: 15px 50px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
<!DOCTYPE html>
<html>
<head>
<style>
#rcorners4 {
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
#rcorners5 {
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
#rcorners6 {
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
</style>
</head>
<body>
<p id="rcorners4"></p>
<p id="rcorners5"></p>
<p id="rcorners6"></p>
</body>
</html>
También podría crear esquinas elípticas:
Ejemplo
#rcorners7 {
border-radius: 50px/15px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners8 {
border-radius: 15px/50px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners9 {
border-radius: 50%;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
<!DOCTYPE html>
<html>
<head>
<style>
#rcorners7 {
border-radius: 50px/15px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
#rcorners8 {
border-radius: 15px/50px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
#rcorners9 {
border-radius: 50%;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
</style>
</head>
<body>
<p id="rcorners7"></p>
<p>Elliptical border - border-radius: 15px/50px:</p>
<p id="rcorners8"></p>
<p id="rcorners9"></p>
</body>
</html>
Property Description
Ejemplo
#borderimg {
border: 10px solid transparent;
padding: 15px;
-webkit-border-image: url(border.png) 30 round; /* Safari 3.1-5 */
-o-border-image: url(border.png) 30 round; /* Opera 11-12.1 */
border-image: url(border.png) 30 round;
}
<!DOCTYPE html>
<html>
<head>
<style>
#borderimg {
padding: 15px;
</style>
</head>
<body>
<p>The border-image property specifies an image to be used as the border around an
element:</p>
<p id="borderimg">Here, the middle sections of the image are repeated to create the border.</p>
<p><strong>Note:</strong> Internet Explorer 10, and earlier versions, do not support the border-
image property.</p>
</body>
</html>
Ejemplo
#borderimg {
border: 10px solid transparent;
padding: 15px;
-webkit-border-image: url(border.png) 30 stretch; /* Safari 3.1-5 */
-o-border-image: url(border.png) 30 stretch; /* Opera 11-12.1 */
border-image: url(border.png) 30 stretch;
}
<!DOCTYPE html>
<html>
<head>
<style>
#borderimg {
border: 10px solid transparent;
padding: 15px;
</style>
</head>
<body>
<p id="borderimg">Here, the middle sections of the image are stretched to create the border.</p>
<p><strong>Note:</strong> Internet Explorer 10, and earlier versions, do not support the border-
image property.</p>
</body>
</html>
#borderimg2 {
border: 10px solid transparent;
padding: 15px;
-webkit-border-image: url(border.png) 20% round; /* Safari 3.1-5 */
-o-border-image: url(border.png) 20% round; /* Opera 11-12.1 */
border-image: url(border.png) 20% round;
}
#borderimg3 {
border: 10px solid transparent;
padding: 15px;
-webkit-border-image: url(border.png) 30% round; /* Safari 3.1-5 */
-o-border-image: url(border.png) 30% round; /* Opera 11-12.1 */
border-image: url(border.png) 30% round;
}
<!DOCTYPE html>
<html>
<head>
<style>
#borderimg1 {
padding: 15px;
#borderimg2 {
padding: 15px;
#borderimg3 {
padding: 15px;
</style>
</head>
<body>
<p><strong>Note:</strong> Internet Explorer 10, and earlier versions, do not support the border-
image property.</p>
</body>
</html>
Property Description
Fondos de CSS3
CSS3 fondos múltiples
CSS3 le permite agregar varias imágenes de fondo para un elemento, a
través de la background-image propiedad.
Ejemplo
#example1 {
background-image: url(img_flwr.gif), url(paper.gif);
background-position: right bottom, left top;
background-repeat: no-repeat, repeat;
}
<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
padding: 15px;
</style>
</head>
<body>
<div id="example1">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
Ejemplo
#example1 {
background: url(img_flwr.gif) right bottom no-repeat, url(paper.gif)
left top repeat;
}
<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
padding: 15px;
</style>
</head>
<body>
<div id="example1">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
Ejemplo
#div1 {
background: url(img_flower.jpg);
background-size: 100px 80px;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
background:url(img_flwr.gif);
background-repeat: no-repeat;
padding:15px;
#example2 {
background:url(img_flwr.gif);
background-repeat: no-repeat;
padding:15px;
</style>
</head>
<body>
<p>Original background-image:</p>
<div id="example1">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat.</p>
</div>
<p>Resized background-image:</p>
<div id="example2">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
La contain palabra clave escala la imagen de fondo para que sea lo más
grande posible (pero tanto su ancho como su altura deben ajustarse dentro
del área de contenido). Como tal, dependiendo de las proporciones de la
imagen de fondo y del área de posicionamiento de fondo, pueden existir
algunas áreas del fondo que no están cubiertas por la imagen de fondo.
Ejemplo
#div1 {
background: url(img_flower.jpg);
background-size: contain;
background-repeat: no-repeat;
}
#div2 {
background: url(img_flower.jpg);
background-size: cover;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html>
<head>
<style>
.div1 {
height:150px;
width:180px;
background:url(img_flwr.gif);
background-repeat: no-repeat;
.div2 {
width:180px;
background:url(img_flwr.gif);
background-repeat: no-repeat;
background-size: contain;
.div3 {
height:150px;
width:180px;
background:url(img_flwr.gif);
background-repeat: no-repeat;
background-size: cover;
</style>
</head>
<body>
<p>Original image:</p>
<div class="div1">
</div>
<div class="div2">
<p>Lorem ipsum dolor sit amet.</p>
</div>
<div class="div3">
</div>
</body>
</html>
Ejemplo
#example1 {
background: url(img_flwr.gif) left top no-repeat, url(img_flwr.gif)
right bottom no-repeat, url(paper.gif) left top repeat;
background-size: 50px, 130px, auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
padding: 15px;
</style>
</head>
<body>
<div id="example1">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>
Ejemplo
html {
background: url(img_flower.jpg) no-repeat center fixed;
background-size: cover;
}
<!DOCTYPE html>
<html>
<head>
<style>
html {
background-size: cover;
body {
color: white;
</style>
</head>
<body>
<h1>Full Page Background Image</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis
nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</body>
</html>
Ejemplo
#example1 {
border: 10px solid black;
padding: 35px;
background: url(img_flwr.gif);
background-repeat: no-repeat;
background-origin: content-box;
}
<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
padding: 35px;
background: url(img_flwr.gif);
background-repeat: no-repeat;
#example2 {
padding: 35px;
background: url(img_flwr.gif);
background-repeat: no-repeat;
background-origin: border-box;
#example3 {
padding: 35px;
background: url(img_flwr.gif);
background-repeat: no-repeat;
background-origin: content-box;
</style>
</head>
<body>
<div id="example1">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat.</p>
</div>
<p>background-origin: border-box:</p>
<div id="example2">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat.</p>
</div>
<p>background-origin: content-box:</p>
<div id="example3">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat.</p>
</div>
</body>
</html>ç
Ejemplo
#example1 {
border: 10px dotted black;
padding: 35px;
background: yellow;
background-clip: content-box;
}
<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
background: yellow;
#example2 {
padding:35px;
background: yellow;
background-clip: padding-box;
#example3 {
padding:35px;
background: yellow;
background-clip: content-box;
</style>
</head>
<body>
<div id="example1">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
</div>
<p>background-clip: padding-box:</p>
<div id="example2">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
</div>
<p>background-clip: content-box:</p>
<div id="example3">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
</div>
</body>
</html>
Property Description
CSS3 Colores
CSS3 Colores
CSS admite nombres de color, hexadecimal y colores RGB.
Colores RGBA
Colores HSL
Colores HSLA
opacidad
Colores RGBA
Los valores de color RGBA son una extensión de valores de color RGB con
un canal alfa, que especifica la opacidad de un color.
Un valor de color RGBA se especifica con: rgba (rojo, verde, azul, alfa). El
parámetro alfa es un número entre 0,0 (totalmente transparente) y 1,0
(completamente opaco).
Ejemplo
#p1 {background-color: rgba(255, 0, 0, 0.3);} /* red with opacity */
#p2 {background-color: rgba(0, 255, 0, 0.3);} /* green with opacity */
#p3 {background-color: rgba(0, 0, 255, 0.3);} /* blue with opacity */
<!DOCTYPE html>
<html>
<head>
<style>
#p1 {background-color:rgba(255,0,0,0.3);}
#p2 {background-color:rgba(0,255,0,0.3);}
#p3 {background-color:rgba(0,0,255,0.3);}
#p4 {background-color:rgba(192,192,192,0.3);}
#p5 {background-color:rgba(255,255,0,0.3);}
#p6 {background-color:rgba(255,0,255,0.3);}
</style>
</head>
<body>
<p>RGBA colors:</p>
<p id="p1">Red</p>
<p id="p2">Green</p>
<p id="p3">Blue</p>
<p id="p4">Grey</p>
<p id="p5">Yellow</p>
<p id="p6">Cerise</p>
</body>
</html>
Colores HSL
HSL significa tono, saturación y ligereza.
<!DOCTYPE html>
<html>
<head>
<style>
#p1 {background-color:hsl(120,100%,50%);}
#p2 {background-color:hsl(120,100%,75%);}
#p3 {background-color:hsl(120,100%,25%);}
#p4 {background-color:hsl(120,60%,70%);}
#p5 {background-color:hsl(290,100%,50%);}
#p6 {background-color:hsl(290,60%,70%);}
</style>
</head>
<body>
<p>HSL colors:</p>
<p id="p1">Green</p>
<p id="p5">Violet</p>
</body>
</html>
Colores HSLA
Los valores de color HSLA son una extensión de los valores de color HSL
con un canal alfa - que especifica la opacidad de un color.
<!DOCTYPE html>
<html>
<head>
<style>
#p1 {background-color:hsla(120,100%,50%,0.3);}
#p2 {background-color:hsla(120,100%,75%,0.3);}
#p3 {background-color:hsla(120,100%,25%,0.3);}
#p4 {background-color:hsla(120,60%,70%,0.3);}
#p5 {background-color:hsla(290,100%,50%,0.3);}
#p6 {background-color:hsla(290,60%,70%,0.3);}
</style>
</head>
<body>
<p>HSLA colors:</p>
<p id="p1">Green</p>
</body>
</html>
Opacidad
La opacity propiedad CSS3 establece la opacidad de todo el elemento
(tanto el color de fondo como el texto serán opacos / transparentes).
Ejemplo
#p1 {background-color:rgb(255,0,0);opacity:0.6;} /* red with opacity */
#p2 {background-color:rgb(0,255,0);opacity:0.6;} /* green with opacity
*/
#p3 {background-color:rgb(0,0,255);opacity:0.6;} /* blue with opacity */
<!DOCTYPE html>
<html>
<head>
<style>
#p1 {background-color:rgb(255,0,0);opacity:0.6;}
#p2 {background-color:rgb(0,255,0);opacity:0.6;}
#p3 {background-color:rgb(0,0,255);opacity:0.6;}
#p4 {background-color:rgb(192,192,192);opacity:0.6;}
#p5 {background-color:rgb(255,255,0);opacity:0.6;}
#p6 {background-color:rgb(255,0,255);opacity:0.6;}
</style>
</head>
<body>
<p id="p1">Red</p>
<p id="p2">Green</p>
<p id="p3">Blue</p>
<p id="p4">Grey</p>
<p id="p5">Yellow</p>
<p id="p6">Cerise</p>
</body>
</html>
CSS3 Gradientes
Los gradientes CSS3 permiten mostrar transiciones suaves entre dos o más
colores especificados.
Anteriormente, había que usar imágenes para estos efectos. Sin embargo,
mediante el uso de gradientes CSS3 puede reducir el tiempo de descarga y
el uso de ancho de banda. Además, los elementos con degradados se ven
mejor cuando se amplían, ya que el degradado es generado por el
navegador.
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(red, yellow); /* For Safari 5.1
to 6.0 */
background: -o-linear-gradient(red, yellow); /* For Opera 11.1 to
12.0 */
background: -moz-linear-gradient(red, yellow); /* For Firefox 3.6 to
15 */
background: linear-gradient(red, yellow); /* Standard syntax */
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 200px;
</style>
</head>
<body>
<p>This linear gradient starts at the top. It starts red, transitioning to yellow:</p>
<div id="grad1"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 200px;
</style>
</head>
<body>
<h3>Linear Gradient - Left to Right</h3>
<p>This linear gradient starts at the left. It starts red, transitioning to yellow:</p>
<div id="grad1"></div>
</body>
</html>
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(left top, red, yellow);/* For
Safari 5.1 to 6.0 */
background: -o-linear-gradient(bottom right, red, yellow);/* For Opera
11.1 to 12.0 */
background: -moz-linear-gradient(bottom right, red, yellow);/* For
Firefox 3.6 to 15 */
background: linear-gradient(to bottom right, red, yellow);/* Standard
syntax */
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 200px;
background: linear-gradient(to bottom right, red, yellow); /* Standard syntax (must be last) */
</style>
</head>
<body>
<p>This linear gradient starts at top left. It starts red, transitioning to yellow:</p>
<div id="grad1"></div>
</html>
Uso de ángulos
Si desea más control sobre la dirección del gradiente, puede definir un
ángulo, en lugar de las direcciones predefinidas (abajo, arriba, derecha,
izquierda, abajo a la derecha, etc.).
Sintaxis
background: linear-gradient(angle, color-stop1, color-stop2);
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(-90deg, red, yellow); /* For Safari
5.1 to 6.0 */
background: -o-linear-gradient(-90deg, red, yellow); /* For Opera 11.1
to 12.0 */
background: -moz-linear-gradient(-90deg, red, yellow); /* For Firefox
3.6 to 15 */
background: linear-gradient(-90deg, red, yellow); /* Standard syntax */
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 100px;
#grad2 {
height: 100px;
#grad3 {
height: 100px;
#grad4 {
height: 100px;
</style>
</head>
<body>
</body>
</html>
Uso de múltiples paradas de color
El siguiente ejemplo muestra un gradiente lineal (de arriba a abajo) con
múltiples paradas de color:
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(red, yellow, green); /* For Safari
5.1 to 6.0 */
background: -o-linear-gradient(red, yellow, green); /* For Opera 11.1
to 12.0 */
background: -moz-linear-gradient(red, yellow, green); /* For Firefox
3.6 to 15 */
background: linear-gradient(red, yellow, green); /* Standard syntax */
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 200px;
#grad2 {
height: 200px;
background: -webkit-linear-gradient(red, orange, yellow, green, blue, indigo, violet); /* For Safari
5.1 to 6.0 */
background: -o-linear-gradient(red, orange, yellow, green, blue, indigo, violet); /* For Opera 11.1
to 12.0 */
background: -moz-linear-gradient(red, orange, yellow, green, blue, indigo, violet); /* For Firefox
3.6 to 15 */
background: linear-gradient(red, orange, yellow, green, blue, indigo, violet); /* Standard syntax
(must be last) */
#grad3 {
height: 200px;
background: -webkit-linear-gradient(red 10%, green 85%, blue 90%); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(red 10%, green 85%, blue 90%); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(red 10%, green 85%, blue 90%); /* For Firefox 3.6 to 15 */
background: linear-gradient(red 10%, green 85%, blue 90%); /* Standard syntax (must be last) */
</style>
</head>
<body>
<div id="grad2"></div>
<div id="grad3"></div>
<p><strong>Note:</strong> Color stops are automatically spaced evenly when no percents are
specified.</p>
</body>
</html>
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
/* For Safari 5.1 to 6.0 */
background: -webkit-linear-
gradient(left,red,orange,yellow,green,blue,indigo,violet);
/* For Opera 11.1 to 12.0 */
background: -o-linear-
gradient(left,red,orange,yellow,green,blue,indigo,violet);
/* For Fx 3.6 to 15 */
background: -moz-linear-
gradient(left,red,orange,yellow,green,blue,indigo,violet);
/* Standard syntax */
background: linear-gradient(to right,
red,orange,yellow,green,blue,indigo,violet);
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 55px;
background: -webkit-linear-gradient(left, red, orange, yellow, green, blue, indigo, violet); /* For
Safari 5.1 to 6.0 */
background: -o-linear-gradient(left, red, orange, yellow, green, blue, indigo, violet); /* For Opera
11.1 to 12.0 */
background: -moz-linear-gradient(left, red, orange, yellow, green, blue, indigo, violet); /* For Fx
3.6 to 15 */
background: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet); /* Standard
syntax (must be last) */
</style>
</head>
<body>
Gradient Background
</div>
</body>
</html>
Uso de la transparencia
Los gradientes CSS3 también admiten la transparencia, que puede
utilizarse para crear efectos de atenuación.
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
background: -webkit-linear-
gradient(left,rgba(255,0,0,0),rgba(255,0,0,1)); /*Safari 5.1-6*/
background: -o-linear-
gradient(right,rgba(255,0,0,0),rgba(255,0,0,1)); /*Opera 11.1-12*/
background: -moz-linear-
gradient(right,rgba(255,0,0,0),rgba(255,0,0,1)); /*Fx 3.6-15*/
background: linear-gradient(to right, rgba(255,0,0,0),
rgba(255,0,0,1)); /*Standard*/
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 200px;
</style>
</head>
<body>
<p>To add transparency, we use the rgba() function to define the color stops. The last parameter
in the rgba() function can be a value from 0 to 1, and it defines the transparency of the color: 0
indicates full transparency, 1 indicates full color (no transparency).</p>
<div id="grad1"></div>
</body>
</html>
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
/* Safari 5.1 to 6.0 */
background: -webkit-repeating-linear-gradient(red, yellow 10%, green
20%);
/* Opera 11.1 to 12.0 */
background: -o-repeating-linear-gradient(red, yellow 10%, green 20%);
/* Firefox 3.6 to 15 */
background: -moz-repeating-linear-gradient(red, yellow 10%, green 20%);
/* Standard syntax */
background: repeating-linear-gradient(red, yellow 10%, green 20%);
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 200px;
background: -o-repeating-linear-gradient(red, yellow 10%, green 20%); /* For Opera 11.1 to 12.0
*/
#grad2 {
height: 200px;
#grad3 {
height: 200px;
background: -webkit-repeating-linear-gradient(190deg,red,yellow 7%,green 10%); /* For Safari 5.1
to 6.0 */
#grad4 {
height: 200px;
</style>
</head>
<body>
<div id="grad1"></div>
<p>A repeating gradient on 45deg axe starting red and finishing green:</p>
<div id="grad2"></div>
<p>A repeating gradient on 190deg axe starting red and finishing green:</p>
<div id="grad3"></div>
<p>A repeating gradient on 90deg axe starting red and finishing green:</p>
<div id="grad4"></div>
</body>
</html>
Para crear un gradiente radial también debe definir al menos dos paradas
de color.
Sintaxis
background: radial-gradient(shape size at position, start-color, ...,
last-color);
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
background: -webkit-radial-gradient(red, yellow, green); /* Safari 5.1
to 6.0 */
background: -o-radial-gradient(red, yellow, green); /* For Opera 11.6
to 12.0 */
background: -moz-radial-gradient(red, yellow, green); /* For Firefox
3.6 to 15 */
background: radial-gradient(red, yellow, green); /* Standard syntax */
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 150px;
width: 200px;
</style>
</head>
<body>
<div id="grad1"></div>
</body>
</html>
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
background: -webkit-radial-gradient(red 5%, yellow 15%, green 60%); /*
Safari 5.1-6.0 */
background: -o-radial-gradient(red 5%, yellow 15%, green 60%); /* For
Opera 11.6-12.0 */
background: -moz-radial-gradient(red 5%, yellow 15%, green 60%); /* For
Firefox 3.6-15 */
background: radial-gradient(red 5%, yellow 15%, green 60%);/* Standard
syntax */
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 150px;
width: 200px;
background: -o-radial-gradient(red 5%, yellow 15%, green 60%); /* For Opera 11.6 to 12.0 */
background: -moz-radial-gradient(red 5%, yellow 15%, green 60%); /* For Firefox 3.6 to 15 */
background: radial-gradient(red 5%, yellow 15%, green 60%); /* Standard syntax (must be last) */
</style>
</head>
<body>
<div id="grad1"></div>
</html>
Establecer la forma
El parámetro de forma define la forma. Puede tomar el valor círculo o
elipse. El valor predeterminado es elipse.
Ejemplo
#grad {
background: red; /* For browsers that do not support gradients */
background: -webkit-radial-gradient(circle, red, yellow, green); /*
Safari */
background: -o-radial-gradient(circle, red, yellow, green);/* Opera
11.6 to 12.0 */
background: -moz-radial-gradient(circle, red, yellow, green); /*
Firefox 3.6 to 15 */
background: radial-gradient(circle, red, yellow, green); /* Standard
syntax */
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 150px;
width: 200px;
#grad2 {
height: 150px;
width: 200px;
</style>
</head>
<body>
<h3>Radial Gradient - Shapes</h3>
<div id="grad1"></div>
<p><strong>Circle:</strong></p>
<div id="grad2"></div>
</body>
</html>
Ejemplo
Un gradiente radial con diferentes palabras clave de tamaño:
#grad1 {
background: red; /* For browsers that do not support gradients */
/* Safari 5.1 to 6.0 */
background: -webkit-radial-gradient(60% 55%, closest-side, red, yellow,
black);
/* For Opera 11.6 to 12.0 */
background: -o-radial-gradient(60% 55%, closest-side, red, yellow,
black);
/* For Firefox 3.6 to 15 */
background: -moz-radial-gradient(60% 55%, closest-side, red, yellow,
black);
/* Standard syntax */
background: radial-gradient(closest-side at 60% 55%, red, yellow,
black);
}
#grad2 {
/* Safari 5.1 to 6.0 */
background: -webkit-radial-gradient(60% 55%, farthest-side, red,
yellow, black);
/* Opera 11.6 to 12.0 */
background: -o-radial-gradient(60% 55%, farthest-side, red, yellow,
black);
/* For Firefox 3.6 to 15 */
background: -moz-radial-gradient(60% 55%, farthest-side, red, yellow,
black);
/* Standard syntax */
background: radial-gradient(farthest-side at 60% 55%, red, yellow,
black);
}
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 150px;
width: 150px;
background: -webkit-radial-gradient(60% 55%, closest-side, red, yellow, black); /* Safari 5.1 to 6.0
*/
background: -o-radial-gradient(60% 55%, closest-side, red, yellow, black); /* For Opera 11.6 to
12.0 */
background: -moz-radial-gradient(60% 55%, closest-side, red, yellow, black); /* For Firefox 3.6 to
15 */
background: radial-gradient(closest-side at 60% 55%, red, yellow, black); /* Standard syntax (must
be last) */
#grad2 {
height: 150px;
width: 150px;
background: -webkit-radial-gradient(60% 55%, farthest-side, red, yellow, black); /* Safari 5.1 to 6.0
*/
background: -o-radial-gradient(60% 55%, farthest-side, red, yellow, black); /* For Opera 11.6 to
12.0 */
background: -moz-radial-gradient(60% 55%, farthest-side, red, yellow, black); /* For Firefox 3.6 to
15 */
#grad3 {
height: 150px;
width: 150px;
background: -moz-radial-gradient(60% 55%, closest-corner, red, yellow, black); /* For Firefox 3.6
to 15 */
#grad4 {
height: 150px;
width: 150px;
background: -o-radial-gradient(60% 55%, farthest-corner, red, yellow, black); /* For Opera 11.6 to
12.0 */
background: -moz-radial-gradient(60% 55%, farthest-corner, red, yellow, black); /* For Firefox 3.6
to 15 */
</style>
</head>
<body>
<p><strong>closest-side:</strong></p>
<div id="grad1"></div>
<p><strong>farthest-side:</strong></p>
<div id="grad2"></div>
<p><strong>closest-corner:</strong></p>
<div id="grad3"></div>
<div id="grad4"></div>
</body>
</html>
Ejemplo
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 150px;
width: 200px;
background: -o-repeating-radial-gradient(red, yellow 10%, green 15%); /* For Opera 11.6 to 12.0
*/
</style>
</head>
<body>
<h3>Repeating Radial Gradient</h3>
<div id="grad1"></div>
</body>
</html>
text-shadow
box-shadow
Sombra de texto CSS3
La text-shadow propiedad CSS3 aplica sombra al texto.
Ejemplo
h1 {
text-shadow: 2px 2px;
}
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
<p><b>Note:</b> Internet Explorer 9 and earlier versions, do not support the text-shadow
property.</p>
</body>
</html>
Ejemplo
h1 {
text-shadow: 2px 2px red;
}
Ejemplo
h1 {
text-shadow: 2px 2px 5px red;
}
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
<p><b>Note:</b> Internet Explorer 9 and earlier versions, do not support the text-shadow
property.</p>
</body>
</html>
Ejemplo
h1 {
color: white;
text-shadow: 2px 2px 4px #000000;
}
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: white;
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
<p><b>Note:</b> Internet Explorer 9 and earlier versions, do not support the text-shadow
property.</p>
</body>
</html>
Ejemplo
h1 {
text-shadow: 0 0 3px #FF0000;
}
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
<p><b>Note:</b> Internet Explorer 9 and earlier versions, do not support the text-shadow
property.</p>
</body>
</html>
Sombras múltiples
Para agregar más de una sombra al texto, puede agregar una lista de
sombras separada por comas.
Ejemplo
h1 {
text-shadow: 0 0 3px #FF0000, 0 0 5px #0000FF;
}
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
<p><b>Note:</b> Internet Explorer 9 and earlier versions, do not support the text-shadow
property.</p>
</body>
</html>
Ejemplo
h1 {
color: white;
text-shadow: 1px 1px 2px black, 0 0 25px blue, 0 0 5px darkblue;
}
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: white;
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
<p><b>Note:</b> Internet Explorer 9 and earlier versions, do not support the text-shadow
property.</p>
</body>
</html>
Ejemplo
h1 {
color: yellow;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
padding: 15px;
background-color: yellow;
</style>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
padding: 15px;
background-color: yellow;
</style>
</head>
<body>
</body>
</html>
Ejemplo
div {
box-shadow: 10px 10px 5px grey;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
padding: 15px;
background-color: yellow;
</style>
</head>
<body>
</html>
Ejemplo
#boxshadow {
position: relative;
box-shadow: 1px 2px 4px rgba(0, 0, 0, .5);
padding: 10px;
background: white;
}
#boxshadow img {
width: 100%;
border: 1px solid #8a4419;
border-style: inset;
}
#boxshadow::after {
content: '';
position: absolute;
z-index: -1; /* hide shadow behind image */
box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3);
width: 70%;
left: 15%; /* one half of the remaining 30% */
height: 100px;
bottom: 0;
}
<!DOCTYPE html>
<html>
<head>
<style>
#boxshadow {
position: relative;
padding: 10px;
background: white;
#boxshadow img {
width: 100%;
border-style: inset;
#boxshadow::after {
content: '';
position: absolute;
width: 70%;
height: 100px;
bottom: 0;
</style>
</head>
<body>
<div id="boxshadow">
</div>
</body>
</html>
Divertido Tarjetas
Un ejemplo de uso de la box-shadow propiedad para crear tarjetas
similares a papel:
Ejemplo
div.card {
width: 250px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0,
0, 0.19);
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<style>
div.card {
width: 250px;
text-align: center;
div.header {
background-color: #4CAF50;
color: white;
padding: 10px;
font-size: 40px;
div.container {
padding: 10px;
}
</style>
</head>
<body>
<h2>Cards</h2>
<div class="card">
<div class="header">
<h1>1</h1>
</div>
<div class="container">
<p>January 1, 2016</p>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div.polaroid {
width: 250px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-align: center;
div.container {
padding: 10px;
</style>
</head>
<body>
<div class="polaroid">
<div class="container">
<p>Hardanger, Norway</p>
</div>
</div>
</body>
</html>
Propiedades de sombra de CSS3
En la tabla siguiente se enumeran las propiedades de sombra de CSS3:
Property Description
Texto CSS3
CSS3 contiene varias nuevas características de texto.
text-overflow
word-wrap
word-break
Se puede recortar:
Ejemplo
p.test1 {
white-space: nowrap;
width: 200px;
border: 1px solid #000000;
overflow: hidden;
text-overflow: clip;
}
p.test2 {
white-space: nowrap;
width: 200px;
border: 1px solid #000000;
overflow: hidden;
text-overflow: ellipsis;
}
<!DOCTYPE html>
<html>
<head>
<style>
p.test1 {
white-space: nowrap;
width: 200px;
overflow: hidden;
text-overflow: clip;
p.test2 {
white-space: nowrap;
width: 200px;
overflow: hidden;
text-overflow: ellipsis;
</style>
</head>
<body>
<p>The following two paragraphs contains a long text that will not fit in the box.</p>
<p>text-overflow: clip:</p>
<p class="test1">This is some long text that will not fit in the box</p>
<p>text-overflow: ellipsis:</p>
<p class="test2">This is some long text that will not fit in the box</p>
</body>
</html>
<html>
<head>
<style>
div.test {
white-space: nowrap;
width: 200px;
overflow: hidden;
div.test:hover {
text-overflow: inherit;
overflow: visible;
</style>
</head>
<body>
<p>Hover over the two divs below, to see the entire text.</p>
<div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the
box</div>
<br>
<div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div>
</body>
</html>
Ejemplo
Permita que las palabras largas puedan romperse y encajar en la siguiente
línea:
p {
word-wrap: break-word;
}
<!DOCTYPE html>
<html>
<head>
<style>
p.test {
width: 11em;
word-wrap: break-word;
</style>
</head>
<body>
</body>
</html>
p.test2 {
word-break: break-all;
}
<!DOCTYPE html>
<html>
<head>
<style>
p.test1 {
width: 140px;
word-break: keep-all;
p.test2 {
width: 140px;
word-break: break-all;
</style>
</head>
<body>
<p class="test1">This paragraph contains some text. This line will-break-at-hyphens.</p>
<p class="test2">This paragraph contains some text. The lines will break at any character.</p>
<p><b>Note:</b> The word-break property is not supported in Opera 12 and earlier versions.</p>
</body>
</html>
Property Description
Las fuentes SVG permiten que SVG se utilice como glifos al mostrar
texto. La especificación SVG 1.1 define un módulo de fuente que permite la
creación de fuentes dentro de un documento SVG. También puede aplicar
CSS a documentos SVG y la regla @ font-face puede aplicarse al texto en
documentos SVG.
Las fuentes EOT son una forma compacta de fuentes OpenType diseñadas
por Microsoft para su uso como fuentes incrustadas en páginas web.
div {
font-family: myFirstFont;
}
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: myFirstFont;
src: url(sansation_light.woff);
div {
font-family: myFirstFont;
</style>
</head>
<body>
<div>
With CSS3, websites can finally use fonts other than the pre-selected "web-safe" fonts.
</div>
<p><b>Note:</b> Internet Explorer 8 and earlier, do not support the @font-face rule.</p>
</body>
</html>
Ejemplo
@font-face {
font-family: myFirstFont;
src: url(sansation_bold.woff);
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: myFirstFont;
src: url(sansation_light.woff);
@font-face {
font-family: myFirstFont;
src: url(sansation_bold.woff);
font-weight: bold;
div {
font-family: myFirstFont;
</style>
</head>
<body>
<div>
With CSS3, websites can <b>finally</b> use fonts other than the pre-selected "web-safe" fonts.
</div>
<p><b>Note:</b> Internet Explorer 8 and earlier, do not support the @font-face rule.</p>
</body>
</html>
Los navegadores utilizarán esto siempre que una parte de texto con la
familia de fuentes "myFirstFont" deba mostrarse en negrita.
CSS3 Transformaciones 2D
CSS3 transforma
Las transformaciones CSS3 le permiten traducir, rotar, escalar e inclinar
elementos.
Pase el mouse sobre los elementos de abajo para ver la diferencia entre
una transformación 2D y 3D:
CSS3 Transformaciones 2D
En este capítulo aprenderá sobre los siguientes métodos de transformación
2D:
translate()
rotate()
scale()
skewX()
skewY()
matrix()
El método translate ()
Ejemplo
div {
-ms-transform: translate(50px, 100px); /* IE 9 */
-webkit-transform: translate(50px, 100px); /* Safari */
transform: translate(50px, 100px);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
-ms-transform: translate(50px,100px); /* IE 9 */
</style>
</head>
<body>
<div>
The translate() method moves an element from its current position. This div element is moved 50
pixels to the right, and 100 pixels down from its current position.
</div>
</body>
</html>
El método rotate ()
Ejemplo
div {
-ms-transform: rotate(20deg); /* IE 9 */
-webkit-transform: rotate(20deg); /* Safari */
transform: rotate(20deg);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
}
div#myDiv {
-ms-transform: rotate(20deg); /* IE 9 */
</style>
</head>
<body>
<div>
</div>
<div id="myDiv">
The rotate() method rotates an element clockwise or counter-clockwise. This div element is
rotated clockwise 20 degrees.
</div>
</body>
</html>
Ejemplo
div {
-ms-transform: rotate(-20deg); /* IE 9 */
-webkit-transform: rotate(-20deg); /* Safari */
transform: rotate(-20deg);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
-ms-transform: rotate(-20deg); /* IE 9 */
</style>
</head>
<body>
<div>
<div id="myDiv">
The rotate() method rotates an element clockwise or counter-clockwise. This div element is
rotated counter-clockwise with 20 degrees.
</div>
</body>
</html>
El método scale ()
Ejemplo
div {
-ms-transform: scale(2, 3); /* IE 9 */
-webkit-transform: scale(2, 3); /* Safari */
transform: scale(2, 3);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 150px;
width: 200px;
height: 100px;
background-color: yellow;
-ms-transform: scale(2,3); /* IE 9 */
</style>
</head>
<body>
<div>
This div element is two times of its original width, and three times of its original height.
</div>
</body>
</html>
El ejemplo siguiente reduce el elemento <div> a la mitad de su anchura y
altura originales:
Ejemplo
div {
-ms-transform: scale(0.5, 0.5); /* IE 9 */
-webkit-transform: scale(0.5, 0.5); /* Safari */
transform: scale(0.5, 0.5);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 150px;
width: 200px;
height: 100px;
background-color: yellow;
-ms-transform: scale(0.5,0.5); /* IE 9 */
</style>
</head>
<body>
<p>The scale() method increases or decreases the size of an element.</p>
<div>
This div element is decreased to be half of its original width and height.
</div>
</body>
</html>
El método skewX ()
El skewX() método inclina un elemento a lo largo del eje X por el ángulo
dado.
Ejemplo
div {
-ms-transform: skewX(20deg); /* IE 9 */
-webkit-transform: skewX(20deg); /* Safari */
transform: skewX(20deg);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
-ms-transform: skewX(20deg); /* IE 9 */
</style>
</head>
<body>
<p>The skewX() method skews an element along the X-axis by the given angle.</p>
<div>
</div>
<div id="myDiv">
</div>
</body>
</html>
El método skewY ()
El skewY() método inclina un elemento a lo largo del eje Y por el ángulo
dado.
Ejemplo
div {
-ms-transform: skewY(20deg); /* IE 9 */
-webkit-transform: skewY(20deg); /* Safari */
transform: skewY(20deg);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
-ms-transform: skewY(20deg); /* IE 9 */
</style>
</head>
<body>
<p>The skewY() method skews an element along the Y-axis by the given angle.</p>
<div>
</div>
<div id="myDiv">
</div>
</body>
</html>
El método sesgado ()
El skew() método inclina un elemento a lo largo del eje X y Y por los
ángulos dados.
Ejemplo
div {
-ms-transform: skew(20deg, 10deg); /* IE 9 */
-webkit-transform: skew(20deg, 10deg); /* Safari */
transform: skew(20deg, 10deg);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
-ms-transform: skew(20deg,10deg); /* IE 9 */
</style>
</head>
<body>
<div>
This a normal div element.
</div>
<div id="myDiv">
This div element is skewed 20 degrees along the X-axis, and 10 degrees along the Y-axis.
</div>
</body>
</html>
Ejemplo
div {
-ms-transform: skew(20deg); /* IE 9 */
-webkit-transform: skew(20deg); /* Safari */
transform: skew(20deg);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
-ms-transform: skew(20deg); /* IE 9 */
</style>
</head>
<body>
<div>
</div>
<div id="myDiv">
</div>
</body>
</html>
El matrix() método combina todos los métodos de transformación 2D en
uno.
Los parámetros son los siguientes: matrix (scaleX (), skewY (), skewX (),
scaleY (), translateX (), translateY ())
Ejemplo
div {
-ms-transform: matrix(1, -0.3, 0, 1, 0, 0); /* IE 9 */
-webkit-transform: matrix(1, -0.3, 0, 1, 0, 0); /* Safari */
transform: matrix(1, -0.3, 0, 1, 0, 0);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
border: 1px solid black;
div#myDiv1 {
div#myDiv2 {
</style>
</head>
<body>
<p>The matrix() method combines all the 2D transform methods into one.</p>
<div>
</div>
<div id="myDiv1">
<div id="myDiv2">
</div>
</body>
</html>
Property Description
Métodos de transformación 2D
Function Description
CSS3 Transformaciones 3D
CSS3 Transformaciones 3D
CSS3 le permite dar formato a sus elementos mediante transformaciones
en 3D.
Pase el mouse sobre los elementos de abajo para ver la diferencia entre
una transformación 2D y 3D:
CSS3 Transformaciones 3D
En este capítulo aprenderá sobre los siguientes métodos de transformación
3D:
rotateX()
rotateY()
rotateZ()
El método rotateX ()
Ejemplo
div {
-webkit-transform: rotateX(150deg); /* Safari */
transform: rotateX(150deg);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
</style>
</head>
<body>
<div>
</div>
<div id="myDiv">
The rotateX() method rotates an element around its X-axis at a given degree. This div element is
rotated 150 degrees.
</div>
<p><b>Note:</b> Internet Explorer 9 (and earlier versions) does not support the rotateX()
method.</p>
</body>
</html>
El método rotateY ()
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
</style>
</head>
<body>
<div>
<div id="myDiv">
The rotateY() method rotates an element around its Y-axis at a given degree. This div element is
rotated 150 degrees.
</div>
<p><b>Note:</b> Internet Explorer 9 (and earlier versions) does not support the rotateY()
method.</p>
</body>
</html>
El método rotateZ ()
El rotateZ() método hace girar un elemento alrededor de su eje Z en un
grado dado:
Ejemplo
div {
-webkit-transform: rotateZ(90deg); /* Safari */
transform: rotateZ(90deg);
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
</style>
</head>
<body>
<div>
</div>
<div id="myDiv">
The rotateZ() method rotates an element around its Z-axis at a given degree. This div element is
rotated 90 degrees.
</div>
<p><b>Note:</b> Internet Explorer 9 (and earlier versions) does not support the rotateZ()
method.</p>
</body>
</html>
Property Description
Function
matrix3d
(n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n)
translate3d(x,y,z)
translateX(x)
translateY(y)
translateZ(z)
scale3d(x,y,z)
scaleX(x)
scaleY(y)
scaleZ(z)
rotate3d(x,y,z,angle)
rotateX(angle)
rotateY(angle)
rotateZ(angle)
perspective(n
Transiciones CSS3
Transiciones CSS3
Las transiciones CSS3 le permiten cambiar los valores de propiedad sin
problemas (de un valor a otro), durante una duración determinada.
Ejemplo
div {
width: 100px;
height: 100px;
background: red;
-webkit-transition: width 2s; /* Safari */
transition: width 2s;
}
Ejemplo
div:hover {
width: 300px;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
div:hover {
width: 300px;
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
<p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>
Ejemplo
div {
-webkit-transition: width 2s, height 4s; /* Safari */
transition: width 2s, height 4s;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
div:hover {
width: 300px;
height: 300px;
}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
<p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>
Ejemplo
#div1 {transition-timing-function: linear;}
#div2 {transition-timing-function: ease;}
#div3 {transition-timing-function: ease-in;}
#div4 {transition-timing-function: ease-out;}
#div5 {transition-timing-function: ease-in-out;}
<!DOCTYPEhtml>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
/* Standard syntax */
div:hover {
width: 300px;
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div id="div1">linear</div><br>
<div id="div2">ease</div><br>
<div id="div3">ease-in</div><br>
<div id="div4">ease-out</div><br>
<div id="div5">ease-in-out</div><br>
<p>Hover over the div elements above, to see the different speed curves.</p>
</body>
</html>
Ejemplo
div {
-webkit-transition-delay: 1s; /* Safari */
transition-delay: 1s;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition-delay: 1s;
}
div:hover {
width: 300px;
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
<p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>
Transición + Transformación
El ejemplo siguiente también añade una transformación al efecto de
transición:
Ejemplo
div {
-webkit-transition: width 2s, height 2s, -webkit-transform 2s; /*
Safari */
transition: width 2s, height 2s, transform 2s;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
div:hover {
width: 300px;
height: 300px;
transform: rotate(180deg);
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
<p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>
Ejemplo
div {
transition-property: width;
transition-duration: 2s;
transition-timing-function: linear;
transition-delay: 1s;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
-webkit-transition-property: width;
-webkit-transition-duration: 2s;
-webkit-transition-timing-function: linear;
-webkit-transition-delay: 1s;
/* Standard syntax */
transition-property: width;
transition-duration: 2s;
transition-timing-function: linear;
transition-delay: 1s;
div:hover {
width: 300px;
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
<p>Hover over the div element above, to see the transition effects.</p>
</body>
</html>
!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
div:hover {
width: 300px;
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
<p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>
Property Description
Animaciones CSS3
Animaciones CSS3
CSS3 animaciones permite la animación de la mayoría de los elementos
HTML sin usar JavaScript o Flash!
La regla @keyframes
Cuando especifique estilos CSS dentro de la @keyframes regla, la animación
cambiará gradualmente del estilo actual al nuevo estilo en determinados
momentos.
Ejemplo
/* The animation code */
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: example;
animation-duration: 4s;
}
@-webkit-keyframes example {
to {background-color: yellow;}
/* Standard syntax */
@keyframes example {
to {background-color: yellow;}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Nota: Si la animation-duration propiedad no está especificada, la
animación no tendrá ningún efecto, ya que el valor predeterminado es 0.
Ejemplo
/* The animation code */
@keyframes example {
0% {background-color: red;}
25% {background-color: yellow;}
50% {background-color: blue;}
100% {background-color: green;}
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: example;
animation-duration: 4s;
@-webkit-keyframes example {
0% {background-color: red;}
/* Standard syntax */
@keyframes example {
0% {background-color: red;}
}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Ejemplo
/* The animation code */
@keyframes example {
0% {background-color:red; left:0px; top:0px;}
25% {background-color:yellow; left:200px; top:0px;}
50% {background-color:blue; left:200px; top:200px;}
75% {background-color:green; left:0px; top:200px;}
100% {background-color:red; left:0px; top:0px;}
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
@-webkit-keyframes example {
}
/* Standard syntax */
@keyframes example {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
<!DOCTYPEhtml>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
animation-delay: 2s;
/* Standard syntax */
@keyframes example {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Establecer cuántas veces debe ejecutarse
una animación
La animation-iteration-count propiedad especifica el número de veces
que debe ejecutarse una animación.
Ejemplo
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 3;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 3;
@-webkit-keyframes example {
/* Standard syntax */
@keyframes example {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Ejemplo
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
-webkit-animation-name: example; /* Safari 4.0 - 8.0 */
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
@-webkit-keyframes example {
/* Standard syntax */
@keyframes example {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Ejemplo
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 3;
animation-direction: reverse;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 3;
animation-direction: reverse;
@-webkit-keyframes example {
}
/* Standard syntax */
@keyframes example {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Ejemplo
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 3;
animation-direction: alternate;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 3;
animation-direction: alternate;
@-webkit-keyframes example {
/* Standard syntax */
@keyframes example {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Especificar la curva de velocidad de la
animación
La animation-timing-function propiedad especifica la curva de velocidad
de la animación.
Ejemplo
#div1 {animation-timing-function: linear;}
#div2 {animation-timing-function: ease;}
#div3 {animation-timing-function: ease-in;}
#div4 {animation-timing-function: ease-out;}
#div5 {animation-timing-function: ease-in-out;}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 50px;
background-color: red;
font-weight: bold;
position: relative;
/* Standard syntax */
@-webkit-keyframesmymove {
to {left: 300px;}
}
/* Standard syntax */
@keyframes mymove {
to {left: 300px;}
</style>
</head>
<body>
<div id="div1">linear</div>
<div id="div2">ease</div>
<div id="div3">ease-in</div>
<div id="div4">ease-out</div>
<div id="div5">ease-in-out</div>
</body>
</html>
Ejemplo
div {
animation-name: example;
animation-duration: 5s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
-webkit-animation-name: example;
-webkit-animation-duration: 5s;
-webkit-animation-timing-function: linear;
-webkit-animation-delay: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
/* Standard syntax */
animation-name: example;
animation-duration: 5s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
@-webkit-keyframes example {
/* Standard syntax */
@keyframes example {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Ejemplo
div {
animation: example 5s linear 2s infinite alternate;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
@-webkit-keyframesmyfirst {
0% {background-color:red; left:0px; top:0px;}
/* Standard syntax */
@keyframesmyfirst {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Propiedades de Animación CSS3
La siguiente tabla muestra la regla @keyframes y todas las propiedades de
la animación:
Property Description
@keyframes Specifiestheanimationcode
CSS Imágenes
Aprenda cómo diseñar imágenes utilizando CSS.
Imágenes redondeadas
Utilice la border-radius propiedad para crear imágenes redondeadas:
<!DOCTYPE html>
<html>
<head>
<style>
img {
border-radius: 8px;
</style>
</head>
<body>
<h2>Rounded Images</h2>
</body>
</html>
Imágenes en miniatura
Utilice la border propiedad para crear imágenes en miniatura.
Ejemplo
img {
border: 1px solid #ddd;
border-radius: 4px;
padding:5px;
width:150px;
}
<img src="paris.jpg"alt="Paris">
<!DOCTYPE html>
<html>
<head>
<style>
img {
padding: 5px;
width: 150px;
</style>
</head>
<body>
<h2>Thumbnail Images</h2>
</body>
</html>
Ejemplo
img {
border: 1px solid #ddd;
border-radius: 4px;
padding: 5px;
width: 150px;
}
img:hover {
box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
}
<a href="paris.jpg">
<img src="paris.jpg"alt="Paris">
</a>
<!DOCTYPE html>
<html>
<head>
<style>
img {
border-radius: 4px;
padding: 5px;
width: 150px;
img:hover {
</style>
</head>
<body>
<p>Use the border property to create thumbnail images. Wrap an anchor around the image to use
it as a link.</p>
</a>
</body>
</html>
Imágenes sensibles
Las imágenes sensibles se ajustarán automáticamente para adaptarse al
tamaño de la pantalla.
Si desea que una imagen se reduzca si tiene que hacerlo, pero nunca
escala hasta ser mayor que su tamaño original, agregue lo siguiente:
Ejemplo
img {
max-width: 100%;
height: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
max-width: 100%;
height: auto;
</style>
</head>
<body>
<h2>Responsive Images</h2>
<p>Responsive images will automatically adjust to fit the size of the screen.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
img {
display: block;
margin: auto;
</style>
</head>
<body>
</body>
</html>
Ejemplo
div.polaroid {
width: 80%;
background-color: white;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0,
0, 0.19);
}
div.container {
text-align: center;
padding: 10px 20px;
}
<!DOCTYPE html>
<html>
<head>
<style>
body {margin:25px;}
div.polaroid {
width: 80%;
background-color: white;
margin-bottom: 25px;
div.container {
text-align: center;
</style>
</head>
<body>
<div class="polaroid">
<div class="container">
</div>
</div>
<div class="polaroid">
<img src="lights600x400.jpg" alt="Norway" style="width:100%">
<div class="container">
</div>
</div>
</body>
</html>
Imagen transparente
La opacity propiedad puede tomar un valor de 0.0 - 1.0. El valor más
bajo, más transparente:
Ejemplo
img {
opacity: 0.5;
filter: alpha(opacity=50); /* For IE8 and earlier */
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
opacity: 0.5;
</style>
</head>
<body>
<h1>Image Transparency</h1>
<p>The opacity property specifies the transparency of an element. The lower the value, the more
transparent:</p>
</body>
</html>
Texto de la imagen
Cómo colocar el texto en una imagen:
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
.topleft {
position: absolute;
top: 8px;
left: 16px;
font-size: 18px;
}
img {
width: 100%;
height: auto;
opacity: 0.3;
</style>
</head>
<body>
<h2>Image Text</h2>
<div class="container">
</div>
</body>
</html>
Filtros de imagen
La filter propiedad CSS añade efectos visuales (como desenfoque y saturación) a un
elemento.
Nota: La propiedad de filtro no es compatible con Internet Explorer, Edge 12 o Safari 5.1 y
versiones anteriores.
Ejemplo
img {
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
filter: grayscale(100%);
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 33%;
height: auto;
float: left;
max-width: 235px;
</style>
</head>
<body>
<p><strong>Note:</strong> The filter property is not supported in Internet Explorer, Edge 12, or
Safari 5.1 and earlier.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
background-color: #008CBA;
.container:hover .overlay {
opacity: 1;
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
</style>
</head>
<body>
<h2>Fade in Overlay</h2>
<div class="container">
<div class="overlay">
</div>
</div>
</body>
</html>
Ejemplo 2
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
}
.image {
opacity: 1;
display: block;
width: 100%;
height: auto;
backface-visibility: hidden;
.middle {
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
.container:hover .image {
opacity: 0.3;
.container:hover .middle {
opacity: 1;
}
.text {
background-color: #4CAF50;
color: white;
font-size: 16px;
</style>
</head>
<body>
<h2>Fade in a Box</h2>
<div class="container">
<div class="middle">
</div>
</div>
</body>
</html>
Ejemplo 3
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
.image {
display: block;
width: 100%;
height: auto;
.overlay {
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height:0;
.container:hover .overlay {
bottom: 0;
height: 100%;
.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
</style>
</head>
<body>
<div class="container">
<div class="overlay">
</div>
</div>
</body>
</html>
Ejemplo 4
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
.image {
display: block;
width: 100%;
height: auto;
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 0;
.container:hover .overlay {
height: 100%;
.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
</style>
</head>
<body>
<div class="overlay">
</div>
</div>
</body>
</html>
Ejemlplo 5
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
.image {
display: block;
width: 100%;
height: auto;
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 0;
height: 100%;
.container:hover .overlay {
width: 100%;
.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
}
</style>
</head>
<body>
<div class="container">
<div class="overlay">
</div>
</div>
</body>
</html>
Ejemplo 6
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 50%;
.image {
display: block;
width: 100%;
height: auto;
.overlay {
position: absolute;
bottom: 0;
left: 100%;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 0;
height: 100%;
.container:hover .overlay {
width: 100%;
left: 0;
.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
</style>
</head>
<body>
<div class="container">
<div class="overlay">
</div>
</div>
</body>
</html>
Galería de imágenes
CSS se puede utilizar para crear galerías de imágenes. Este ejemplo utiliza
consultas de medios para volver a organizar las imágenes en diferentes
tamaños de pantalla. Cambie el tamaño de la ventana del navegador para
ver el efecto:
Ejemplo
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
<!DOCTYPE html>
<html>
<head>
<style>
div.gallery {
div.gallery:hover {
div.galleryimg {
width: 100%;
height: auto;
div.desc {
padding: 15px;
text-align: center;
*{
box-sizing: border-box;
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
.responsive {
width: 49.99999%;
margin: 6px 0;
.responsive {
width: 100%;
.clearfix:after {
content: "";
display: table;
clear: both;
</style>
</head>
<body>
<div class="gallery">
</a>
</div>
</div>
<div class="responsive">
<div class="gallery">
</a>
</div>
</div>
<div class="responsive">
<div class="gallery">
</a>
</div>
<div class="responsive">
<div class="gallery">
</a>
</div>
</div>
<div class="clearfix"></div>
<div style="padding:6px;">
<p>This example use media queries to re-arrange the images on different screen sizes: for screens
larger than 700px wide, it will show four images side by side, for screens smaller than 700px, it will
show two images side by side. For screens smaller than 500px, the images will stack vertically
(100%).</p>
<p>You will learn more about media queries and responsive web design later in our CSS
Tutorial.</p>
</div>
</body>
</html>
Imagen Modal (Avanzada)
Este es un ejemplo para demostrar cómo CSS y JavaScript pueden trabajar
juntos.
En primer lugar, use CSS para crear una ventana modal (cuadro de
diálogo) y ocultarla de forma predeterminada.
Ejemplo
// Get the modal
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its "alt" text as a
caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
<!DOCTYPE html>
<html>
<head>
<style>
#myImg {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
.modal {
left: 0;
top: 0;
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
#caption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
/* Add Animation */
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
@-webkit-keyframes zoom {
to {-webkit-transform: scale(1)}
@keyframes zoom {
to {transform: scale(1)}
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
.modal-content {
width: 100%;
</style>
</head>
<body>
<h2>Image Modal</h2>
<p>In this example, we use CSS to create a modal (dialog box) that is hidden by default.</p>
<p>We use JavaScript to trigger the modal and to display the current image inside the modal when
it is clicked on. Also note that we use the value from the image's "alt" attribute as an image
caption text inside the modal.</p>
<p>Don't worry if you do not understand the code right away. When you are done with CSS, go to
our JavaScript Tutorial to learn more.</p>
<span class="close">×</span>
<div id="caption"></div>
</div>
<script>
// Get the image and insert it inside the modal - use its "alt" text as a caption
varimg = document.getElementById('myImg');
varmodalImg = document.getElementById("img01");
varcaptionText = document.getElementById("caption");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
span.onclick = function() {
modal.style.display = "none";
</script>
</body>
</html>
CSS Botones
Aprenda cómo diseñar los botones utilizando CSS.
Ejemplo
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
background-color: #4CAF50;
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
</style>
</head>
<body>
<h2>CSS Buttons</h2>
<button>Default Button</button>
<button class="button">Button</button>
</body>
</html>
Ejemplo
.button1 {background-color: #4CAF50;} /* Green */
.button2 {background-color: #008CBA;} /* Blue */
.button3 {background-color: #f44336;} /* Red */
.button4 {background-color: #e7e7e7; color: black;} /* Gray */
.button5 {background-color: #555555;} /* Black */
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
}
.button2 {background-color: #008CBA;} /* Blue */
</style>
</head>
<body>
<h2>Button Colors</h2>
<button class="button">Green</button>
</body>
</html>
Ejemplo
.button1 {font-size: 10px;}
.button2 {font-size: 12px;}
.button3 {font-size: 16px;}
.button4 {font-size: 20px;}
.button5 {font-size: 24px;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
cursor: pointer;
</style>
</head>
<body>
<h2>Button Sizes</h2>
</body>
</html>
Ejemplo
.button1 {padding: 10px 24px;}
.button2 {padding: 12px 28px;}
.button3 {padding: 14px 40px;}
.button4 {padding: 32px 16px;}
.button5 {padding: 16px;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
</style>
</head>
<body>
<h2>Button Sizes</h2>
</body>
</html>
Botones redondeados
Ejemplo
.button1 {border-radius: 2px;}
.button2 {border-radius: 4px;}
.button3 {border-radius: 8px;}
.button4 {border-radius: 12px;}
.button5 {border-radius: 50%;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
</style>
</head>
<body>
<h2>Rounded Buttons</h2>
</body>
</html>
Ejemplo
.button1 {
background-color: white;
color: black;
border: 2px solid #4CAF50; /* Green */
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
.button1 {
background-color: white;
color: black;
.button2 {
background-color: white;
color: black;
}
.button3 {
background-color: white;
color: black;
.button4 {
background-color: white;
color: black;
.button5 {
background-color: white;
color: black;
</style>
</head>
<body>
</body>
</html>
Botones Hoverable
Ejemplo
.button {
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
}
.button:hover {
background-color: #4CAF50; /* Green */
color: white;
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
transition-duration: 0.4s;
cursor: pointer;
.button1 {
background-color: white;
color: black;
.button1:hover {
background-color: #4CAF50;
color: white;
.button2 {
background-color: white;
color: black;
.button2:hover {
background-color: #008CBA;
color: white;
.button3 {
background-color: white;
color: black;
.button3:hover {
background-color: #f44336;
color: white;
}
.button4 {
background-color: white;
color: black;
.button5 {
background-color: white;
color: black;
.button5:hover {
background-color: #555555;
color: white;
</style>
</head>
<body>
<h2>Hoverable Buttons</h2>
<p>Use the :hover selector to change the style of the button when you move the mouse over
it.</p>
<p><strong>Tip:</strong> Use the transition-duration property to determine the speed of the
"hover" effect:</p>
</body>
</html>
Shadow Botones
Ejemplo
.button1 {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0
rgba(0,0,0,0.19);
}
.button2:hover {
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0
rgba(0,0,0,0.19);
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
transition-duration: 0.4s;
.button1 {
.button2:hover {
}
</style>
</head>
<body>
<h2>Shadow Buttons</h2>
</body>
</html>
Botones de movilidad
Ejemplo
.disabled {
opacity: 0.6;
cursor: not-allowed;
}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
.disabled {
opacity: 0.6;
cursor: not-allowed;
</style>
</head>
<body>
<h2>Disabled Buttons</h2>
<p>Use the opacity property to add some transparency to the button (make it look disabled):</p>
</body>
</html>
Ancho botón
Ejemplo
.button1 {width: 250px;}
.button2 {width: 50%;}
.button3 {width: 100%;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
</style>
</head>
<body>
<h2>Button Width</h2>
</body>
</html>
Grupos de botones
Ejemplo
.button {
float: left;
}
<!DOCTYPE html>
<html>
<head>
<style>
.btn-group .button {
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
float: left;
.btn-group .button:hover {
background-color: #3e8e41;
</style>
</head>
<body>
<h2>Button Groups</h2>
<div class="btn-group">
<button class="button">Button</button>
<button class="button">Button</button>
<button class="button">Button</button>
<button class="button">Button</button>
</div>
<p style="clear:both"><br>Remember to clear floats after, or else will this p element also float
next to the buttons.</p>
</body>
</html>
Ejemplo
.button {
float: left;
border: 1px solid green;
}
<!DOCTYPE html>
<html>
<head>
<style>
.btn-group .button {
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
float: left;
.btn-group .button:not(:last-child) {
.btn-group .button:hover {
background-color: #3e8e41;
</style>
</head>
<body>
<div class="btn-group">
<button class="button">Button</button>
<button class="button">Button</button>
<button class="button">Button</button>
<button class="button">Button</button>
</div>
<p style="clear:both"><br>Remember to clear floats after, or else will this p element also float
next to the buttons.</p>
</body>
</html>
Ejemplo
.button {
display: block;
}
<!DOCTYPE html>
<html>
<head>
<style>
.btn-group .button {
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
width: 150px;
display: block;
.btn-group .button:not(:last-child) {
.btn-group .button:hover {
background-color: #3e8e41;
</style>
</head>
<body>
<h2>Vertical Button Group</h2>
<div class="btn-group">
<button class="button">Button</button>
<button class="button">Button</button>
<button class="button">Button</button>
<button class="button">Button</button>
</div>
</body>
</html>
Botones animados
Ejemplo 1
<!DOCTYPE html>
<html>
<head>
<style>
.button {
display: inline-block;
border-radius: 4px;
background-color: #f4511e;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 28px;
padding: 20px;
width: 200px;
cursor: pointer;
margin: 5px;
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
.button:hover span {
padding-right: 25px;
.button:hover span:after {
opacity: 1;
right: 0;
</style>
</head>
<body>
<h2>Animated Button</h2>
</body>
</html>
Ejemplo 2
<!DOCTYPE html>
<html>
<head>
<style>
.button {
display: inline-block;
font-size: 24px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
.button:active {
background-color: #3e8e41;
transform: translateY(4px);
}
</style>
</head>
<body>
</body>
</html>
Ejemplo 3
<html>
<head>
<style>
.button {
position: relative;
background-color: #4CAF50;
border: none;
font-size: 28px;
color: #FFFFFF;
padding: 20px;
width: 200px;
text-align: center;
text-decoration: none;
overflow: hidden;
cursor: pointer;
.button:after {
content: "";
background: #f1f1f1;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-top: -120%;
opacity: 0;
.button:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s
</style>
</head>
<body>
</body>
</html>
Paginacion de CSS3
Ejemplos de paginación CSS
Aprenda a crear una paginación de respuesta utilizando CSS.
Paginación simple
Si tiene un sitio web con muchas páginas, puede agregar algún tipo de
paginación a cada página:
Ejemplo
.pagination {
display: inline-block;
}
.pagination a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
}
<!DOCTYPE html>
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
text-decoration: none;
</style>
</head>
<body>
<h2>Simple Pagination</h2>
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</body>
</html>
Resalte la página actual con una .active clase y utilice el :hover selector
para cambiar el color de cada enlace de página cuando mueva el mouse
sobre ellos:
Ejemplo
.pagination a.active {
background-color: #4CAF50;
color: white;
}
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
text-decoration: none;
.pagination a.active {
background-color: #4CAF50;
color: white;
</style>
</head>
<body>
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</body>
</html>
Ejemplo
.pagination a {
border-radius: 5px;
}
.pagination a.active {
border-radius: 5px;
}
<!DOCTYPE html>
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
text-decoration: none;
.pagination a.active {
background-color: #4CAF50;
color: white;
border-radius: 5px;
.pagination a:hover:not(.active) {
background-color: #ddd;
border-radius: 5px;
</style>
</head>
<body>
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</body>
</html>
Ejemplo
.pagination a {
transition: background-color .3s;
}
<!DOCTYPE html>
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
text-decoration: none;
.pagination a.active {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</body>
</html>
Paginación limitada
Ejemplo
.pagination a {
border: 1px solid #ddd; /* Gray */
}
<!DOCTYPE html>
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
text-decoration: none;
}
.pagination a.active {
background-color: #4CAF50;
color: white;
</style>
</head>
<body>
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</body>
</html>
Fronteras redondeadas
Ejemplo
.pagination a:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.pagination a:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
<!DOCTYPE html>
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
.pagination a.active {
background-color: #4CAF50;
color: white;
.pagination a:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
.pagination a:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
</style>
</head>
<body>
<h2>Pagination with Rounded Borders</h2>
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</body>
</html>
Ejemplo
.pagination a {
margin: 0 4px; /* 0 is for top and bottom. Feel free to change
it */
}
<!DOCTYPE html>
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
text-decoration: none;
margin: 0 4px;
.pagination a.active {
background-color: #4CAF50;
color: white;
}
.pagination a:hover:not(.active) {background-color: #ddd;}
</style>
</head>
<body>
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</body>
</html>
Tamaño de paginación
Ejemplo
.pagination a {
font-size: 22px;
}
<!DOCTYPE html>
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
text-decoration: none;
font-size: 22px;
.pagination a.active {
background-color: #4CAF50;
color: white;
</style>
</head>
<body>
<h2>Pagination Size</h2>
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</body>
</html>
Paginación Centrada
Ejemplo
.center {
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
.pagination {
display: inline-block;
}
.pagination a {
color: black;
float: left;
text-decoration: none;
margin: 0 4px;
.pagination a.active {
background-color: #4CAF50;
color: white;
</style>
</head>
<body>
<h2>Centered Pagination</h2>
<div class="center">
<div class="pagination">
<a href="#">«</a>
<a href="#">1</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">»</a>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.pagination {
display: inline-block;
.pagination a {
color: black;
float: left;
text-decoration: none;
.pagination a.active {
background-color: #4CAF50;
color: white;
</style>
</head>
<body>
<p>Next/Previous buttons:</p>
<div class="pagination">
<a href="#">❮</a>
<a href="#">❮</a>
</div>
<p>Navigation pagination:</p>
<div class="pagination">
</div>
</body>
</html>
Ejemplo
ul.breadcrumb {
padding: 8px 16px;
list-style: none;
background-color: #eee;
}
ul.breadcrumb li+li:before {
padding: 8px;
color: black;
content: "/\00a0";
}
<!DOCTYPE html>
<html>
<head>
<style>
ul.breadcrumb {
list-style: none;
background-color: #eee;
ul.breadcrumb li+li:before {
padding: 8px;
color: black;
content: "/\00a0";
</style>
</head>
<body>
<h2>Breadcrumb Pagination</h2>
<ul class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">Pictures</a></li>
<li>Italy</li>
</ul>
</body>
</html>
column-count
column-gap
column-rule-style
column-rule-width
column-rule-color
column-rule
column-span
column-width
CSS3 Crear varias columnas
La column-count propiedad especifica el número de columnas en las que debe
dividirse un elemento.
Ejemplo
div {
-webkit-column-count: 3; /* Chrome, Safari, Opera */
-moz-column-count: 3; /* Firefox */
column-count: 3;
}
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-moz-column-count: 3; /* Firefox */
column-count: 3;
</style>
</head>
<body>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse
molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
eros et accumsan et iusto odio dignissim qui blandit praesent luptatum
zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber
tempor cum soluta nobis eleifend option congue nihil imperdiet doming id
quod mazim placerat facer possim assum.
</div>
</body>
</html>
Ejemplo
div {
-webkit-column-gap: 40px; /* Chrome, Safari, Opera */
-moz-column-gap: 40px; /* Firefox */
column-gap: 40px;
}
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-moz-column-count: 3; /* Firefox */
column-count: 3;
column-gap: 40px;
</style>
</head>
<body>
<p><b>Note:</b> Internet Explorer 9, and earlier versions, does not support the column-gap
property.</p>
<div class="newspaper">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis
nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis
autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</div>
</body>
</html>
Reglas de la columna CSS3
La column-rule-style propiedad especifica el estilo de la regla entre
columnas:
Ejemplo
div {
-webkit-column-rule-style: solid; /* Chrome, Safari, Opera */
-moz-column-rule-style: solid; /* Firefox */
column-rule-style: solid;
}
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-moz-column-count: 3; /* Firefox */
column-count: 3;
column-gap: 40px;
column-rule-style: solid;
</style>
</head>
<body>
<p><b>Note:</b> Internet Explorer 9, and earlier versions, does not support the column-rule-style
property.</p>
<div class="newspaper">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis
nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis
autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</div>
</body>
</html>
Ejemplo
div {
-webkit-column-rule-width: 1px; /* Chrome, Safari, Opera */
-moz-column-rule-width: 1px; /* Firefox */
column-rule-width: 1px;
}
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-moz-column-count: 3; /* Firefox */
column-count: 3;
column-gap: 40px;
column-rule-style: solid;
column-rule-width: 1px;
</style>
</head>
<body>
<p><b>Note:</b> Internet Explorer 9, and earlier versions, does not support the column-rule-
width property.</p>
<div class="newspaper">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis
nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis
autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</div>
</body>
</html>
Ejemplo
div {
-webkit-column-rule-color: lightblue; /* Chrome, Safari, Opera */
-moz-column-rule-color: lightblue; /* Firefox */
column-rule-color: lightblue;
}
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-moz-column-count: 3; /* Firefox */
column-count: 3;
column-gap: 40px;
-webkit-column-rule-style: solid; /* Chrome, Safari, Opera */
column-rule-style: solid;
column-rule-width: 1px;
column-rule-color: lightblue;
</style>
</head>
<body>
<p><b>Note:</b> Internet Explorer 9, and earlier versions, does not support the column-rule-color
property.</p>
<div class="newspaper">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis
nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis
autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</div>
</body>
</html>
Ejemplo
div {
-webkit-column-rule: 1px solid lightblue; /* Chrome, Safari, Opera */
-moz-column-rule: 1px solid lightblue; /* Firefox */
column-rule: 1px solid lightblue;
}
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-moz-column-count: 3; /* Firefox */
column-count: 3;
column-gap: 40px;
}
</style>
</head>
<body>
<p><b>Note:</b> Internet Explorer 9, and earlier versions, does not support the column-rule
property.</p>
<div class="newspaper">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis
nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis
autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-moz-column-count: 3; /* Firefox */
column-count: 3;
column-gap: 40px;
h2 {
column-span: all;
}
</style>
</head>
<body>
<p><b>Note:</b> Firefox and Internet Explorer 9 (and earlier versions) do not support the column-
span property.</p>
<div class="newspaper">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis
nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis
autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</div>
</body>
</html>
Ejemplo
div {
-webkit-column-width: 100px; /* Chrome, Safari, Opera */
-moz-column-width: 100px; /* Firefox */
column-width: 100px;
}
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-moz-column-count: 3; /* Firefox */
column-count: 3;
column-width: 100px;
</style>
</head>
<body>
<p><b>Note:</b> Internet Explorer 9, and earlier versions, does not support the column-width
property.</p>
<div class="newspaper">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis
nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis
autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</div>
</body>
</html>
Property Description
resize
outline-offset
Redimensionamiento CSS3
La resize propiedad especifica si el usuario debe o no redimensionar un
elemento.
Ejemplo
div {
resize: horizontal;
overflow: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 20px;
width: 300px;
resize: horizontal;
overflow: auto;
}
</style>
</head>
<body>
</body>
</html>
Ejemplo
div {
resize: vertical;
overflow: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 20px;
width: 300px;
resize: vertical;
overflow: auto;
</style>
</head>
<body>
</body>
</html>
Ejemplo
div {
resize: both;
overflow: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 20px;
width: 300px;
resize: both;
overflow: auto;
</style>
</head>
<body>
<div>Let the user resize both the height and the width of this div element.</div>
</body>
</html>
Ejemplo
div {
border: 1px solid black;
outline: 1px solid red;
outline-offset: 15px;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 20px;
padding: 10px;
width: 300px;
height: 100px;
outline-offset: 15px;
</style>
</head>
<body>
</body>
</html>
Property Description
.div2 {
width: 300px;
height: 100px;
padding: 50px;
border: 1px solid red;
}
<!DOCTYPE html>
<html>
<head>
<style>
.div1 {
width: 300px;
height: 100px;
.div2 {
width: 300px;
height: 100px;
padding: 50px;
</style>
</head>
<body>
<br>
<div class="div2">This div is bigger (width is also 300px and height is 100px).</div>
</body>
</html>
Ejemplo
.div1 {
width: 300px;
height: 100px;
border: 1px solid blue;
box-sizing: border-box;
}
.div2 {
width: 300px;
height: 100px;
padding: 50px;
border: 1px solid red;
box-sizing: border-box;
}
<!DOCTYPE html>
<html>
<head>
<style>
.div1 {
width: 300px;
height: 100px;
box-sizing: border-box;
.div2 {
width: 300px;
height: 100px;
padding: 50px;
box-sizing: border-box;
</style>
</head>
<body>
<br>
<div class="div2">Hooray!</div>
</body>
</html>
Dado que el resultado de usar el box-sizing: border-box; es mucho mejor,
muchos desarrolladores quieren que todos los elementos de sus páginas
funcionen de esta manera.
Ejemplo
* {
box-sizing: border-box;
}
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
*{
box-sizing: border-box;
input, textarea {
width: 100%;
}
</style>
</head>
<body>
<form action="/action_page.php">
First name:<br>
Last name:<br>
Comments:<br>
</textarea>
<br><br>
</form>
<p><strong>Tip:</strong> Try to remove the box-sizing property from the style element and look
what happens.
Notice that the width of input, textarea, and submit button will go outside of the screen.</p>
</body>
</html>
Ejemplo
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-item">flex item 1</div>
<div class="flex-item">flex item 2</div>
<div class="flex-item">flex item 3</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
body {
direction: rtl;
}
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
}
<!DOCTYPE html>
<html>
<head>
<style>
body {
direction: rtl;
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Dirección Flex
La flex-direction propiedad especifica la dirección de los elementos
flexibles dentro del contenedor flexible. El valor predeterminado de flex-
direction es row (de izquierda a derecha, de arriba a abajo).
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row-reverse;
flex-direction: row-reverse;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row-reverse;
flex-direction: row-reverse;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column-reverse;
flex-direction: column-reverse;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column-reverse;
flex-direction: column-reverse;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
La propiedad justify-content
La justify-content propiedad alinea horizontalmente los elementos del
contenedor flexible cuando los elementos no utilizan todo el espacio
disponible en el eje principal.
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: flex-end;
justify-content: flex-end;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: flex-end;
justify-content: flex-end;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
El siguiente ejemplo muestra el resultado de usar el center valor:
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: center;
justify-content: center;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: center;
justify-content: center;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</body>
</html>
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-around;
justify-content: space-around;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-around;
justify-content: space-around;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
La propiedad align-items
La align-items propiedad alinea verticalmente los elementos del
contenedor flexible cuando los elementos no utilizan todo el espacio
disponible en el eje transversal.
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: flex-start;
align-items: flex-start;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: flex-start;
align-items: flex-start;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: flex-end;
align-items: flex-end;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: flex-end;
align-items: flex-end;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
margin: 10px;
}
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: baseline;
align-items: baseline;
width: 400px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-align-items: baseline;
align-items: baseline;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
La propiedad flex-wrap
La flex-wrap propiedad especifica si los elementos flexibles deben
envolverse o no, si no hay suficiente espacio para ellos en una línea flex.
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: nowrap;
flex-wrap: nowrap;
width: 300px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: nowrap;
flex-wrap: nowrap;
width: 300px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
El siguiente ejemplo muestra el resultado de usar el wrap valor:
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
width: 300px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
width: 300px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap-reverse;
flex-wrap: wrap-reverse;
width: 300px;
height: 250px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap-reverse;
flex-wrap: wrap-reverse;
width: 300px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</body>
</html>
La propiedad align-content
La align-content propiedad modifica el comportamiento de la flex-wrap
propiedad. Es similar a align-items, pero en lugar de alinear elementos
flexibles, alinea las líneas flexibles.
Ejemplo
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-align-content: center;
align-content: center;
width: 300px;
height: 300px;
background-color: lightgrey;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-align-content: center;
align-content: center;
width: 300px;
height: 300px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Ejemplo
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
}
.first {
-webkit-order: -1;
order: -1;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin: 10px;
.first {
-webkit-order: -1;
order: -1;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Margen
El ajuste margin: auto; absorberá el espacio adicional. Se puede utilizar
para empujar elementos flexibles en diferentes posiciones.
Ejemplo
.flex-item {
background-color: cornflowerblue;
width: 75px;
height: 75px;
margin: 10px;
}
.flex-item:first-child {
margin-right: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 75px;
height: 75px;
margin: 10px;
.flex-item:first-child {
margin-right: auto;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Centrado perfecto
En el siguiente ejemplo resolveremos un problema casi diario: centrado
perfecto.
Es muy fácil con flexbox. El ajuste margin: auto; hará que el elemento
esté perfectamente centrado en ambos ejes:
Ejemplo
.flex-item {
background-color: cornflowerblue;
width: 75px;
height: 75px;
margin: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item {
background-color: cornflowerblue;
width: 75px;
height: 75px;
margin: auto;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
Alinearse
La align-self propiedad de los elementos flexibles anula la propiedad
align-items del contenedor flex para ese elemento. Tiene los mismos
valores posibles que la align-items propiedad.
Ejemplo
.flex-item {
background-color: cornflowerblue;
width: 60px;
min-height: 100px;
margin: 10px;
}
.item1 {
-webkit-align-self: flex-start;
align-self: flex-start;
}
.item2 {
-webkit-align-self: flex-end;
align-self: flex-end;
}
.item3 {
-webkit-align-self: center;
align-self: center;
}
.item4 {
-webkit-align-self: baseline;
align-self: baseline;
}
.item5 {
-webkit-align-self: stretch;
align-self: stretch;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
.flex-item {
background-color: cornflowerblue;
width: 60px;
min-height: 100px;
margin: 10px;
.item1 {
-webkit-align-self: flex-start;
align-self: flex-start;
.item2 {
-webkit-align-self: flex-end;
align-self: flex-end;
.item3 {
-webkit-align-self: center;
align-self: center;
.item4 {
-webkit-align-self: baseline;
align-self: baseline;
.item5 {
-webkit-align-self: stretch;
align-self: stretch;
</style>
</head>
<body>
<div class="flex-container">
</div>
</body>
</html>
flexionar
La flex propiedad especifica la longitud del elemento flexible, en relación
con el resto de los elementos flexibles dentro del mismo contenedor.
En el siguiente ejemplo, el primer elemento flexible consumirá 2/4 del
espacio libre y los otros dos elementos flexibles consumirán 1/4 del espacio
libre cada uno:
Ejemplo
.flex-item {
background-color: cornflowerblue;
margin: 10px;
}
.item1 {
-webkit-flex: 2;
flex: 2;
}
.item2 {
-webkit-flex: 1;
flex: 1;
}
.item3 {
-webkit-flex: 1;
flex: 1;
}
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item {
background-color: cornflowerblue;
margin: 10px;
.item1 {
-webkit-flex: 2;
flex: 2;
.item2 {
-webkit-flex: 1;
flex: 1;
.item3 {
-webkit-flex: 1;
flex: 1;
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-item item1">flex item 1</div>
</div>
</body>
</html>
EJEMPLOS
Ejemplo 1
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
font-weight: bold;
text-align: center;
.flex-container > * {
padding: 10px;
flex: 1 100%;
}
.main {
text-align: left;
background: cornflowerblue;
.aside1 { order: 1; }
.main { order: 2; }
.aside2 { order: 3; }
.footer { order: 4; }
</style>
</head>
<body>
<div class="flex-container">
<header class="header">Header</header>
<article class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sed ex turpis. Cras luctus
nibh lectus, in ullamcorper ex tempor eleifend. Nulla bibendum, eros a consequat vestibulum, orci
massa fermentum quam, sed commodo nunc ex vitae nisl. Aliquam ullamcorper interdum est nec
tincidunt.</p>
</article>
<footer class="footer">Footer</footer>
</div>
</body>
</html>
Property Description
align-items Vertically aligns the flex items when the items do not use
all available space on the cross-axis
Value Description
Speech Used for screenreaders that "reads" the page out loud
Ejemplo
@media screen and (min-width: 480px) {
body {
background-color: lightgreen;
}
}
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: pink;
body {
background-color: lightgreen;
</style>
</head>
<body>
</body>
</html>
Ejemplo
@media screen and (min-width: 480px) {
#leftsidebar {width: 200px; float: left;}
#main {margin-left:216px;}
}
<!DOCTYPE html>
<html>
<head>
<style>
#leftsidebar {
float: none;
width: auto;
}
#menulist {
margin: 0;
padding: 0;
.menuitem {
background: #CDF0F6;
border-radius: 4px;
list-style-type: none;
margin: 4px;
padding: 2px;
</style>
</head>
<body>
<div class="wrapper">
<div id="leftsidebar">
<ul id="menulist">
</ul>
</div>
<div id="main">
<p>This example shows a menu that will float to the left of the page if the viewport is 480 pixels
wide or wider. If the viewport is less than 480 pixels, the menu will be on top of the content.</p>
</div>
</div>
</body>
</html>
ul li a {
color: green;
text-decoration: none;
padding: 3px;
display: block;
}
</style>
</head>
<body>
<ul>
<li><a data-
email="[email protected]"href="mailto:[email protected]">John
Doe</a></li>
<li><a data-
email="[email protected]"href="mailto:[email protected]">Mary
Moe</a></li>
<li><a data-
email="[email protected]"href="mailto:[email protected]">Aman
da Panda</a></li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
ul li a {
color: green;
text-decoration: none;
padding: 3px;
display: block;
</style>
</head>
<body>
<ul>
<li><a data-email="[email protected]"
href="mailto:[email protected]">Amanda Panda</a></li>
</ul>
</body>
</html>
Observe la data-email atributo. En HTML5, podemos usar los atributos
prefijados con data-para almacenar información. Usaremos el data-
atributo más adelante.
Ejemplo 2
@media screen and (max-width: 699px) and (min-width: 520px) {
ul li a {
padding-left: 30px;
background: url(email-icon.png) left center no-repeat;
}
}
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
ul li a {
color: green;
text-decoration: none;
padding: 3px;
display: block;
ul li a {
padding-left: 30px;
</style>
</head>
<body>
<ul>
<li><a data-email="[email protected]"
href="mailto:[email protected]">Amanda Panda</a></li>
</ul>
</body>
</html>
Ancho de 700 a 1000px - Prefacio los
enlaces con un texto
Cuando el ancho del navegador está entre 700 y 1000px, prefamaremos
cada enlace de correo electrónico con el texto "Email:":
Ejemplo 3
@media screen and (max-width: 1000px) and (min-width: 700px) {
ul li a:before {
content: "Email: ";
font-style: italic;
color: #666666;
}
}
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
ul li a {
color: green;
text-decoration: none;
padding: 3px;
display: block;
}
@media screen and (max-width: 699px) and (min-width: 520px) {
ul li a {
padding-left: 30px;
ul li a:before {
font-style: italic;
color: #666666;
</style>
</head>
<body>
<ul>
</ul>
</body>
</html>
Ejemplo 4
@media screen and (min-width: 1001px) {
ul li a:after {
content: " (" attr(data-email) ")";
font-size: 12px;
font-style: italic;
color: #666666;
}
}
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
ul li a {
color: green;
text-decoration: none;
padding: 3px;
display: block;
ul li a {
padding-left: 30px;
ul li a:before {
font-style: italic;
color: #666666;
font-size: 12px;
font-style: italic;
color: #666666;
</style>
</head>
<body>
<ul>
<li><a data-email="[email protected]"
href="mailto:[email protected]">Amanda Panda</a></li>
</ul>
</body>
</html>
Widthabove 1151px - Agregar icono como
lo usamos antes
Para anchos de navegador por encima de 1151px, volveremos a agregar el
icono como lo usamos antes.
Ejemplo 5
@media screen and (max-width: 699px) and (min-width: 520px), (min-width:
1151px) {
ul li a {
padding-left: 30px;
background: url(email-icon.png) left center no-repeat;
}
}
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
ul li a {
color: green;
text-decoration: none;
padding: 3px;
display: block;
@media screen and (max-width: 699px) and (min-width: 520px), (min-width: 1151px) {
ul li a {
padding-left: 30px;
ul li a:before {
font-style: italic;
color: #666666;
ul li a:after {
font-size: 12px;
font-style: italic;
color: #666666;
}
</style>
</head>
<body>
<ul>
<li><a data-email="[email protected]"
href="mailto:[email protected]">Amanda Panda</a></li>
</ul>
</body>
</html>
Más ejemplos
Utilice la lista de enlaces de correo electrónico en una barra lateral en una
página web
<!DOCTYPE html>
<html>
<head>
<style>
#nav {
list-style-type: none;
#nav li a {
color: green;
text-decoration: none;
padding: 3px;
display: block;
#nav {
width: 35%;
float:left;
@media screen and (max-width: 699px) and (min-width: 520px), (min-width: 1151px) {
#nav li a {
padding-left: 30px;
font-style: italic;
color: #666666;
#nav li a:after {
font-size: 12px;
font-style: italic;
color: #666666;
</style>
</head>
<body>
<ul id="nav">
</ul>
<div id="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
Excepteursintoccaecatcupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.</p>
</div>
</body>
</html>
El uso de una vista de cuadrícula es muy útil al diseñar páginas web. Hace
que sea más fácil colocar elementos en la página.
Una vista de cuadrícula sensible a menudo tiene 12 columnas y tiene un
ancho total del 100%, y se reducirá y se expandirá a medida que cambia el
tamaño de la ventana del navegador.
* {
box-sizing: border-box;
}
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
.header {
padding: 15px;
.menu {
width: 25%;
float: left;
padding: 15px;
border: 1px solid red;
.main {
width: 75%;
float: left;
padding: 15px;
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="menu">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="main">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</body>
</html>
El ejemplo anterior está bien si la página web contiene sólo dos columnas.
CSS:
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
.header {
padding: 15px;
.row::after {
content: "";
clear: both;
display: table;
[class*="col-"] {
float: left;
padding: 15px;
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<div class="col-3">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="col-9">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</div>
</body>
</html>
CSS:
[class*="col-"] {
float: left;
padding: 15px;
border: 1px solid red;
}
HTML:
<div class="row">
<div class="col-3">...</div> <!-- 25% -->
<div class="col-9">...</div> <!-- 75% -->
</div>
Las columnas dentro de una fila están todas flotando a la izquierda y, por lo
tanto, se sacan del flujo de la página, y otros elementos se colocarán como
si las columnas no existieran. Para evitar esto, agregaremos un estilo que
borre el flujo:
CSS:
.row::after {
content: "";
clear: both;
display: table;
}
Ejemplo
html {
font-family: "Lucida Sans", sans-serif;
}
.header {
background-color: #9933cc;
color: #ffffff;
padding: 15px;
}
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color :#33b5e5;
color: #ffffff;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px
rgba(0,0,0,0.24);
}
.menu li:hover {
background-color: #0099cc;
}
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
.row::after {
content: "";
clear: both;
display: table;
[class*="col-"] {
float: left;
padding: 15px;
html {
.header {
background-color: #9933cc;
color: #ffffff;
padding: 15px;
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color: #33b5e5;
color: #ffffff;
.menu li:hover {
background-color: #0099cc;
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="col-9">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</div>
</body>
</html>
Observe que la página web del ejemplo no se ve bien cuando cambia el
tamaño de la ventana del navegador a un ancho muy pequeño. En el
siguiente capítulo aprenderá a solucionarlo.
Ejemplo
Si la ventana del navegador es inferior a 500px, el color de fondo cambiará
a lightblue:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightgreen;
}
body {
background-color: lightblue;
</style>
</head>
<body>
<p>Resize the browser window. When the width of this document is less than 500 pixels, the
background-color is "lightblue", otherwise it is "lightgreen".</p>
</body>
</html>
Ejemplo
Cuando la pantalla (ventana del navegador) es menor que 768px, cada
columna debe tener un ancho de 100%:
/* For desktop: */
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
.row::after {
content: "";
clear: both;
display: block;
[class*="col-"] {
float: left;
padding: 15px;
html {
.header {
background-color: #9933cc;
color: #ffffff;
padding: 15px;
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color: #33b5e5;
color: #ffffff;
.menu li:hover {
background-color: #0099cc;
.aside {
background-color: #33b5e5;
padding: 15px;
color: #ffffff;
text-align: center;
font-size: 14px;
}
.footer {
background-color: #0099cc;
color: #ffffff;
text-align: center;
font-size: 12px;
padding: 15px;
/* For desktop: */
[class*="col-"] {
width: 100%;
}
}
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="col-6">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
</div>
<div class="col-3 right">
<div class="aside">
<h2>What?</h2>
<h2>Where?</h2>
<h2>How?</h2>
</div>
</div>
</div>
<div class="footer">
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</body>
</html>
Ejemplo
/* For mobile phones: */
[class*="col-"] {
width: 100%;
}
@media only screen and (min-width: 768px) {
/* For desktop: */
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
}
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
.row::after {
content: "";
clear: both;
display: table;
[class*="col-"] {
float: left;
padding: 15px;
html {
.header {
background-color: #9933cc;
color: #ffffff;
padding: 15px;
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color: #33b5e5;
color: #ffffff;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
.menu li:hover {
background-color: #0099cc;
.aside {
background-color: #33b5e5;
padding: 15px;
color: #ffffff;
text-align: center;
font-size: 14px;
.footer {
background-color: #0099cc;
color: #ffffff;
text-align: center;
font-size: 12px;
padding: 15px;
[class*="col-"] {
width: 100%;
/* For desktop: */
.col-1 {width: 8.33%;}
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="col-6">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
</div>
<div class="aside">
<h2>What?</h2>
<h2>Where?</h2>
<h2>How?</h2>
</div>
</div>
</div>
<div class="footer">
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</body>
</html>
Ejemplo
Tenga en cuenta que los dos conjuntos de clases son casi idénticos, la única
diferencia es el nombre (col- y col-m-):
<html>
<head>
<style>
*{
box-sizing: border-box;
.row::after {
content: "";
clear: both;
display: table;
[class*="col-"] {
float: left;
padding: 15px;
html {
.header {
background-color: #9933cc;
color: #ffffff;
padding: 15px;
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color: #33b5e5;
color: #ffffff;
.menu li:hover {
background-color: #0099cc;
.aside {
background-color: #33b5e5;
padding: 15px;
color: #ffffff;
text-align: center;
font-size: 14px;
.footer {
background-color: #0099cc;
color: #ffffff;
text-align: center;
font-size: 12px;
padding: 15px;
[class*="col-"] {
width: 100%;
/* For tablets: */
/* For desktop: */
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
</div>
<div class="aside">
<h2>What?</h2>
<h2>Where?</h2>
<h2>How?</h2>
</div>
</div>
</div>
<div class="footer">
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</body>
</html>
Ejemplo HTML
Para escritorio:
Para tabletas:
<div class="row">
<div class="col-3 col-m-3">...</div>
<div class="col-6 col-m-9">...</div>
<div class="col-3 col-m-12">...</div>
</div>
Ejemplo
La página web tendrá un fondo azul claro si la orientación está en modo
horizontal:
@media only screen and (orientation: landscape) {
body {
background-color: lightblue;
}
}
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightgreen;
body {
background-color: lightblue;
</style>
</head>
<body>
<p>Resize the browser window. When the width of this document is larger than the height, the
background-color is "lightblue", otherwise it is "lightgreen".</p>
</body>
</html>
Ejemplo
img {
width: 100%;
height: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 100%;
height: auto;
</style>
</head>
<body>
<img src="img_chania.jpg" width="460" height="345">
<p>Resize the browser window to see how the image will scale.</p>
</body>
</html>
Ejemplo
img {
max-width: 100%;
height: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
max-width: 100%;
height: auto;
</style>
</head>
<body>
<p>Resize the browser window to see how the image wil scale when the width is less than
460px.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
img {
width: 100%;
height: auto;
.row:after {
content: "";
clear: both;
display: table;
[class*="col-"] {
float: left;
padding: 15px;
width: 100%;
html {
.header {
background-color: #9933cc;
color: #ffffff;
padding: 15px;
}
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color :#33b5e5;
color: #ffffff;
.menu li:hover {
background-color: #0099cc;
.aside {
background-color: #33b5e5;
padding: 15px;
color: #ffffff;
text-align: center;
font-size: 14px;
.footer {
background-color: #0099cc;
color: #ffffff;
text-align: center;
font-size: 12px;
padding: 15px;
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
</div>
<div class="aside">
<h2>What?</h2>
<h2>Where?</h2>
<h2>How?</h2>
</div>
</div>
</div>
<div class="footer">
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</body>
</html>
Imágenes de fondo
Las imágenes de fondo también pueden responder al cambio de tamaño y
escalado.
Ejemplo
div {
width: 100%;
height: 400px;
background-image: url('img_flowers.jpg');
background-repeat: no-repeat;
background-size: contain;
border: 1px solid red;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100%;
height: 400px;
background-image: url('img_flowers.jpg');
background-repeat: no-repeat;
background-size: contain;
</style>
</head>
<body>
<div></div>
</body>
</html>
2. Si la background-sizepropiedad está configurada como "100% 100%",
la imagen de fondo se extenderá para cubrir todo el área de contenido:
Ejemplo
div {
width: 100%;
height: 400px;
background-image: url('img_flowers.jpg');
background-size: 100% 100%;
border: 1px solid red;
}
<!DOCTYPE html>
<html>
<head>
div {
width: 100%;
height: 400px;
background-image: url('img_flowers.jpg');
</style>
</head>
<body>
<div></div>
</body>
</html>
Ejemplo
div {
width: 100%;
height: 400px;
background-image: url('img_flowers.jpg');
background-size: cover;
border: 1px solid red;
}
Ejemplo
/* For width smaller than 400px: */
body {
background-image: url('img_smallflower.jpg');
}
<html>
<head>
<style>
body {
background-repeat: no-repeat;
background-image: url('img_smallflower.jpg');
body {
background-image: url('img_flowers.jpg');
</style>
</head>
<body>
<p style="margin-top:360px;">Resize the browser width and the background image will change at
400px.</p>
</body>
</html>
Puede utilizar la consulta de medios min-device-width, en lugar de min-
width, que comprueba el ancho del dispositivo, en lugar del ancho del
navegador. A continuación, la imagen no cambiará cuando cambie el
tamaño de la ventana del navegador:
Ejemplo
/* For devices smaller than 400px: */
body {
background-image: url('img_smallflower.jpg');
}
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-repeat: no-repeat;
background-image: url('img_smallflower.jpg');
body {
background-image: url('img_flowers.jpg');
</style>
</head>
<body>
</body>
</html>
Ejemplo
<picture>
<source srcset="img_smallflower.jpg" media="(max-width: 400px)">
<source srcset="img_flowers.jpg">
<img src="img_flowers.jpg" alt="Flowers">
</picture>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<picture>
<source srcset="img_flowers.jpg">
</picture>
<p>Resize the browser width and the background image will change at 400px.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
video {
width: 100%;
height: auto;
</style>
</head>
<body>
</video>
<p>Resize the browser window to see how the size of the video player will scale.</p>
</body>
</html>
Ejemplo
video {
max-width: 100%;
height: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
video {
max-width: 100%;
height: auto;
</style>
</head>
<body>
</video>
<p>Resize the browser window to see how the size of the video player will scale when the width is
less than 400px.</p>
</body>
</html>
Ejemplo
video {
width: 100%;
height: auto;
}
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
video {
width: 100%;
height: auto;
.row:after {
content: "";
clear: both;
display: table;
[class*="col-"] {
float: left;
padding: 15px;
width: 100%;
html {
.header {
background-color: #9933cc;
color: #ffffff;
padding: 15px;
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color: #33b5e5;
color: #ffffff;
.menu li:hover {
background-color: #0099cc;
.aside {
background-color: #33b5e5;
padding: 15px;
color: #ffffff;
text-align: center;
font-size: 14px;
.footer {
background-color: #0099cc;
color: #ffffff;
text-align: center;
font-size: 12px;
padding: 15px;
</style>
</head>
<body>
<div class="header">
<h1>Chania</h1>
</div>
<div class="row">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>
<div class="col-6 col-s-9">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two
parts, the old town and the modern city.</p>
</video>
</div>
<div class="aside">
<h2>What?</h2>
<h2>Where?</h2>
<h2>How?</h2>
</div>
</div>
</div>
<div class="footer">
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</body>
</html>
Uso de W3.CSS
Una gran manera de crear un diseño de respuesta, es utilizar una hoja de
estilo de respuesta, como W3.CSS
<div class="w3-row-padding">
<div class="w3-third">
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
</div>
<div class="w3-third">
<h2>Paris</h2>
<p>Paris is the capital of France.</p>
<p>The Paris area is one of the largest population centers in
Europe,
with more than 12 million inhabitants.</p>
</div>
<div class="w3-third">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>
<p>It is the center of the Greater Tokyo Area,
and the most populous metropolitan area in the world.</p>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<body>
<h1>W3Schools Demo</h1>
</div>
<div class="w3-row-padding">
<div class="w3-third">
<h2>London</h2>
<p>London is the capital city of England.</p>
</div>
<div class="w3-third">
<h2>Paris</h2>
</div>
<div class="w3-third">
<h2>Tokyo</h2>
</div>
</div>
</body>
</html>
Bootstrap
Otro framework muy popular es Bootstrap, esteusa HTML, CSS
yjQueryparahacerpaginas web responsive.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3
.7/css/bootstrap.min.css">
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min
.js"></script>
<scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.
min.js"></script>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>My First Bootstrap Page</h1>
</div>
<div class="row">
<div class="col-sm-4">
...
</div>
<div class="col-sm-4">
...
</div>
<div class="col-sm-4">
...
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="jumbotron">
</div>
<div class="row">
<div class="col-sm-4">
<h3>Column 1</h3>
</div>
<div class="col-sm-4">
<h3>Column 2</h3>
</div>
<div class="col-sm-4">
<h3>Column 3</h3>
</div>
</div>
</div>
</body>
</html>