Beruflich Dokumente
Kultur Dokumente
Example
Example description
CSS
.class
.intro
#id
#firstname
element
element,element
div,p
element element
div p
element>element
div>p
element+element
div+p
[attribute]
[target]
[attribute=value]
[target=_blank]
[attribute~=value]
[title~=flower]
[attribute|=value]
[lang|=en]
:link
a:link
:visited
a:visited
:active
a:active
:hover
a:hover
:focus
input:focus
:first-letter
p:first-letter
:first-line
p:first-line
:first-child
p:first-child
:before
p:before
:after
p:after
:lang(language)
p:lang(it)
element1~element2 p~ul
[attribute^=value]
a[src^="https"]
[attribute$=value]
a[src$=".pdf"]
[attribute*=value]
:first-of-type
p:first-of-type
:last-of-type
p:last-of-type
:only-of-type
p:only-of-type
:only-child
p:only-child
:nth-child(n)
p:nth-child(2)
its parent
:nth-last-child(n)
p:nth-last-child(2)
:nth-of-type(n)
p:nth-of-type(2)
:nth-last-of-type(n) p:nth-last-oftype(2)
:last-child
p:last-child
:root
:root
:empty
p:empty
:target
#news:target
:enabled
input:enabled
:disabled
input:disabled
:checked
input:checked
:not(selector)
:not(p)
::selection
::selection
Selector
A qu tags afecta
Cmo est situado el tag respecto a otros tags
*
tag
tag1 tag2
tag1 + tag2
tag:first-child
tag:link
tag :visited
tag:active
tag :hover
tag :focus
tag[atributo]
Un tag con un atributo cuyo valor son varios valores separados por
comas y uno de ellos es valor.
tag.clase
Un tag con atributo class igual a clase. Es una forma abreviada que
permite css de poner tag[class="~valor"]
tag#id
Un tag con atributo id igual a id. Es una forma abreviada que permite
css de poner tag[id="~id"]
Podemos especificar varios elementos separados por comas y el estilo se aplicara a todos ellos
por igual.
a, p {
font-size: 12px;
}
--------------------------Se utilizan para separar palabras clave. Tambin pueden utilizarse para anidar selectores
si son colocados entre estos. Al anidar selectores, el estilo se aplicar al ltimo elemento
mencionado, pero debe cumplirse la condicin de que ste debe estar dentro de los elementos
anteriores. Un ejemplo para aclarar dudas:
div a {
color: orange;
}
Todas las etiquetas a que estn dentro de una etiqueta div tendrn orange (naranja)
--------------------------div#mi_ejemplo {
/* ... */
}
Ese cdigo modificara el estilo de cualquier etiqueta div con id mi_ejemplo. Si le quitamos el
nombre de la etiqueta, el estilo se aplicara a cualquier etiqueta con id mi_ejemplo.
--------------------------Otra caracterstica es que una etiqueta puede tener varias clases a la vez, separadas por
espacios.
Por ejemplo:
<a class=letraGrande subrayado>
Dado que el selector id debe ser nico, es totalmente seguro utilizar el selector univers al
(*#idNombre o #idNombre). Para mejorar la legibilidad y la facilidad en el mantenimiento
suele ser buena idea conservar el nombre del elemento en su lugar (h2#idNombre).
--------------------------Son llamados pseudo-elementos porque en realidad no existen en el documento fuente
(ninguna marca identifica la primer letra de un prrafo, por ejemplo) pero son muy tiles para
seleccionar elementos importantes dentro de la composicin.
CSS 2.1 tiene cuatro pseudo elementos:
:first-line Permite aplicar un estilo determinado a la primera lnea de un prrafo.
:first-letter Permite seleccionar la primer letra de un prrafo, generalmente para utilizarla
como capitular (en un tamao mayor que el resto del prrafo)
:before Permite insertar un contenido antes de un elemento determinado y definir el estilo del
contenido insertado
:after Permite insertar un contenido despus de un elemento determinado y definir el estilo
del contenido insertado
p:first-line { text-transform: uppercase; }
p:first-letter { font-size: 2em; }
h3:before { content: "Tema: "; }
p:after { content: url("icono.gif"); }
body:after {
content: "Fin";
display: block;
}
--------------------------<html>
<head>
<title>Prueba Clases</title>
<style type="text/css">
div.header{
width: 780px;
height: 256px;
border: dotted 1px #999999;
position: relative;
}
div.header div.logo{
float: left;
width: 256px;
height: 256px;
}
div.header div.links{
float: right;
position: relative;
padding-top: 10px;
}
div.header div.links div{
margin-right: 17px;
background-repeat: no-repeat;
background-position: 0 2px;
padding-left: 21px;
}
div.header div.links div.inicio{
float: left;
background-image: url(inicio.png);
background: blue;
}
div.header div.links div.mapa{
float: left;
background-image: url(sitemap.png);
background: green;
}
div.header div.links div.contacto{
float: left;
background-image: url(email.png);
background: red;
}
</style>
</head>
<body>
<div class="header">
<div class="logo"><img src="splash.png" alt="Mi logo" width="256" height="256"
/></div>
<div class="links">
<div class="inicio">Inicio</div>
<div class="mapa">Mapa del Sitio</div>
<div class="contacto">Contctame</div>
</div>
</div>
</body>
</html>
--------------------------You can combine various class selectors together as shown below:
#content, #footer, #supplement {
position: absolute;
left: 510px;
width: 200px;
}
--------------------------Pseudo-classes can be combined with CSS classes:
a.red:visited {color:#FF0000;}
<a class="red" href="css_syntax.asp">CSS Syntax</a>
--------------------------For example, if we have the following CSS declaration,
b.special {
color:#0000FF;
}
i.special {
color:#FF0000;
}
--------------------------.applylarge {
font-size:20px;
}
.applyred {
color:#FF0000;
}
<p class="applylarge applyred">This is an example of multiple classes.</p>
--------------------------h2 {
color: red;
}
.thisOtherClass {
color: red;
}
.yetAnotherClass {
color: red;
}
You could make it:
h2, .thisOtherClass, .yetAnotherClass {
color: red;
}
--------------------------#top {
background-color: #ccc;
padding: 1em
}
#top h1 {
color: #ff0;
}
#top p {
color: red;
font-weight: bold;
}
Removes the need for classes or ID's if it is applied to HTML that looks something like this:
<div id="top">
<h1>Chocolate curry</h1>
<p>This is my recipe for making curry purely with chocolate</p>
<p>Mmm mm mmmmm</p>
</div>
--------------------------td{
font-family: verdana, arial !important;
}
td.micelda{
font-family: monospace;
}