HTML5 structure and starter CSS =============================== Goal ---- We are going to design a personal portfolio page with a main menu, content, and a footer. We fill in the content with an image along with some text. We are going to do all of this with HTML5 elements so `open up a HTML5 cheatsheet `_ and keep it handy. Main Content ------------ We will start by building the main page of our personal presentation, since this will give the main structure to the whole website design. Project Structure ----------------- Start a new directory for this project, alongside the *example1* directory you've been using so far. Call the new directory something like *portfolio*. Copy the files from *example1* into the *portfolio* directory to use them as a basis for your new project. After you have the files copied into *portfolio*, edit the HTML page there and remove all of the body content (everything inside the body tags, so you have an empty page with just the meta tags, title, and the CSS link tag.) We can use this as the basis for a new page. Creating the page ----------------- Let's start by wrapping our page in a div to give a centered design to our page. *"A div tag defines a section in a HTML file and is used to group elements to format them with CSS in order to lay out a web page."* Div is a general tag and can be used in many different situations just to wrap together a group of HTML elements and style them. For this reason we need to give it a name; otherwise, we can't style each one in a different way. There are two ways to give a name to a div tag: with an id or with a class. Think about an id as a personal and unique name like your surname/name and think about the class as personal characteristics, such as the color of your hair or your age. Id, the unique one, is used when you need to write a specific style valid only for this element. Classes are more common and used to give different HTML elements the same style and characteristics. We can now write our main page content: ::
Since we have just one main content, we can use the ID selector. In styles.css we make this div always centered in the middle. To call the class in CSS, we need to write ``.`` and the class name just after it. For the ID it is the same but with ``#`` instead of ``.``. :: #wrap-centered { width: 100%; margin: 0 auto; } Here we define the width of an element and then give it a ``margin: 0 auto`` which is a common rule to center the element. We use 100% instead of 100px because we want our page to be responsive or, in other words, we want the page to resize when the browser windows change dimensions. Now everything inside this div will be centered. At the beginning of the ``styles.css`` file, let's write something like this: :: * { /* don't use '0px' or any other unit, if you set the value to zero */ padding: 0; margin: 0; border: 0; } That is to set all the elements ``*`` with default ``padding``, ``margin`` and ``border`` to 0. This can be really useful to do because every browser sets a default size for some tags, and without setting all of them again to 0 it will be impossible to calculate the position of HTML elements and to position them on the page, since every browser will interpret that in a different way. Navigation Menu --------------- Time to write our navigation menu. Inside of the div we are going to write our first HTML5 element. :: Here we have 3 new elements. First, the nav tag. That tag means navigation and wraps up all the elements that are essential for the navigation in the website. ``