Now for the nitty gritty of what makes a webpage look the way it does. Almost all formatting and design in HTML is done with CSS, there are two main types of CSS. There is Inline CSS which has the CSS inside the element, usually in the form of the style attribute. We can also do internal CSS by using CSS in the <head> of the document or even external CSS by linking to a stylesheet not actually part of the document. We are going to cover all forms of CSS in this section and proper CSS usage along with some examples to help you better understand how to style with CSS. First we will go over the most common of the CSS properties and potential values for each property.
Here is a list of the CSS properties
color
Sets the color of text
opacity
Sets the opacity level for an element
background
A shorthand property for setting all the background properties in one declaration
background-attachment
Sets whether a background image is fixed or scrolls with the rest of the page
background-blend-mode
Specifies the blending mode of each background layer (color/image)
background-color
Specifies the background color of an element
background-image
Specifies one or more background images for an element
background-position
Specifies the position of a background image
background-repeat
Sets how a background image will be repeated
background-clip
Specifies the painting area of the background
background-origin
Specifies where the background image(s) is/are positioned
background-size
Specifies the size of the background image(s)
border
Sets all the border properties in one declaration
border-bottom
Sets all the bottom border properties in one declaration
border-color
Sets the color of the four borders
border-image
A shorthand property for setting all the border-image-* properties
display
Specifies how a certain HTML element should be displayed
float
Specifies whether or not a box should float
height
Sets the height of an element
left
Specifies the left position of a positioned element
margin
Sets all the margin properties in one declaration
padding
Sets all the padding properties in one declaration
visibility
Specifies whether or not an element is visible
width
Sets the width of an element
hanging-punctuation
Specifies whether a punctuation character may be placed outside the line box
hyphens
Sets how to split words to improve the layout of paragraphs
letter-spacing
Increases or decreases the space between characters in a text
line-break
Specifies how/if to break lines
line-height
Sets the line height
tab-size
Specifies the length of the tab-character
text-align
Specifies the horizontal alignment of text
text-align-last
Describes how the last line of a block or a line right before a forced line break is aligned when text-align is "justify"
text-indent
Specifies the indentation of the first line in a text-block
text-justify
Specifies the justification method used when text-align is "justify"
white-space
Specifies how white-space inside an element is handled
word-spacing
Increases or decreases the space between words in a text
word-wrap
Allows long, unbreakable words to be broken and wrap to the next line
text-decoration
Specifies the decoration added to text
text-decoration-color
Specifies the color of the text-decoration
text-decoration-line
Specifies the type of line in a text-decoration
text-decoration-style
Specifies the style of the line in a text decoration
text-shadow
Adds shadow to text
font
Sets all the font properties in one declaration
font-family
Specifies the font family for text
font-kerning
Controls the usage of the kerning information (how letters are spaced)
font-size
Specifies the font size of text
font-style
Specifies the font style for text
direction
Specifies the text direction/writing direction
text-orientation
Defines the orientation of the text in a line
border-collapse
Specifies whether or not table borders should be collapsed
border-spacing
Specifies the distance between the borders of adjacent cells
list-style
Sets all the properties for a list in one declaration
list-style-image
Specifies an image as the list-item marker
list-style-position
Specifies if the list-item markers should appear inside or outside the content flow
list-style-type
Specifies the type of list-item marker
ime-mode
Controls the state of the input method editor for text fields
nav-down
Specifies where to navigate when using the arrow-down navigation key
outline
Sets all the outline properties in one declaration
outline-color
Sets the color of an outline
outline-offset
Offsets an outline, and draws it beyond the border edge
outline-style
Sets the style of an outline
outline-width
Sets the width of an outlin
column-fill
Specifies how to fill columns
column-gap
Specifies the gap between the columns
column-rule
A shorthand property for setting all the column-rule-* properties
column-span
Specifies how many columns an element should span across
column-width
Specifies the width of the columns
columns
A shorthand property for setting column-width and column-count
Now that we have our CSS list to work with we can start styling our pages. First we are going to go ahead and cover some inline CSS, although it has been used throughout this guide I haven't really gone to far in depth about it. Inline CSS is CSS that is used inside each individual elemental, here are a few examples of inline CSS. Each of these examples will go over how the CSS is working with the elelment to style the page.
First we will start with the style attribute
Code:
<body style="background-color:blue;color:red;">
This is an example if inline CSS, when using the style attribute to add CSS to an element remember to always wrap the property in double quotes. The CSS in the style attribute is set up in a way that it is {property}{colon}{value}{semicolon}. this may be repeated as many times as you'd like for each additional property. It is important to remember to always trail the last value with a semicolon otherwise it will mess up the page.
Now we will talk a little more about internal CSS. Internal CSS uses classes and IDs to pass CSS from the <style> element in the head to individual elements or groups of elements in the body of the document. A side note, <style> is both an element and an attribute, and while the style attribute is a global attribute it cannot be used in the <style> element. We are going to use the <style> element to create CSS in the head of the document and then afterword we are going to call this CSS from the body.
Code:
<style>
div.para {
background-color:red;
color:white;
margin:20px;
padding:20px;
}
p {
background-color:white;
colo:blue;
margin:20px;
padding:20px;
]
#para3 {
background-color:blue;
color:white;
margin:20px;
padding:20px;
}
</style>
This can be used to define styles for the entire document and most webpages uses severl ID's and classes in conjunction with one another to get the best looking results. for the previous style example we woould need elements within the boday that can handle these elements.
[code]<body>
<div class="para">
<p>This is going to be displayed using the CSS style of the class <q>para</q> in the head of the document</p>
</div>
<p>This will be displayed using the paragraph style listed in our CSS. This is because it isn't in a div container or using any special ID.</p>
<div class="para">
<p id="para3">This will be displayed using the CSS para3 in our head, this is because individual tags override any container CSS we have on the parent element.</p>
</div>
</body>
Now that we have establised a working understanding of how CSS works with IDs and classes we can put our page together and check out what we have done so far. I am going to provide a full webpage covering as many aspects from this tutorial as I can and use CSS to style it and make it look nice.
Code:
<!DOCTYPE html>
<html>
<head>
<title>What we have done so far</title>
<meta charset="UTF-8">
<meta name="keywords" value="html,tutorial,guide,hackforums">
<meta name="author" value="RenRioku">
<style>
ul#nav li {
display:inline;
}
body {
background-image: url("https://hackforums.net/images/modern_pl/mosaic.png");
background-attachment: fixed;
background-repeat: repeat-xy;
color:white;
}
div.finish {
text-align:center;
width:70%;
}
#fin01 {
background-color:red;
color:white
border:1px solid black;
padding:5px;
}
#fin02 {
background-color:white;
color:blue;
border:1px solid black;
padding:5px;
}
#fin03 {
background-color:blue;
color:white
border:1px solid black;
padding:5px;
}
</style>
</head>
<body>
<p><iframe src="https://hackforums.net" name="frame" height="400" width="100%"></iframe></p>
<p><ul id="nav">
<li><a href="https://hackforums.net/forumdisplay.php?fid=134" target="frame">Suggestions and Ideas</a></li>
<li><a href="https://hackforums.net/forumdisplay.php?fid=162" target="frame">HF News</a></li>
<li><a href="https://hackforums.net/forumdisplay.php?fid=336" target="frame">Wiki Talk</a></li>
<li><a href="https://hackforums.net/forumdisplay.php?fid=140" target="frame">Ub3r Support</a></li>
</ul>
<form action="action">
<fieldset>
<legend>About You</legend>
<input type="text" name="box1" value="Username"> <input type="text" name="box2" value="UID"><br>
<legend>Are you learning a lot from this turorial?</legend>
<input type="radio" name="radio" value="radio1" checked>Yes<br>
<input type="radio" name="radio" value="radio2">No
</fieldset>
</form></p>
<div class="finish">
<p id="fin01">After a long hard battle we are finally nearing the end, it has been a long journey with you.</p>
<p id="fin02">I have enjoyed writing this tutorial, even though it took a crazy long time to write I dont think it will take as long to read.</p>
<p id="fin03">This is the last project, the next section will just be a breif rundown of all the HTML tags, just to make sure we get them all.</p>
</div>
</body>
</html>
Given the elements I couldn't make it look very good, maybe you can do better? Let's see your work too. Now for external CSS, the one thing we have yet to cover. External CSS uses a stylesheet linked in the header, everything we just stuck in the <style> tag in the last example, is exactly how it will go in the stylesheet. Stylesheets can have any name, but must always have the .cc extension. If we want to link them to our webpage so we can use them on our document we would just need to link them in the header. The rest of the document stays the same, just easier to manage without the CSS in it.
Code:
<link rel="stylesheet" type="text/css" href="styles.css">
And last but not least we finally get to the tags, I will have each tag listed in a code box and with it will be a usage example. I will try to cover as many as I can, but only as far as the character count will let me.
Code:
[b]<!--[/b]>
This is used for commenting in HTML, this will not show up in the browser display.
Code:
<!DOCTYPE>
This is for the DOCTYPE declaratioon, for HTML5 we just use <!DOCTYPE html>
Code:
<a>
This is used for links. <a href="link here">YOUR LINK</a>
Code:
<abbr>
This is used to abbreviate phrases and words.
Code:
<address>
You can use this when adding an address, and it will italicize the address.
Code:
<area>
The <area> tag is part of the image mapping tool in HTML
Code:
<article>
The article tag is used to disply independent, self-contained information.
Code:
<aside>
The <aside> tag defines some content aside from the content it is placed in.
Code:
<audio>
This is used to play audio through the browser.
Code:
<b>
<b> is used to make text bold
Code:
<base>
The <base> tag defines the base URL for the document and can shorten links being used for resources.
Code:
<bdi>
Bi-directional Isolate is used to keep text in formatting and to keep it from being messed up by the browser.
Code:
<bdo>
Bi-directional Overide forces the text to follow a specific format.
Code:
<blockquote>
This is used for quoting large blocks of text.
Code:
<body>
This is the main content block element, what you see on a webpage is all contained in the <body> element.
Code:
<br>
This is used for a line break
Code:
<button>
This is used to create a button, you can use CSS to make the button look nicer.
Code:
<canvas>
The <canvas> tag is used to draw graphics, on the fly, via scripting
Code:
<caption>
The <caption> tag defines a table caption and must be inserteed immediately after the <table> tag.
Code:
<cite>
<cite> is used to cite a source for information, these will not show up but can be read by viewing the page source.
Code:
<code>
Used to define computer code.
Code:
<col>
This is to determine columns in tables.
Code:
<colgroup>
This is used to cover groups of columns in tables.
Code:
<datalist>
This is used to provide an autofill option on <input>
Code:
<dd>
This is used to describe a list item in descriptive lists.
Code:
<del>
The <del> tag defines text that has been deleted from a document
Code:
<dfn>
This is used as a defining term.
Code:
<dialog>
The <dialog> tag defines a dialog box or window.
Code:
<div>
This is a block level element that is used to contain several elements within one or multiple parts of the document.
Code:
<dl>
This is used to define a descriptive list.
Code:
<dt>
<dt> is used to define a term in a descriptive list.
Code:
<embed>
This is used to create a container for external content.
Code:
<fieldset>
This is used to generate a named border around forms.
Code:
<figcaption>
This will add a caption to a <figure> element
Code:
<figure>
The <figure> tag adds self contained content to the webpage.
Code:
<footer>
This will display information in the bottom of the page, often used for contact info and copyright info.
Code:
<form>
With this you can create a webform to send to a server
Code:
<h1> - <h6>
These are the headers, each getting progressively smaller.
Code:
<head>
This is the top of the document, the part usualy contains the <title> and <meta> tags.
Code:
<hr>
This will make a horizontal rule accross the webpage
Code:
<html>
This defines the document.
Code:
<i>
This will italicize text.
Code:
<iframe>
This allows you to display a webpage within a webpage in a neat box.
Code:
<img>
This is used to embed images into the webpage.
Code:
<input>
<input> is used in conjuction with forms to take user input.
Code:
<ins>
The <ins> tag defines a text that has been inserted into a document.
Code:
<kbd>
The <kbd> tag is a phrase tag. It defines keyboard input.
Code:
<legend>
This defines a border within a fieldset in a form.
Code:
<li>
This is a list item, for either ordered or unordered lists.
Code:
<link>
This is used to link external resources to the document such as CSS stylesheets.
Code:
<map>
This is used for image mapping
Code:
<mark>
The <mark> tag highlights text.
Code:
<menu>
The <menu> tag defines a list for different objects.
Code:
<menuitem>
A selection in a menu.
Code:
<meta>
The <meta> provides metadata about the document, this can only go in the <head> tag.
Code:
<nav>
Can be used to define a navigation menu.
Code:
<noscript>
When you have javascript disabled this tells the browser what to display
Code:
<object>
This defines an embedded object such as a video or image.
Code:
<ol>
Ordered list
Code:
<optgroup>
This is used to group options in a dropdown list.
Code:
<option>
This defines an ption in a drop down list.
Code:
<p>
The defines a paragraph in the body.
Code:
<progress>
The <progress> tag represents the progress of a task.
Code:
<q>
This is used for quoting text in stricter documents.
Code:
<samp>
This provides a sample of computer code.
Code:
<script >
This is used to run javascript in the webpage.
Code:
<section>
The <section> tag defines sections in a document, such as chapters, headers, footers, or any other sections of the document.
Code:
<select>
This is used to create a dropdown list.
Code:
<source>
This is used to identify multple resources for media elements.
Code:
<span>
The <span> tag is used to group inline-elements in a document.
Code:
<style>
The <style> tag is used to define CSS for one or more elements.
Code:
<sub>
This provies subtext.
Code:
<sup>
This provides supertext.
Code:
<table>
This is used to create a table with multiple rows and columns.
Code:
<tbody>
This is used to group the body content of a table.
Code:
<td>
This is the tabledata tag that displays table data.
Code:
<textarea>
This will provide a text area for user inout.
Code:
<tfoot>
This is used to group the elements in the footer of the table.
Code:
<th>
This defines the table header for any column.
Code:
<thead>
<thead> is used to group the elements in the header of a table.
Code:
<title>
This defines the page title, alternatively when used as an attribute can provide a hover box with info about what you are viewing.
Code:
<tr>
This is used to define a row in a table.
Code:
<ul>
Unordered List.
Code:
<var>
This will define a variable.
In conclusion I hope you learned a lot from this, I spent a lot of time working on it and expect it to be put to good use.
I want to give a special thanks to a certain member for letting me use the Dawn Sub-Forum to post this, that user is Ninetails.
Also want to give thanks to Ariana for being a postholder while I was getting the thread ready to go.
I want to thank the developers of the website CoolText since that site is where I got the sectional banners for this guide.
Here are some links to further your study of HTML and refine your skills as a web developer.
0 Comments