HTML
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="[Link]">
</head>
<body>
</body>
</html>
Head
The HTML <head> element is a container for the following elements:
● <meta>: The <meta> element is typically used to specify the character set, page
description, keywords, author of the document, and viewport settings. The metadata will
not be displayed on the page, but is used by browsers (how to display content or reload
page), by search engines (keywords), and other web services.
○ Setting the viewport to make your website look good on all devices:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
● <link>: Defines the relationship between the current document and an external
resource. The <link> tag is most often used to link to external style sheets:
● <base>: Specifies the base URL and/or target for all relative URLs in a page. The
<base> tag must have either an href or a target attribute present, or both. There can
only be one single <base> element in a document!
Comentarios
<!--Aquí puedo escribir lo que me da la gana y no afectará el código.-->
<!--Al escribir mi código tengo que tener en cuenta que otras personas lo leerán y que
debo facilitarles la tarea.-->
Etiquetas
Etiqueta dentro de etiqueta
Atributos
src (source): usar comillas
alt
Anchor
<a href=”url”> </a>
target
<a href="url">
<img src="source" alt="A cute orange cat lying on its back.">
</a>
Lists
Unordered: <ul><li>
Ordered: ol
list-style-type:square
disc Sets the list item marker to a bullet (default)
circle Sets the list item marker to a circle
squareSets the list item marker to a square
none The list items will not be marked
<html lang="en">
<body>
...
</body>
<!-- Write your comments here -->
Links
<a href="[Link] is a link</a>
FIELDSET
<fieldset>
<label for="first-name">Enter Your First Name: <input id="first-name"/></label>
<label for="last-name">Enter Your Last Name: <input id="last-name"/></label>
<label for="email">Enter Your Email: <input id="email"/></label>
<label for="new-password">Create a New Password: <input
id="new-password"/></label>
</fieldset>
image
Atributos de HTML:
src: (source) Link de la imagen.
alt: Descripción de la imagen por si el link falla.
width y height: Ancho y alto.
Propiedades de CSS:
float: (left o right) Mueve la imagen a la izquierda o derecha.
width y height: Ancho y alto.
background-repeat (no-repeat)
background-image
background-repeat (no-repeat)
background-attachment (fixed)
background-size (cover, 100% 100%)
Sintaxis:
<img src="url" alt="alt text" width="#" height="#">
<img src="url" alt="alt text" style="width:#px;height:#px;"> (recomendable)
URL absoluta: Linkea a una imagen externa hosteada en otro website. La URL no incluye el
nombre del dominio. Ejemplo: src="[Link]
URL relativa: Linkea a una imagen hosteada dentro del sitio web.
Si la URL empieza sin slash, será relativa a la página actual.
Ejemplo: src="[Link]".
Si la URL empieza con slash, será relativa al dominio.
Ejemplo: src="/images/[Link]"
Tip: It is almost always best to use relative URLs. They will not break if you change domain.
MAP
Elemento: <map> (define un mapa a partir de una imagen)
<area> define las áreas clickeables
PICTURE
The <picture> element contains one or more <source> elements, each referring to different
images through the srcset attribute. This way the browser can choose the image that best
fits the current view and/or device.
Each <source> element has a media attribute that defines when the image is the most
suitable.
<picture>
<source media="(min-width: 650px)" srcset="img_food.jpg">
<source media="(min-width: 465px)" srcset="img_car.jpg">
<img src="img_girl.jpg">
</picture>
Note: Always specify an <img> element as the last child element of the <picture> element.
The HTML <picture> element allows you to define different images for different browser
window sizes.
The <img> element is used by browsers that do not support the <picture> element, or if none
of the <source> tags match.
2. Format Support. Some browsers or devices may not support all image formats. By using
the <picture> element, you can add images of all formats, and the browser will use the first
format it recognizes, and ignore any of the following elements.
FAVICON
Agregar ícono a la pestaña
<head>
<title>My Page Title</title>
<link rel="icon" type="image/x-icon" href="/images/[Link]">
</head>
TABLE
<table> Defines a table
<th> Defines a header cell in a table
<tr> Defines a row in a table
<td> Defines a cell in a table (table data)
<caption> Defines a table caption
<colgroup> Specifies a group of one or more columns in a table for formatting
<col> Specifies column properties for each column within a <colgroup> element
<thead> Groups the header content in a table
<tbody> Groups the body content in a table
<tfoot> Groups the footer content in a table
<table>
<caption>Título de tabla</caption>
<tr>
<th>Person 1</th>
<th>Person 2</th>
<th>Person 3</th>
</tr>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
BORDERS
table, th, td {
border: 1px solid black;
border-collapse: collapse; (evita doble borde)
border-radius: 10px; (redondear bordes)
border-color: #96D4D4;
}
tr:nth-child(even) {
background-color: #D6EEEE;
}
td:nth-child(even), th:nth-child(even) {
background-color: #D6EEEE;
}
The <colgroup> element should be used as a container for the column specifications.
The span attribute specifies how many columns that get the style.
width property
visibility property
background properties
border properties
HIPERLINKS
<a href="url">link text</a>
Se puede usar title:
<a href="[Link] title="Go to W3Schools HTML section">Visit
our HTML Tutorial</a>
The target attribute can have one of the following values:
● _self - Default. Opens the document in the same window/tab as it was clicked
● _blank - Opens the document in a new window or tab
● _parent - Opens the document in the parent frame
● _top - Opens the document in the full body of the window
<a href="[Link] target="_blank">Visit W3Schools!</a>
Link a mail:
Use mailto: inside the href attribute to create a link that opens the user's email program
(to let them send a new email):
<a href="[Link] email</a>
Botón:
<button onclick="[Link]='[Link]'">HTML Tutorial</button>
Bookmarks
Horizontal rule
The <hr> tag defines a thematic break in an HTML page, and is most often displayed as
a horizontal rule.
Preformatted text
<pre>
My Bonnie lies over the ocean.
<body style="background-color:powderblue;">
<p style="font-family:courier;">This is a paragraph.</p>
<p style="font-size:160%;">This is a paragraph.</p>
<p style="text-align:center;">Centered paragraph.</p>
The HTML <address> tag defines the contact information for the author/owner of a
document or an article.
The contact information can be an email address, URL, physical address, phone
number, social media handle, etc.
The text in the <address> element usually renders in italic, and browsers will always
add a line break before and after the <address> element.
Layout
The <label> element is useful for screen-reader users, because the screen-reader will read
out loud the label when the user focus on the input element.
The <label> element also help users who have difficulty clicking on very small regions (such
as radio buttons or checkboxes) - because when the user clicks the text within the <label>
element, it toggles the radio button/checkbox.
The for attribute of the <label> tag should be equal to the id attribute of the <input> element
to bind them together.
<input type="radio"> Displays a radio button (for selecting one of many choices)
<input type="checkbox"> Displays a checkbox (for selecting zero or more of many
choices)
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
Form Elements
<form> Defines an HTML form for user input
<input> Defines an input control
<textarea> Defines a multiline input control (text area)
<label> Defines a label for an <input> element
<fieldset> Groups related elements in a form
<legend> Defines a caption for a <fieldset> element
<select> Defines a drop-down list
<optgroup> Defines a group of related options in a drop-down list
<option> Defines an option in a drop-down list
<button> Defines a clickable button
<datalist> Specifies a list of pre-defined options for input controls
<output> Defines the result of a calculation
Select
Textarea
Button
Fieldset
Datalist
<form action="/action_page.php">
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
Output
<form action="/action_page.php"
oninput="[Link]=parseInt([Link])+parseInt([Link])">
0
<input type="range" id="a" name="a" value="50">
100 +
<input type="number" id="b" name="b" value="50">
=
<output name="x" for="a b"></output>
<br><br>
<input type="submit">
</form>
HTML INPUT TYPES
Text
defines a single-line text input field
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
Password
defines a password field
<form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>
Submit
<input type="submit">
defines a button for submitting form data to a form-handler.
The form-handler is typically a server page with a script for processing input data.
The form-handler is specified in the form's action attribute:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
Reset
Defines a reset button that will reset all form values to their default values.
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>
Radio
defines a radio button.
<p>Choose your favorite Web language:</p>
<form>
<input type="radio" id="html" name="fav_language" value="HTML">
<label for="html">HTML</label><br>
<input type="radio" id="css" name="fav_language" value="CSS">
<label for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language" value="JavaScript">
<label for="javascript">JavaScript</label>
</form>
Checkbox
defines a checkbox.
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
button
defines a button:
<input type="button" onclick="alert('Hello World!')" value="Click Me!">
color
used for input fields that should contain a color.
Depending on browser support, a color picker can show up in the input field.
<form>
<label for="favcolor">Select your favorite color:</label>
<input type="color" id="favcolor" name="favcolor">
</form>
date
Is used for input fields that should contain a date. Depending on browser support, a date
picker can show up in the input field.
<form>
<label for="datemax">Enter a date before 1980-01-01:</label>
<input type="date" id="datemax" name="datemax" max="1979-12-31"><br><br>
<label for="datemin">Enter a date after 2000-01-01:</label>
<input type="date" id="datemin" name="datemin" min="2000-01-02">
</form>
Datetime-local
specifies a date and time input field, with no time zone.
Depending on browser support, a date picker can show up in the input field.
<form>
<label for="birthdaytime">Birthday (date and time):</label>
<input type="datetime-local" id="birthdaytime" name="birthdaytime">
</form>
email
is used for input fields that should contain an e-mail address. Depending on browser
support, the e-mail address can be automatically validated when submitted. Some
smartphones recognize the email type, and add ".com" to the keyboard to match email input.
<form>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email">
</form>
image
defines an image as a submit button. The path to the image is specified in the src attribute.
<form>
<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">
</form>
file
defines a file-select field and a "Browse" button for file uploads.
<form>
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
</form>
hidden
defines a hidden input field (not visible to a user).
A hidden field lets web developers include data that cannot be seen or modified by users
when a form is submitted.
A hidden field often stores what database record that needs to be updated when the form is
submitted.
Note: While the value is not displayed to the user in the page's content, it is visible (and can
be edited) using any browser's developer tools or "View Source" functionality. Do not use
hidden inputs as a form of security!
<form>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="hidden" id="custId" name="custId" value="3487">
<input type="submit" value="Submit">
</form>
month
allows the user to select a month and year.
Depending on browser support, a date picker can show up in the input field.
Not supported in Firefox, Safari, or Internet Explorer 11.
<form>
<label for="bdaymonth">Birthday (month and year):</label>
<input type="month" id="bdaymonth" name="bdaymonth">
</form>
number
You can also set restrictions on what numbers are accepted.
The following example displays a numeric input field, where you can enter a value from 1 to
5:
<form>
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number" id="quantity" name="quantity" min="1" max="5">
</form>
input restrictions
checked Specifies that an input field should be pre-selected when the page loads (for
type="checkbox" or type="radio")
disabled Specifies that an input field should be disabled
max Specifies the maximum value for an input field
maxlength Specifies the maximum number of character for an input field
min Specifies the minimum value for an input field
pattern Specifies a regular expression to check the input value against
readonly Specifies that an input field is read only (cannot be changed)
required Specifies that an input field is required (must be filled out)
size Specifies the width (in characters) of an input field
step Specifies the legal number intervals for an input field
value Specifies the default value for an input field
range
defines a control for entering a number whose exact value is not important (like a slider
control). Default range is 0 to 100. However, you can set restrictions on what numbers are
accepted with the min, max, and step attributes:
<form>
<label for="vol">Volume (between 0 and 50):</label>
<input type="range" id="vol" name="vol" min="0" max="50">
</form>
search
is used for search fields (a search field behaves like a regular text field).
<form>
<label for="gsearch">Search Google:</label>
<input type="search" id="gsearch" name="gsearch">
</form>
tel
is used for input fields that should contain a telephone number.
<form>
<label for="phone">Enter your phone number:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">
</form>
time
allows the user to select a time (no time zone).
Depending on browser support, a time picker can show up in the input field.
<form>
<label for="appt">Select a time:</label>
<input type="time" id="appt" name="appt">
</form>
url
is used for input fields that should contain a URL address.
Depending on browser support, the url field can be automatically validated when submitted.
Some smartphones recognize the url type, and adds ".com" to the keyboard to match url
input.
<form>
<label for="homepage">Add your homepage:</label>
<input type="url" id="homepage" name="homepage">
</form>
week
allows the user to select a week and year.
Depending on browser support, a date picker can show up in the input field.
<form>
<label for="week">Select a week:</label>
<input type="week" id="week" name="week">
</form>
<input type="submit">
readonly
The input readonly attribute specifies that an input field is read-only.
A read-only input field cannot be modified (however, a user can tab to it, highlight it, and
copy the text from it).
The value of a read-only input field will be sent when submitting the form!
disabled
The input disabled attribute specifies that an input field should be disabled.
A disabled input field is unusable and un-clickable.
The value of a disabled input field will not be sent when submitting the form!
size
The input size attribute specifies the visible width, in characters, of an input field.
The default value for size is 20.
Note: The size attribute works with the following input types: text, search, tel, url, email, and
password.
maxlength
The input maxlength attribute specifies the maximum number of characters allowed in an
input field.
Note: When a maxlength is set, the input field will not accept more than the specified number
of characters. However, this attribute does not provide any feedback. So, if you want to alert
the user, you must write JavaScript code.
The input min and max attributes specify the minimum and maximum values for an input
field.
The min and max attributes work with the following input types: number, range, date,
datetime-local, month, time and week.
Tip: Use the max and min attributes together to create a range of legal values.
multiple
The input multiple attribute specifies that the user is allowed to enter more than one value in
an input field.
The multiple attribute works with the following input types: email, and file.
pattern
The input pattern attribute specifies a regular expression that the input field's value is
checked against, when the form is submitted.
The pattern attribute works with the following input types: text, date, search, url, tel, email,
and password.
Tip: Use the global title attribute to describe the pattern to help the user.
<form>
<label for="country_code">Country code:</label>
<input type="text" id="country_code" name="country_code"
pattern="[A-Za-z]{3}" title="Three letter country code">
</form>
placeholder
The input placeholder attribute specifies a short hint that describes the expected value of an
input field (a sample value or a short description of the expected format).
The short hint is displayed in the input field before the user enters a value.
The placeholder attribute works with the following input types: text, search, url, tel, email,
and password.
required
The input required attribute specifies that an input field must be filled out before submitting
the form.
The required attribute works with the following input types: text, search, url, tel, email,
password, date pickers, number, checkbox, radio, and file.
step
The input step attribute specifies the legal number intervals for an input field.
Tip: This attribute can be used together with the max and min attributes to create a range of
legal values.
The step attribute works with the following input types: number, range, date, datetime-local,
month, time and week.
autofocus
The input autofocus attribute specifies that an input field should automatically get focus
when the page loads.
Tip: Always specify both the height and width attributes for images. If height and width are
set, the space required for the image is reserved when the page is loaded. Without these
attributes, the browser does not know the size of the image, and cannot reserve the
appropriate space to it. The effect will be that the page layout will change during loading
(while the images load).
list
The input list attribute refers to a <datalist> element that contains pre-defined options for an
<input> element.
<form>
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
autocomplete
The input autocomplete attribute specifies whether a form or an input field should have
autocomplete on or off.
Autocomplete allows the browser to predict the value. When a user starts to type in a field,
the browser should display options to fill in the field, based on earlier typed values.
The autocomplete attribute works with <form> and the following <input> types: text, search,
url, tel, email, password, datepickers, range, and color.
CSS
Each declaration includes a CSS property name and a value, separated by a colon.
Multiple CSS declarations are separated with semicolons, and declaration blocks are
surrounded by curly braces.
Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
Simple selectors
The element selector selects HTML elements based on the element name.
p{
text-align: center;
color: red;
}
To select elements with a specific class, write a period (.) character, followed by the
class name.
.center {
text-align: center;
color: red;
}
[Link] {
text-align: center;
color: red;
}
solo los párrafo clase center <p class=”center”>
Comments
/* This is a single-line comment */
/* This is
a multi-line
comment */
background-image
By default, the background-image property repeats an image both horizontally and vertically.
body {
background-image: url("gradient_bg.png");
}
background-repeat
By default, the background-image property repeats an image both horizontally and vertically.
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x; /* solo repite en eje x */
}
Showing the background image only once is also specified by the background-repeat
property:
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
}
background-position
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
background-attachment
The background-attachment property specifies whether the background image should
scroll or be fixed (will not scroll with the rest of the page):
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
background-attachment: fixed/scroll;
}
Shorthand property
En lugar de escribir:
body {
background-color: #ffffff;
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
Podemos escribir:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
When using the shorthand property the order of the property values is:
1. background-color
2. background-image
3. background-repeat
4. background-attachment
5. background-position
It does not matter if one of the property values is missing, as long as the other ones are
in this order. Note that we do not use the background-attachment property in the
examples above, as it does not have a value.
Propiedad Descripción
border
border-style
The border-style property can have from one to four values (for the top border, right border,
bottom border, and the left border).
Note: None of the OTHER CSS border properties (which you will learn more about in the
next chapters) will have ANY effect unless the border-style property is set!
border-width
The border-width property specifies the width of the four borders.
The width can be set as a specific size (in px, pt, cm, em, etc) or by using one of the
three pre-defined values: thin, medium, or thick:
Cuando se da un valor, éste define todos los bordes.
Cuando se dan dos valores, el primero define top y bot, mientras que el segundo define
L y R.
Cuando se dan tres valores, el primero define top, el segundo define L y R, y, el tercero,
bot.
Cuando se dan cuatro valores, el primero define top, el segundo, R, el tercero bot y el
cuarto L.
border-radius
redondea bordes
The border property is a shorthand property for the following individual border properties:
border-width
border-style (required)
border-color
margin
All the margin properties can have the following values:
auto
You can set the margin property to auto to horizontally center the element within its
container.
The element will then take up the specified width, and the remaining space will be split
equally between the left and right margins.
margin collapse
Top and bottom margins of elements are sometimes collapsed into a single margin that is
equal to the largest of the two margins.
This does not happen on left and right margins! Only top and bottom margins!
padding
The CSS padding properties are used to generate space around an element's content,
inside of any defined borders.
The CSS width property specifies the width of the element's content area. The content
area is the portion inside the padding, border, and margin of an element (the box model).
So, if an element has a specified width, the padding added to that element will be added
to the total width of the element. This is often an undesirable result.
To keep the width, no matter the amount of padding, you can use the box-sizing
property. This causes the element to maintain its actual width; if you increase the
padding, the available content space will decrease.
box-sizing: border-box;
height/width
The height and width properties are used to set the height and width of an element.
The height and width properties do not include padding, borders, or margins. It sets the
height/width of the area inside the padding, border, and margin of the element.
The height and width properties may have the following values:
auto - This is default. The browser calculates the height and width
length - Defines the height/width in px, cm, etc.
% - Defines the height/width in percent of the containing block
initial - Sets the height/width to its default value
inherit - The height/width will be inherited from its parent value
Note: Remember that the height and width properties do not include padding, borders, or
margins! They set the height/width of the area inside the padding, border, and margin of the
element!
The max-width can be specified in length values, like px, cm, etc., or in percent (%) of the
containing block, or set to none (this is default. Means that there is no maximum width).
The problem with the <div> above occurs when the browser window is smaller than the
width of the element (500px). The browser then adds a horizontal scrollbar to the page.
Using max-width instead, in this situation, will improve the browser's handling of small
windows.
Note: If you for some reason use both the width property and the max-width property on the
same element, and the value of the width property is larger than the max-width property; the
max-width property will be used (and the width property will be ignored).
● Content - The content of the box, where text and images appear
● Padding - Clears an area around the content. The padding is transparent
● Border - A border that goes around the padding and content
● Margin - Clears an area outside the border. The margin is transparent
Important: When you set the width and height properties of an element with CSS, you just
set the width and height of the content area. To calculate the full size of an element, you
must also add padding, borders and margins.
outline
An outline is a line that is drawn around elements, OUTSIDE the borders, to make the
element "stand out".
outline-style
outline-color
outline-width
outline-offset
outline
Note: Outline differs from borders! Unlike border, the outline is drawn outside the element's
border, and may overlap other content. Also, the outline is NOT a part of the element's
dimensions; the element's total width and height is not affected by the width of the outline.
width
The outline-width property specifies the width of the outline, and can have one of the
following values:
shorthand
The outline property is a shorthand property for setting the following individual outline
properties:
● outline-width
● outline-style (required)
● outline-color
outline-offset
The outline-offset property adds space between an outline and the edge/border of an
element. The space between an element and its outline is transparent.
text
color
background-color: lightgrey;
color: blue;
text-align
The text-align property is used to set the horizontal alignment of a text. A text can be left or
right aligned, centered, or justified.
text-align: center/right/left/justify;
text-align-last
The text-align-last property specifies how to align the last line of a text.
text-align-last: center/right/left/justify;
direction
The direction and unicode-bidi properties can be used to change the text direction of an
element:
direction: rtl;
unicode-bidi: bidi-override;
vertical-align
The vertical-align property sets the vertical alignment of an element.
vertical-align: baseline/text-top/text-bottom/sub/super;
text-decoration
text-decoration-line
The text-decoration-line property is used to add a decoration line to text.
text-decoration-line: overline/line-through/underline/overline underline/none;
text-decoration-color
The text-decoration-color property is used to set the color of the decoration line.
text-decoration-color: red;
text-decoration-style
The text-decoration-style property is used to set the style of the decoration line.
text-decoration-style: solid/double/dotted/dashed/wavy;
text-decoration-thickness
The text-decoration-thickness property is used to set the thickness of the decoration line.
text-decoration-thickness: auto/5px/25%;
shorthand
The text-decoration property is a shorthand property for:
● text-decoration-line (required)
● text-decoration-color (optional)
● text-decoration-style (optional)
● text-decoration-thickness (optional)
text-transform
The text-transform property is used to specify uppercase and lowercase letters in a text. It
can be used to turn everything into uppercase or lowercase letters, or capitalize the first
letter of each word:
text-transform: uppercase/lowercase/capitalize;
Text Spacing
text-indent
The text-indent property is used to especifica la sangría:
text-indent: 50px;
letter-spacing
The letter-spacing property is used to specify the space between the characters in a text.
acepta valores positivos o negativos
letter-spacing: 5px;
letter-spacing: -2px;
line-height
The line-height property is used to specify the space between lines:
line-height: 0.8;
word-spacing
The word-spacing property is used to specify the space between the words in a text.
acepta valores positivos o negativos
word-spacing: 5px;
word-spacing: -2px;
white-space
The white-space property specifies how white-space inside an element is handled. Ajuste de
línea de notepad.
white-space: nowrap;
text-shadow
The text-shadow property adds shadow to text.
In its simplest use, you only specify the horizontal shadow (2px) and the vertical shadow
(2px):
font
font-family
Note: If the font name is more than one word, it must be in quotation marks, like: "Times
New Roman".
Tip: The font-family property should hold several font names as a "fallback" system, to
ensure maximum compatibility between browsers/operating systems. Start with the font you
want, and end with a generic family (to let the browser pick a similar font in the generic
family, if no other fonts are available). The font names should be separated with comma.
Web safe fonts are fonts that are universally installed across all browsers and devices.
However, there are no 100% completely web safe fonts. There is always a chance that a
font is not found or is not installed properly.
This means that you should add a list of similar "backup fonts" in the font-family property. If
the first font does not work, the browser will try the next one, and the next one, and so on.
Always end the list with a generic font family name.
The following list are the best web safe fonts for HTML and CSS:
● Arial (sans-serif)
● Verdana (sans-serif)
● Tahoma (sans-serif)
● Trebuchet MS (sans-serif)
● Times New Roman (serif)
● Georgia (serif)
● Garamond (serif)
● Courier New (monospace)
● Brush Script MT (cursive)
Note: Before you publish your website, always check how your fonts appear on different
browsers and devices, and always use fallback fonts!
font-style
The font-style property is mostly used to specify italic text.
font-variant
The font-variant property specifies whether or not a text should be displayed in a small-caps
font.
In a small-caps font, all lowercase letters are converted to uppercase letters. However, the
converted uppercase letters appear in a smaller font size than the original uppercase letters
in the text.
font-variant: normal/small-caps;
font-size
The font-size property sets the size of the text.
Being able to manage the text size is important in web design. However, you should not use
font size adjustments to make paragraphs look like headings, or headings look like
paragraphs.
Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for paragraphs.
Absolute size:
Setting the text size with pixels gives you full control over the text size
Tip: If you use pixels, you can still use the zoom tool to resize the entire page.
To allow users to resize the text (in the browser menu), many developers use em instead of
pixels.
1em is equal to the current font size. The default text size in browsers is 16px. So, the
default size of 1em is 16px.
The size can be calculated from pixels to em using this formula: pixels/16=em
In the example above, the text size in em is the same as the previous example in pixels.
However, with the em size, it is possible to adjust the text size in all browsers.
Unfortunately, there is still a problem with older versions of Internet Explorer. The text
becomes larger than it should when made larger, and smaller than it should when made
smaller.
The solution that works in all browsers, is to set a default font-size in percent for the <body>
element:
The text size can be set with a vw unit, which means the "viewport width".
That way the text size will follow the size of the browser window:
<h1 style="font-size:10vw">Hello World</h1>
Viewport is the browser window size. 1vw = 1% of viewport width. If the viewport is 50cm
wide, 1vw is 0.5cm.
Google Fonts
Just add a special style sheet link in the <head> section and then refer to the font in the
CSS.
<head>
<link rel="stylesheet" href="[Link]
family=Sofia">
<style>
body {
font-family: "Sofia", sans-serif;
}
</style>
</head>
Note: When specifying a font in CSS, always list at minimum one fallback font (to avoid
unexpected behaviors). So, also here you should add a generic font family (like serif or sans-
serif) to the end of the list.
To use multiple Google fonts, just separate the font names with a pipe character (|), like this:
<link rel="stylesheet" href="[Link]
family=Audiowide|Sofia|Trirong">
Note: Requesting multiple fonts may slow down your web pages! So be careful about that.
Google has also enabled different font effects that you can use.
First add effect=effectname to the Google API, then add a special class name to the element
that is going to use the special effect. The class name always starts with font-effect- and
ends with the effectname.
To request multiple font effects, just separate the effect names with a pipe character (|), like
this:
<head>
<link rel="stylesheet" href="[Link]
family=Sofia&effect=neon|outline|emboss|shadow-multiple">
<style>
body {
font-family: "Sofia", sans-serif;
font-size: 30px;
}
</style>
</head>
<body>
</body>
1. Complement
It is always safe to find font pairings that complement one another.
A great font combination should harmonize, without being too similar or too different.
3. Contrast is King
Two fonts that are too similar will often conflict. However, contrasts, done the right way,
brings out the best in each font.
A strong superfamily includes both serif and sans serif variations of the same font (e.g.
Lucida and Lucida Sans).
Below, we have shown some popular font pairings that will suit many brands and contexts.
Shorthand
font-style
font-variant
font-weight
font-size/line-height
font-family
Note: The font-size and font-family values are required. If one of the other values is missing,
their default value are used.
Icons
The simplest way to add an icon to your HTML page, is with an icon library, such as Font
Awesome.
Add the name of the specified icon class to any inline HTML element (like <i> or <span>).
All the icons in the icon libraries below, are scalable vectors that can be customized with
CSS (size, color, shadow, etc.)
To use the Font Awesome icons, go to [Link], sign in, and get a code to add in
the <head> section of your HTML page:
<script src="[Link]
crossorigin="anonymous"></script>
To use the Bootstrap glyphicons, add the following line inside the <head> section of your
HTML page:
<link rel="stylesheet"
href="[Link]
[Link]">
To use the Google icons, add the following line inside the <head> section of your HTML
page:
<link rel="stylesheet"
href="[Link]
family=Material+Icons">
links
Links can be styled with any CSS property (e.g. color, font-family, background, etc.).
In addition, links can be styled differently depending on what state they are in.
When setting the style for several link states, there are some order rules:
Tipos de cursores
auto
crosshair
default
e-resize
help
move
n-resize
ne-resize
nw-resize
pointer
progress
s-resize
se-resize
sw-resize
text
w-resize
wait
lists
list-style-type
list-style-position
The list-style-position property specifies the position of the list-item markers (bullet points).
"list-style-position: outside;" means that the bullet points will be outside the list item. The
start of each line of a list item will be aligned vertically. This is default:
"list-style-position: inside;" means that the bullet points will be inside the list item. As it is part
of the list item, it will be part of the text and push the text at the start:
The list-style-type:none property can also be used to remove the markers/bullets. Note that
the list also has default margin and padding. To remove this, add margin:0 and padding:0 to
<ul> or <ol>:
Shorthand
When using the shorthand property, the order of the property values are:
list-style-type (if a list-style-image is specified, the value of this property will be displayed if
the image for some reason cannot be displayed)
list-style-position (specifies whether the list-item markers should appear inside or outside the
content flow)
list-style-image (specifies an image as the list item marker)
If one of the property values above is missing, the default value for the missing property will
be inserted, if any.
tables
responsive table
A responsive table will display a horizontal scroll bar if the screen is too small to display the
full content:
Add a container element (like <div>) with overflow-x:auto around the <table> element to
make it responsive:
display
display Specifies how an element should be displayed
visibility Specifies whether or not an element should be visible
position
The position property specifies the type of positioning method used for an element.
static
HTML elements are positioned static by default.
Static positioned elements are not affected by the top, bottom, left, and right properties.
An element with position: static; is not positioned in any special way; it is always positioned
according to the normal flow of the page
relative
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause
it to be adjusted away from its normal position. Other content will not be adjusted to fit into
any gap left by the element.
fixed
An element with position: fixed; is positioned relative to the viewport, which means it always
stays in the same place even if the page is scrolled. The top, right, bottom, and left
properties are used to position the element.
A fixed element does not leave a gap in the page where it would normally have been
located.
absolute
An element with position: absolute; is positioned relative to the nearest positioned ancestor
(instead of positioned relative to the viewport, like fixed).
Note: Absolute positioned elements are removed from the normal flow, and can overlap
elements.
sticky
An element with position: sticky; is positioned based on the user's scroll position.
A sticky element toggles between relative and fixed, depending on the scroll position. It is
positioned relative until a given offset position is met in the viewport - then it "sticks" in place
(like position:fixed).
Note: Internet Explorer does not support sticky positioning. Safari requires a -webkit- prefix
(see example below). You must also specify at least one of top, right, bottom or left for sticky
positioning to work.
z-index Property
When elements are positioned, they can overlap other elements.
The z-index property specifies the stack order of an element (which element should be
placed in front of, or behind, the others).
An element with greater stack order is always above an element with a lower stack order.
If two positioned elements overlap each other without a z-index specified, the element
defined last in the HTML code will be shown on top.
overflow
The overflow property specifies whether to clip the content or to add scrollbars when the
content of an element is too big to fit in the specified area.
Note: In OS X Lion (on Mac), scrollbars are hidden by default and only shown when being
used (even though "overflow:scroll" is set).
visible
By default, the overflow is visible, meaning that it is not clipped and it renders outside the
element's box
hidden
With the hidden value, the overflow is clipped, and the rest of the content is hidden
scroll
Setting the value to scroll, the overflow is clipped and a scrollbar is added to scroll inside the
box. Note that this will add a scrollbar both horizontally and vertically (even if you do not
need it)
auto
The auto value is similar to scroll, but it adds scrollbars only when necessary
overflow-x/y
The overflow-x and overflow-y properties specifies whether to change the overflow of
content just horizontally or vertically (or both):
float
The CSS float property specifies how an element should float.
The float property is used for positioning and formatting content e.g. let an image float left to
the text in a container.
clear
The CSS clear property specifies what elements can float beside the cleared element and on
which side.
When we use the float property, and we want the next element below (not on right or left),
we will have to use the clear property.
The clear property specifies what should happen with the element that is next to a floating
element.
none - The element is not pushed below left or right floated elements. This is default
left - The element is pushed below left floated elements
right - The element is pushed below right floated elements
both - The element is pushed below both left and right floated elements
inherit - The element inherits the clear value from its parent
When clearing floats, you should match the clear to the float: If an element is floated to the
left, then you should clear to the left. Your floated element will continue to float, but the
cleared element will appear below it on the web page.
The overflow: auto clearfix works well as long as you are able to keep control of your
margins and padding (else you might see scrollbars). The new, modern clearfix hack
however, is safer to use, and the following code is used for most webpages
.clearfix::after {
content: "";
clear: both;
display: table;
}
inline-block
Compared to display: inline, the major difference is that display: inline-block allows to set a
width and height on the element.
Also, with display: inline-block, the top and bottom margins/paddings are respected, but with
display: inline they are not.
Compared to display: block, the major difference is that display: inline-block does not add a
line-break after the element, so the element can sit next to other elements.
combinators
A combinator is something that explains the relationship between the selectors.
A CSS selector can contain more than one simple selector. Between the simple selectors,
we can include a combinator.
Pseudo-classes
:first-child p:first-child Selects every <p> elements that is the first child of its
parent
:first-of-type p:first-of-type Selects every <p> element that is the first <p> element
of its parent
:lang(language) p:lang(it) Selects every <p> element with a lang attribute value
starting with "it"
:last-child p:last-child Selects every <p> elements that is the last child of its
parent
:last-of-type p:last-of-type Selects every <p> element that is the last <p> element
of its parent
:nth-child(n) p:nth-child(2) Selects every <p> element that is the second child of
its parent
:nth-last-child(n) p:nth-last-child(2) Selects every <p> element that is the second child of
its parent, counting from the last child
:nth-last-of-type(n) p:nth-last-of-type(2) Selects every <p> element that is the second <p>
element of its parent, counting from the last child
:nth-of-type(n) p:nth-of-type(2) Selects every <p> element that is the second <p>
element of its parent
:only-of-type p:only-of-type Selects every <p> element that is the only <p>
element of its parent
:only-child p:only-child Selects every <p> element that is the only child of its
parent
selector:pseudo-class {
property: value;
}
/* unvisited link */
a:link {}
/* visited link */
a:visited {}
/* mouse over link */
a:hover {}
/* selected link */
a:active {}
Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be
effective! a:active MUST come after a:hover in the CSS definition in order to be effective!
Pseudo-class names are not case-sensitive.
div:hover {}
/* apunta a todos los <div> */
first-child
The :first-child pseudo-class matches a specified element that is the first child of another
element.
Pseudo Elements
A CSS pseudo-element is used to style specified parts of an element.
opacity
The opacity property specifies the opacity/transparency of an element.
The opacity property can take a value from 0.0 - 1.0. The lower the value, the more
transparent:
BOOTSTRAP
Para añadir BOOTSTRAP:
<link rel="stylesheet"
href="[Link]
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/
K68vbdEjh4u" crossorigin="anonymous"/>
You can include Font Awesome in any app by adding the following code to the top of your
HTML:
<link rel="stylesheet" href="[Link]
integrity="sha384-
50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf"
crossorigin="anonymous">
The i element was originally used to make other elements italic, but is now commonly used
for icons. You can add the Font Awesome classes to the i element to turn it into an icon, for
example:
<i class="fas fa-info-circle"></i>
class="text-primary text-center
Create a Bootstrap Button
Bootstrap has its own styles for button elements, which look much better than the plain
HTML ones.
Create a new button element below your large kitten photo. Give it the btn and btn-default
classes, as well as the text of Like.
By making them block elements with the additional class of btn-block, your button will stretch
to fill your page's entire horizontal space and any elements following it will flow onto a "new
line" below the block.
Note that this button will still need the btn and btn-block classes.
Create a button with the text Delete and give it the class btn-danger.
Note that these buttons still need the btn and btn-block classes.
Bootstrap has different column width attributes that it uses depending on how wide the
user's screen is. For example, phones have narrow screens, and laptops have wider
screens.
Take for example Bootstrap's col-md-* class. Here, md means medium, and * is a number
specifying how many columns wide the element should be. In this case, the column width of
an element on a medium-sized screen, such as a laptop, is being specified.
In the Cat Photo App that we're building, we'll use col-xs-*, where xs means extra small (like
an extra-small mobile phone screen), and * is the number of columns specifying how many
columns wide the element should be.
Put the Like, Info and Delete buttons side-by-side by nesting all three of them within one
<div class="row"> element, then each of them within a <div class="col-xs-4"> element.
The row class is applied to a div, and the buttons themselves can be nested within it.
JQUERY
$(document).ready(function() {
});
All jQuery functions start with a $, usually referred to as a dollar sign operator, or as bling.
$("button").addClass("animated bounce");
Note that, just like with CSS declarations, you type a . before the class's name.
$(".well").addClass("animated shake");
Note that, just like with CSS declarations, you type a # before the id's name.
$("#target3").addClass("animated fadeOut")
Now you know three ways of targeting elements: by type: $("button"), by class: $(".btn"), and
by id $("#target1").
In the same way you can add classes to an element with jQuery's addClass() function, you
can remove them with jQuery's removeClass() function.
$("#target2").removeClass("btn-default");
jQuery has a function called .css() that allows you to change the CSS of an element.
$("#target1").css("color", "blue");
This is slightly different from a normal CSS declaration, because the CSS property and its
value are in quotes, and separated with a comma instead of a colon.
When you disable a button, it will become grayed-out and can no longer be clicked.
jQuery has a function called .prop() that allows you to adjust the properties of elements.
$("button").prop("disabled", true);
Here's how you would rewrite and emphasize the text of our heading:
$("h3").html("<em>jQuery Playground</em>");
jQuery also has a similar function called .text() that only alters text without adding tags. In
other words, this function will not evaluate any HTML tags passed to it, but will instead treat
it as the text you want to replace the existing content with.
jQuery has a function called .remove() that will remove an HTML element entirely
jQuery has a function called appendTo() that allows you to select HTML elements and
append them to another element.
For example, if we wanted to move target4 from our right well to our left well, we would use:
$("#target4").appendTo("#left-well");
For example, if we wanted to copy target2 from our left-well to our right-well, we would use:
$("#target2").clone().appendTo("#right-well");
Did you notice this involves sticking two jQuery functions together? This is called function
chaining and it's a convenient way to get things done with jQuery.
Target the Parent of an Element Using jQuery
Every HTML element has a parent element from which it inherits properties.
jQuery has a function called parent() that allows you to access the parent of whichever
element you've selected.
Here's an example of how you would use the parent() function if you wanted to give the
parent element of the left-well element a background color of blue:
$("#left-well").parent().css("background-color", "blue")
jQuery has a function called children() that allows you to access the children of whichever
element you've selected.
Here's an example of how you would use the children() function to give the children of your
left-well element the color blue:
$("#left-well").children().css("color", "blue")
Fortunately, jQuery has some other tricks for targeting the right elements.
jQuery uses CSS Selectors to target elements. The target:nth-child(n) CSS selector allows
you to select all the nth elements with the target class or element type.
Here's how you would give the third element in each well the bounce class:
$(".target:nth-child(3)").addClass("animated bounce");
Here's how you would target all the odd elements with class target and give them classes:
$(".target:odd").addClass("animated shake");
Here's how we would make the entire body fade out: $("body").addClass("animated
fadeOut");
SASS
Store Data with Sass Variables
One feature of Sass that's different than CSS is it uses variables. They are declared and set
to store data, similar to JavaScript.
In JavaScript, variables are defined using the let and const keywords. In Sass, variables
start with a $ followed by the variable name.
h1 {
font-family: $main-fonts;
color: $headings-color;
}
One example where variables are useful is when a number of elements need to be the same
color. If that color is changed, the only place to edit the code is the variable value.
Create Reusable CSS with Mixins
In Sass, a mixin is a group of CSS declarations that can be reused throughout the style
sheet.
Newer CSS features take time before they are fully adopted and ready to use in all
browsers. As features are added to browsers, CSS rules using them may need vendor
prefixes. Consider box-shadow:
div {
-webkit-box-shadow: 0px 0px 4px #fff;
-moz-box-shadow: 0px 0px 4px #fff;
-ms-box-shadow: 0px 0px 4px #fff;
box-shadow: 0px 0px 4px #fff;
}
It's a lot of typing to re-write this rule for all the elements that have a box-shadow, or to
change each value to test different effects. Mixins are like functions for CSS. Here is how to
write one:
div {
@include box-shadow(0px, 0px, 4px, #fff);
}
@mixin make-bold($bool) {
@if $bool == true {
font-weight: bold;
}
}
And just like in JavaScript, @else if and @else test for more conditions:
@mixin text-effect($val) {
@if $val == danger {
color: red;
}
@else if $val == alert {
color: yellow;
}
@else if $val == success {
color: green;
}
@else {
color: black;
}
}