Table of Contents for
Practical Web Design

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Practical Web Design by Philippe Hong Published by Packt Publishing, 2018
  1. Practical Web Design
  2. Title Page
  3. Copyright and Credits
  4. Practical Web Design
  5. PacktPub.com
  6. Why subscribe?
  7. PacktPub.com
  8. Contributers
  9. About the author
  10. About the reviewers
  11. Packt is searching for authors like you
  12. Table of Contents
  13. Preface
  14. Who this book is for
  15. What this book covers
  16. To get the most out of this book
  17. Download the example code files
  18. Download the color images
  19. Conventions used
  20. Get in touch
  21. Reviews
  22. Evolution of Web Design
  23. The first ever website
  24. Table-based layouts
  25. Introduction of Flash
  26. CSS – the savior
  27. Web 2.0
  28. The rise of the mobile
  29. Responsive web design
  30. Flat design
  31. What's next?
  32. Summary
  33. Web Design and its Components
  34. Grids
  35. The cons
  36. Call to Action
  37. Making it obvious
  38. Using contrasting color
  39. Compelling copy
  40. Placement
  41. Breadcrumb
  42. The search bar
  43. The submit button
  44. Making it noticeable
  45. Placing the search bar correctly
  46. Icons
  47. Describing in a nutshell  
  48. Drawing attention of the users
  49. Directional
  50. Modal
  51. Typography
  52. Choosing a font that connects your brand
  53. Serif fonts
  54. Sans-serif
  55. Casual scripts
  56. Don't use too much typeface
  57. Colors
  58. What colors mean
  59. Usability
  60. Simplicity
  61. Navigability
  62. Accessibility
  63. Consistency
  64. So, how can we be consistent?
  65. Design
  66. Content
  67. Interactions
  68. Summary
  69. Website-Designing Workflow
  70. Our situation
  71. Goal identification
  72. What is the purpose of the website?
  73. Who is the website for?
  74. Is this useful for our audience?
  75. What do they expect to find or do there?
  76. Does the website need to follow a brand or have its own brand identity?
  77. Are there any competitors? If there are, how is the website different than others?
  78. Defining the scope
  79. Creating wireframes
  80. Designing
  81. Get inspiration
  82. Improve
  83. Invent
  84. Implementing, testing, and launching
  85. Summary
  86. Responsive Versus Adaptive Design
  87. Responsive design
  88. Adaptive design
  89. So which one is the best?
  90. The takeaway
  91. Summary
  92. Learning HTML5
  93. Our main tool
  94. What is HTML?
  95. HTML tags
  96. HTML attributes
  97. HTML structure
  98. Creating our first page
  99. HTML elements
  100. Titles and paragraphs
  101. Links and images
  102. Summary
  103. Learning CSS3
  104. The different ways to use CSS
  105. CSS formatting
  106. Parent and child elements
  107. Classes and IDs
  108. CSS box model  
  109. The boxes
  110. Block and inline
  111. CSS layout and dividers
  112. The basic layout
  113. Formatting and indenting your HTML
  114. Styling our class
  115. Summary
  116. Building Your Own Website
  117. Our design
  118. Installing HTML Boilerplate
  119. Editing index.html
  120. Creating our web page
  121. Images folder
  122. Installing our font
  123. Importing Google Font
  124. Adding normalize.css
  125. The header
  126. Creating a menu
  127. Inserting links
  128. Adding a logo
  129. Right-hand side menu
  130. Adding a Facebook like button
  131. Styling our header
  132. Adding the hero section
  133. CSS flexbox
  134. Positioning in CSS
  135. Position static
  136. Position relative
  137. Position absolute
  138. Position fixed
  139. Position sticky
  140. Blog section
  141. Creating the ABOUT US section
  142. Adding the Partner section
  143. Adding the footer section
  144. Summary
  145. Making Our Website Responsive
  146. What are media queries? 
  147. Opening the inspector
  148. Desktop first
  149. Designing the menu
  150. What is jQuery? 
  151. jQuery syntax
  152. Making the hero section responsive
  153. Making the Blog section responsive
  154. Making the ABOUT US section responsive
  155. Making the footer section responsive
  156. Summary
  157. Adding Interaction and Dynamic Content
  158. CSS pseudo-classes
  159. Sticky navigation 
  160. JS Plugin: Waypoints
  161. CSS animation
  162. Adding a dynamic Instagram feed
  163. Installing Instafeed.js
  164. Getting images from your user account
  165. Finding our userID and TokenAccess
  166. Getting our access token
  167. Displaying the feed
  168. Summary
  169. Optimizing and Launching Our Website
  170. Creating a favicon
  171. Site performance optimization
  172. Optimizing images
  173. Optimizing our code
  174. Basic SEO improvement
  175. What is search engine optimization?
  176. Meta description
  177. Valid HTML
  178. Keywords
  179. Links
  180. Launching our website
  181. Buying a domain name
  182. Google analytics
  183. Google Search Console
  184. Summary
  185. What is Bootstrap?
  186. What is Bootstrap?
  187. Components
  188. Bootstrap Grid system
  189. Media queries
  190. Summary
  191. Building a Website with Bootstrap
  192. Installing Bootstrap 
  193. Setting up our project 
  194. Bootstrap navbar 
  195. Coding the Bootstrap navigation
  196. Styling our navigation bar 
  197. Styling the hero section
  198. Styling the Blog section
  199. Styling the about section 
  200. Styling the partner section
  201. Styling the footer
  202. Summary
  203. Introduction to Client-Side Rendering
  204. What is server-side rendering?
  205. What is client-side rendering?
  206. Pros and cons of server and client-side rendering
  207. Server-side rendering
  208. Client-side rendering
  209. Introducing to VueJS
  210. Setting up VueJS
  211. Creating a weather application in VueJS
  212. Vue Material
  213. Components
  214. OpenWeather API
  215. The API call
  216. Summary
  217. Tools to Help Your Workflow
  218. HTML Boilerplate
  219. Lorem Ipsum
  220. CSS preprocessor – LESS
  221. CSS preprocessor – SCSS
  222. ColorZilla
  223. Foundation
  224. Fontastic
  225. webflow
  226. Modernizr
  227. CSS3 Generator
  228. git
  229. CodeKit
  230. Animate.css
  231. TinyPNG
  232. Unsplash
  233. Summary
  234. Other Books You May Enjoy
  235. Leave a review - let other readers know what you think

Styling our header

At the moment, our header is looking very boring. But, no worries, we'll add some magic with CSS and make it prettier.

We saw earlier that CSS can be written in three different ways:

  • Inside an HTML Tag with a style attribute 
  • Inside our <head> section in a HTML document with the tag <style>
  • CSS code can also be put into an external file

For our own project, we're going to use the third way, as commonly used in the web in general, because the CSS can be changed without changing the HTML file.

Let's create our CSS file that will be used for our general styling. In Atom, click File | New File, and save the file with File | Save As. Choose the folder css and name this file styles.css. We have to link this file as we did with the font.css file we created earlier:

<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
<link rel="stylesheet" href="fonts/fonts.css"> <!-- Font face CSS link -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/styles.css">

Now that we have our styles.css, we can get started. But I usually like to view both HTML and CSS at the same time. It's easy to do so; select your styles.css, then go to View | Panes | Split Right. You now have the file open on two different panes. You can close the one on the left:

The view split in two in Atom.

First, we need to target the header tag. The header tag has no class, but we can target an HTML tag with just this tag. In CSS it will be:

header {
}

This will basically target every <header> tag in the HTML, so you need to be careful about it:

If we take a look closely at our design, we can notice that the header takes the full width of the web page, has a height of 70px, and has a gradient grey to a transparent background that lets the image appear behind it.

To do so we have the CSS property width:

header {
width: 100%;
height: 70px;
}

We can now add the background gradient. For that, we have the CSS property background-image: linear-gradient:

background-image: linear-gradient(0deg, rgba(0,0,0,0.00) 0%, rgba(0,0,0,0.50) 50%);

To create a gradient with CSS, I often use a generator (http://www.colorzilla.com/gradient-editor/) that creates the final code for me.

I also sometimes use the CSS tool provided by Sketch or Photoshop to copy the CSS property straight from the design. 

For this exercise, you can just copy the code I provided:

header {
width: 100%;
background-image: linear-gradient(0deg, rgba(0,0,0,0.00) 0%, rgba(0,0,0,0.50) 50%);
}

Save both CSS and HTML files and open index.html on your browser:

We now have our container, but we still need to stylize our menu. Let's first target our list by its class, main-nav. If you remember, to call a class, we need to add a dot before the name of the class, like this:

header .main-nav {

}

Now we want to specifically target every <li> inside the <ul>. To do so, we simply have to add li after, as we saw in the chapter earlier:

header .main-nav li {

}

Let's first remove the list styling, which is a circle by default. To do that, we need to use the CSS property list-style-type:

header .main-nav li {
list-style-type: none;
}

Let's put none, so it will remove all styling in the li tag.

We also have to display the list horizontally instead of vertically. To make this happen, we need to use the CSS property display: inline-block.

The CSS property display: inline-block will display the list as inline but with the ability to set width and height as a block element:

header .main-nav li {
list-style-type: none;
display: inline-block;
}

Let's save our work and check to see what we have so far:

Our goal now is to put the menu right next to the logo. For that, we'll need to make the logo float. As we saw earlier in the CSS chapter, we'll use the CSS property float: left; on the logo:

header .logo {
float: left;
}

We now need to display the menu correctly. We'll first add a height to our main-nav :

header .main-nav {
height: 70px;
}

We also need to make the menu float so the right-hand menu can come on top:

header .main-nav {
height: 70px;
}

Since all <ul> tags have some padding and margin by default, we need to overwrite that:

Header .main-nav {
height: 70px;
float: left;
margin: 0;
padding: 0;
}

The problem is that we have the menu side by side with the logo, so we need to add some padding to the menu:

header .main-nav {
height: 70px;
float: left;
margin: 0;
padding: 0;
padding-left: 0;
}

But now we have two properties that are overlapping since padding includes all paddings such as padding-left. This will still work but it's bad CSS. To write it properly, we can combine and modify the paddings with just one CSS property:

This image explains how you can change different paddings with just one property.

For our exercise, we will do the following:

header .main-nav {
height: 70px;
float: left;
margin: 0;
padding: 0px 15px;
}

Our next goal is to make our menu vertically aligned with the logo. To do so, we can use a little CSS hack by using line-height, which is used normally to change the space between lines on a paragraph. By setting the line-height to the height of the menu, we'll make the menu vertically aligned:

header .main-nav {
height: 70px;
float: left;
margin: 0;
padding: 0px 15px;
line-height: 70px;
}

Now let's customize the font to the one we installed earlier. Let me show you the final CSS so that I can explain line by line what, exactly, it means:

header .main-nav li a {
color: white;
text-decoration: none;
font-family: 'built_titling', Helvetica, sans-serif;
font-weight: 200;
font-size: 20px;
letter-spacing: 4px;
padding: 0px 15px;
}

First we need to target the <a> tag in our .main-nav class. Inside our bracket, we'll have the following:

  1. color: white; will specify the color of the text. You can set this color with a HEX code or with the 140 native color CSS support (https://www.w3schools.com/cssref/css_colors.asp).
  2. text-decoration: none; will suppress all decoration on the text. Here we want to suppress the underline on every link.
  3. font-family: 'built_titling', Helvetica, sans-serif; is to specify the font we want to display. The following font name will serve if the first one couldn't load.
  4. font-weight: 200; is the level of bold of the font.
  5. font-size: 20px; will be the size of the font in pixels.
  6. letter-spacing: will indicate the spacing between each character.
  7. padding: it's inside-padding as we learned earlier.

We're almost done. Let's save and have a look:

We have only the right-hand part to finish, let's get this done!

For this part, we'll need to make it float on the right. Let's first target this class:

Header .right-nav {

}

This right nav will follow almost the same properties as the left nav; we'll only change the float to right:

header .right-nav {
height: 70px;
float: right;
margin: 0;
padding: 0px 15px;
line-height: 70px;
}

As you will see, we'll use a lot of copy/paste for coding as a lot of elements will use the same properties.

But what if we have a lot of selectors that use the same CSS properties? Do we have to copy/paste all of them? A good practice in coding is always to simplify our code so that it takes less time to load.

In CSS, we can call on multiple selectors and put the same CC properties. To do so, we need to separate them with a comma ,. For our left-nav and right-nav for example, we can do the following:

header .main-nav, header .right-nav{
height: 70px;
float: left;
margin: 0;
padding: 0px 15px;
line-height: 70px;
}

header .right-nav {
float: right;
}

This will have the same effect as the code we wrote before. And because we call .right-nav and put the property float: right; after, it overwrites the previous property, which was float: left;. This is a good practice to have when coding in CSS.

Let's make the rest of the code with this good practice in mind:

header .main-nav li, header .right-nav li {
list-style-type: none;
display: inline-block;
}

header .main-nav li a, header .right-nav li a {
color: white;
text-decoration: none;
font-family: 'built_titling', Helvetica, sans-serif;
font-weight: 200;
font-size: 20px;
letter-spacing: 4px;
padding: 0px 15px;
}

We now have our header. Let's save it and have a final look:

Fantastic! Lastly, to make our code clean and easy to read, I'll advise putting some comments at the beginning and at the end of each section of your code.

This will be the final CSS code for our HEADER section:

/* HEADER */

header {
width: 100%;
height: 70px;
background-image: linear-gradient(0deg, rgba(0,0,0,0.00) 0%, rgba(0,0,0,0.50) 50%);
position: absolute;
}

header .logo {
float: left;
}

header .main-nav, header .right-nav{
height: 70px;
float: left;
margin: 0;
padding: 0px 15px;
line-height: 70px;
}

header .right-nav {
float: right;
}

header .main-nav li, header .right-nav li {
list-style-type: none;
display: inline-block;
}

header .main-nav li a, header .right-nav li a {
color: white;
text-decoration: none;
font-family: 'built_titling', Helvetica, sans-serif;
font-weight: 200;
font-size: 20px;
letter-spacing: 4px;
padding: 0px 15px;
}

/* END OF HEADER */