Book Image

HTML5 and CSS3: Building Responsive Websites

By : Ben Frain, Thoriq Firdaus, Benjamin LaGrone
Book Image

HTML5 and CSS3: Building Responsive Websites

By: Ben Frain, Thoriq Firdaus, Benjamin LaGrone

Overview of this book

Responsive web design is an explosive area of growth in modern web development due to the huge volume of different device sizes and resolutions that are now commercially available. The Internet is going mobile. Desktop-only websites just aren’t good enough anymore. With mobile internet usage still rising and tablets changing internet consumption habits, you need to know how to build websites that will just “work,” regardless of the devices used to access them. This Learning Path course explains all the key approaches necessary to create and maintain a modern responsive design using HTML5 and CSS3. Our first module is a step-by-step introduction to ease you into the responsive world, where you will learn to build engaging websites. With coverage of Responsive Grid System, Bootstrap, and Foundation, you will discover three of the most robust frameworks in responsive web design. Next, you’ll learn to create a cool blog page, a beautiful portfolio site, and a crisp professional business site and make them all totally responsive. Packed with examples and a thorough explanation of modern techniques and syntax, the second module provides a comprehensive resource for all things “responsive.” You’ll explore the most up-to-date techniques and tools needed to build great responsive designs, ensuring that your projects won’t just be built “right” for today, but in the future too. The last and the final module is your guide to obtaining full access to next generation devices and browser technology. Create responsive applications that make snappy connections for mobile browsers and give your website the latest design and development advantages to reach mobile devices. At the end of this course, you will learn to get and use all the tools you need to build and test your responsive web project performance and take your website to the next level. This Learning Path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products: ?Responsive Web Design by Example: Beginner’s Guide - Second Edition by Thoriq Firdaus ?Responsive Web Design with HTML5 and CSS3 - Second Edition by Ben Frain ?HTML5 and CSS3 Responsive Web Design Cookbook by Benjamin LaGrone
Table of Contents (6 chapters)

In the previous chapter, we installed a number of software that will facilitate our projects. Here, we will start off our very first project. In this project, we are going to build a responsive blog.

Having a blog is essential for a company. Even several Fortune 500 companies such as FedEx (http://outofoffice.van.fedex.com/), Microsoft (https://blogs.windows.com/) and General Motors (http://fastlane.gm.com/) have official corporate blogs. A blog is a great channel for the company to publish official news as well as to connect with their customers and the masses. Making the blog responsive is the way to go to make the blog more accessible to the readers who may access the site through a mobile device, such as a phone or tablet.

As the blog that we are going to build in this first project will not be that complex, this chapter would be an ideal chapter for those who have just come across responsive web design.

So let's get started.

To sum up, in this chapter, we will cover the following topics:

As we mentioned in Chapter 1, Responsive Web Design, Responsive.gs is a lightweight CSS framework. It comes only with the bare minimum requirements for building responsive websites. In this section, we are going to see what is included in Responsive.gs.

Responsive.gs is shipped with a series of reusable classes to form the responsive grid that makes it easier and faster for web designers to build web page layout. These classes contain preset style rules that have been carefully calibrated and tested. So we can simply drop in these classes within the HTML element to construct the responsive grid. The following is a list of the classes in Responsive.gs:

Class name

Usage

container

We use this class to set the web page container and align it to the center of the browser window. This class, however, does not give the element width. Responsive.gs gives us the flexibility to set the width as per our requirement.

row, group

We use these two classes to wrap a group of columns. Both of these classes are set with so called self-clearing floats that fix some layout issues caused by the element with the CSS float property.

Check the following references for further information about the CSS float property and the issue it may cause to a web page layout:

col

We use this class to define the column of the web page. This class is set with the CSS float property. So any elements set with this class have to be contained within an element with the row or group class to avoid the issues caused by the CSS float property.

gutters

We use this class to add spaces between the columns set with the preceding col class.

span_{x}

This class defines the column width. So we use this class in tandem with the col class.

Responsive.gs comes in three variants of grid, which gives us flexibility while organizing the web page layout. Responsive.gs is available in the 12-, 16-, and 24-columns format. These variants are set in three separate style sheets. If you download Responsive.gs package and then unpack it, you will find three style sheets named responsive.gs.12col.css, responsive.gs.16col.css, and responsive.gs.24col.css.

The only difference between these style sheets is the number of span_ classes defined within it. It is apparent that the 24-column format style sheet has the most number of span_{x} classes; the class stretches from span_1 to span_24. If you need greater flexibility on dividing your page, then using the 24-column format of Responsive.gs is the way to go. Though each column may be too narrow.

clr

This class is provided to address the floating issue. We use this class in the occasion where using the row class would not be semantically appropriate.

Now, let's see how we apply them in an example to discover how they really work. Many times, you will see that a web page is divided into a multiple columns structure. Take that into account as our example here; we can do the following to construct a web page with two columns of content:

As you can see from the preceding code snippet, we first added container that wraps all the contents. Then, it is followed by div with a row class to wrap the columns. At the same time, we also added the gutters class so that there will be blank space between the two columns. In this example, we used the 12-column format. Therefore, to split the page into two equal columns, we added the span_6 class for each column. This is to say that the number of span_{x} classes should be equal to 12, 16, or 24 in accordance with the variant we are using in order for the columns to cover the entire container. So, if we used the 16-columns format, for example, we may add span_8 instead.

In the browser, we will see the following output:

The classes

Paul Boag, in his article Semantic code: What? Why? How? (http://boagworld.com/dev/semantic-code-what-why-how/) wrote:

HTML was originally intended as a means of describing the content of a document, not as a means to make it appear visually pleasing.

Unlike traditional content outlets such as newspapers or magazines, which are apparently intended for humans, the Web is read both by humans and machines such as search engines and screen readers that help visually impaired people navigate websites. So making our website structure semantic is really encouraged. Semantic markup allows these machines to understand the content better and also makes the content more accessible in different formats.

On that account, HTML5 introduces a bunch of new elements in its mission to make the web more semantic. The following is a list of elements that we are going to use for the blog:

These new HTML elements make our document markup more descriptive and meaningful. Unfortunately, Internet Explorer 6, 7, and 8 will not recognize them. Thus, the selectors and style rules that address these elements are inapplicable; it is as if these new elements are not included in the Internet Explorer dictionary.

This is where a polyfill named HTML5Shiv comes into play. We will include HTML5Shiv (https://github.com/aFarkas/html5shiv) to make Internet Explorer 8 and its lower versions acknowledge these new elements. Read the following post (http://paulirish.com/2011/the-history-of-the-html5-shiv/) by Paul Irish for the history behind HTML5Shiv; how it was invented and developed.

Furthermore, older Internet Explorer versions won't be able to render the content in the HTML5 placeholder attribute. Fortunately, we can patch mimic the placeholder attribute functionality in the old Internet Explorer with a polyfill (https://github.com/UmbraEngineering/Placeholder). We will use it later on the blog as well.

Responsive.gs is also shipped with two polyfills to enable certain features that are not supported in Internet Explorer 6, 7, and 8. From now on, let's refer to these browser versions as "old Internet Explorer", shall we?

HTML5 search input types

Besides the new elements, we will also add one particular new type of input on the blog, search. As the

These new HTML elements make our document markup more descriptive and meaningful. Unfortunately, Internet Explorer 6, 7, and 8 will not recognize them. Thus, the selectors and style rules that address these elements are inapplicable; it is as if these new elements are not included in the Internet Explorer dictionary.

This is where a polyfill named HTML5Shiv comes into play. We will include HTML5Shiv (https://github.com/aFarkas/html5shiv) to make Internet Explorer 8 and its lower versions acknowledge these new elements. Read the following post (http://paulirish.com/2011/the-history-of-the-html5-shiv/) by Paul Irish for the history behind HTML5Shiv; how it was invented and developed.

Furthermore, older Internet Explorer versions won't be able to render the content in the HTML5 placeholder attribute. Fortunately, we can patch mimic the placeholder attribute functionality in the old Internet Explorer with a polyfill (https://github.com/UmbraEngineering/Placeholder). We will use it later on the blog as well.

Responsive.gs is also shipped with two polyfills to enable certain features that are not supported in Internet Explorer 6, 7, and 8. From now on, let's refer to these browser versions as "old Internet Explorer", shall we?

HTML5 placeholder attribute

HTML5 introduced a new attribute named placeholder. The specs described this attribute as a

These new HTML elements make our document markup more descriptive and meaningful. Unfortunately, Internet Explorer 6, 7, and 8 will not recognize them. Thus, the selectors and style rules that address these elements are inapplicable; it is as if these new elements are not included in the Internet Explorer dictionary.

This is where a polyfill named HTML5Shiv comes into play. We will include HTML5Shiv (https://github.com/aFarkas/html5shiv) to make Internet Explorer 8 and its lower versions acknowledge these new elements. Read the following post (http://paulirish.com/2011/the-history-of-the-html5-shiv/) by Paul Irish for the history behind HTML5Shiv; how it was invented and developed.

Furthermore, older Internet Explorer versions won't be able to render the content in the HTML5 placeholder attribute. Fortunately, we can patch mimic the placeholder attribute functionality in the old Internet Explorer with a polyfill (https://github.com/UmbraEngineering/Placeholder). We will use it later on the blog as well.

Responsive.gs is also shipped with two polyfills to enable certain features that are not supported in Internet Explorer 6, 7, and 8. From now on, let's refer to these browser versions as "old Internet Explorer", shall we?

HTML5 in Internet Explorer

These new HTML elements make our document markup more descriptive and meaningful. Unfortunately, Internet Explorer 6, 7, and 8 will not recognize them. Thus, the selectors and

style rules that address these elements are inapplicable; it is as if these new elements are not included in the Internet Explorer dictionary.

This is where a polyfill named HTML5Shiv comes into play. We will include HTML5Shiv (https://github.com/aFarkas/html5shiv) to make Internet Explorer 8 and its lower versions acknowledge these new elements. Read the following post (http://paulirish.com/2011/the-history-of-the-html5-shiv/) by Paul Irish for the history behind HTML5Shiv; how it was invented and developed.

Furthermore, older Internet Explorer versions won't be able to render the content in the HTML5 placeholder attribute. Fortunately, we can patch mimic the placeholder attribute functionality in the old Internet Explorer with a polyfill (https://github.com/UmbraEngineering/Placeholder). We will use it later on the blog as well.

Responsive.gs is also shipped with two polyfills to enable certain features that are not supported in Internet Explorer 6, 7, and 8. From now on, let's refer to these browser versions as "old Internet Explorer", shall we?

A look into polyfills in the Responsive.gs package

Responsive.gs is also

shipped with two polyfills to enable certain features that are not supported in Internet Explorer 6, 7, and 8. From now on, let's refer to these browser versions as "old Internet Explorer", shall we?

Box sizing polyfills

The first polyfill is available
CSS3 media queries polyfill

The second polyfill script that comes along with Responsive.gs is respond.js (

Building a website is much the same as building a house; we need to examine the specification of every corner before we stack up all the bricks. So, before we jump in to building the blog, we will examine the blog's wireframe to see how the blog is laid out and also see the things that will be displayed on the blog.

Let's take a look at the following wireframe. This wireframe shows the blog layout when it is viewed on the desktop screen:

Examining the blog's wireframe

As you can see in the preceding screenshot, the blog will be plain and simple. In the header, the blog will have a logo and a search form. Down below the header, consecutively, we will place the menu navigation, the blog post, the pagination for navigating to the next or previous list of posts, and the footer.

The blog post, as in general, will comprise the title, the publishing date, the post's featured image, and the post excerpt. This wireframe is an abstraction of the blog's layout. We use it as our visual reference of how the blog layout will be arranged. So, in spite of the fact that we have shown only one post within the preceding wireframe, we will actually add a few more post items on the actual blog later on.

The following is the blog layout when the viewport width is squeezed:

Examining the blog's wireframe

When the viewport width gets narrow, the blog layout adapts. It is worth noticing that when we shift the layout, we should not alter the content flow as well as the UI hierarchy. Assuring the layout consistency between the desktop and the mobile version will help the users get familiar with a website quickly, regardless of where they are viewing the website. As shown in the preceding wireframe, we still have the UI set in the same order, albeit, they are now stacked vertically in order to fit in the limited area.

One thing that is worth mentioning from this wireframe is that the navigation turns into an HTML dropdown selection. We will discuss how to do so during the course of building the blog.

Now, as we have prepared the tools and checked out the blog layout, we are ready to start off the project. We will start off by creating and organizing the project directories and assets.

Perform the following steps to set up the project's working directory:

  1. Go to the htdocs folder. As a reminder, this folder is the folder in the local server located at:
    • C:\xampp\htdocs in Windows
    • /Applications/XAMPP/htdocs in OSX
    • /opt/lampp/htdocs in Ubuntu
  2. Create a new folder named blog. From now on, we will refer to this folder as the project directory.
  3. Create a new folder named css to store style sheets.
  4. Create a new folder named image to store images.
  5. Create a new folder named scripts to store JavaScript files.
  6. Create a new file named index.html; this HTML file will be the main page of the blog. Download the Responsive.gs package from http://responsive.gs/. The package comes in the .zip format. Extract the package to unleash the files within the package. There, you will find a number of files, including style sheets and JavaScript files, as you can see from the following screenshot:
    Time for action – creating and organizing project directories and assets

    The files that ship in Responsive.gs

  7. Move responsive.gs.12col.css to the css folder of the project directory; it is the only style sheet of Responsive.gs that we need.
  8. Move boxsizing.htc to the scripts folder of the project directory.
  9. The respond.js file that ships in the Responsive.gs package is out-of-date. Let's download the latest version of Respond.js from the GitHub repository (https://github.com/scottjehl/Respond/blob/master/src/respond.js) instead, and put it in the scripts folder of the project directory.
  10. Download HTML5Shiv from https://github.com/aFarkas/html5shiv. Put the JavaScript file html5shiv.js within the scripts folder.
  11. We will also use the placeholder polyfill that is developed by James Brumond (https://github.com/UmbraEngineering/Placeholder). James Brumond developed four different JavaScript files for cater to different scenarios.
  12. The script that we are going to use here is ie-behavior.js, because this script specifically addresses Internet Explorer. Download the script (https://raw.githubusercontent.com/UmbraEngineering/Placeholder/master/src/ie-behavior.js) and rename it as placeholder.js to make it more apparent that this script is a placeholder polyfill. Put it in the scripts folder of the project directory.
  13. The blog will need a few images to use as the post's featured image. In this module, we will use the images shown in the following screenshot, consecutively taken by Levecque Charles (https://twitter.com/Charleslevecque) and Jennifer Langley (https://jennifer-langley.squarespace.com/photography/):
    Time for action – creating and organizing project directories and assets
  14. We will add a favicon to the blog. A favicon is a tiny icon that appears on the browser tab beside the title, which will be helpful for readers to quickly identify the blog. The following is a screenshot that shows a number of pinned tabs in Chrome. I bet that you are still able to recognize the websites within these tabs just by seeing the favicon:
    Time for action – creating and organizing project directories and assets

    Google Chrome pinned tabs

  15. Further, we will also add the iOS icon. In Apple devices such as iPhone and iPad, we can pin websites on the home screen to make it quick to access the website. This is where the Apple icon turns out to be useful. iOS (the iPhone/iPad operating system) will show the icon we provide, as shown in the following screenshot, as if it was a native application:
    Time for action – creating and organizing project directories and assets

    Website added to the iOS home screen

  16. These icons are provided in the source files that come along with this module. Copy these icons and paste them in the image folder that we have just created in step 5, as shown in the following screenshot:
    Time for action – creating and organizing project directories and assets
What just happened?

We have just created a directory Have a go hero – making the directory structure more organized

Many people have their own preferences for how to organize their project's directory structure. The one shown Pop quiz – using polyfill

Earlier In this module, we discussed polyfill and also mentioned a few polyfill scripts that we are going to implement in the blog.

Q1. When do you

Perform the following steps to build the blog:

  1. Open the index.html file that we have created in step 6 of the previous section Time for action – creating and organizing project directories and assets. Let's start by adding the most basic HTML5 structure as follows:
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Blog</title>
    </head>
    <body>
      
    </body>
    </html>

    Here, set DOCTYPE, which has been brought to the bare minimum form. The DOCTYPE format in HTML5 is now shorter and cleaner than the DOCTYPE format of its HTML4 counterpart. Then, we set the language of our page, which in this case is set to en (English). You may change it to your local language; find the code for your local language at http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes.

    We have also set the character encoding to UTF-8 to enable the browser to render the Unicode characters, such as U+20AC, to the readable format .

  2. Below the charset meta tag in the head tag, add the following meta:
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    Internet Explorer can sometimes behave oddly, where it suddenly switches to compatibility mode and renders the page as viewed in Internet Explorer 8 and 7. This meta tag addition will prevent that from happening. It will force Internet Explorer to render the page with the highest support of the latest standards available in Internet Explorer.

  3. Below the http-equiv meta tag, add the following meta viewport tag:
    <meta name="viewport" content="width=device-width, initial-scale=1">

    As we mentioned in Chapter 1, Responsive Web Design, the preceding viewport meta tag specification defines the web page viewport width to follow the device viewport size. It also defines the web page scale at 1:1 upon opening the web page the first time.

  4. Link the Apple icon with the link tag, as follows:
    <link rel="apple-touch-icon" href="image/icon.png">

    As per Apple's official instructions, you would normally need to include multiple sources of icons to cater to iPhone, iPad, and the devices with a Retina screen. That isn't actually necessary for our blog. The trick is that we deliver the largest size required, which is 512 px square, through a single source, as shown in the previous screenshot.

  5. Add a description meta tag below the title, as follows:
    <meta name="description" content="A simple blog built using Responsive.gs">
  6. This description of the blog will show up in Search Engine Result Page (SERP). In this step, we will construct the blog header. First, let's add the HTML5 <header> element along with the classes for styling, to wrap the header content. Add the following within the body tag:
    <header class="blog-header row">
    
    </header>
  7. Within the <header> element that we added in step 9, add a new <div> element with the container and gutters class, as follows:
    <header class="blog-header row">
    <div class="container gutters">
    
    </div>
    </header>

    Referring to the table shown earlier in the chapter, the container class will align the blog header content to the center of the browser window, while the gutters class will add spaces between the columns, which we will add in the next steps.

  8. Create a new column to contain the blog logo/name with a <div> element along with the Responsive.gs col and span_9 class to set the <div> element as column and specify the width. Don't forget to add the class to add custom styles:
    <header class="blog-header row">
    <div class="container gutters">
           <div class="blog-name col span_9">
    <a href="/">Blog</a>
    </div>
    </div>
    </header>
  9. Referring to the blog wireframe, we will have a search form next to the blog logo/name. On that account, create another new column with a <div> element together with the col and span_3 class of Responsive.gs, and the input search type. Add the <div> element below the logo markup as follows:
    <header class="blog-header row">
    <div class="container gutters">
           <div class="blog-name col span_9">
       <a href="/">Blog</a>
    </div>
    <div class="blog-search col span_3">
               <div class="search-form">
                 <form action="">
     <input class="input_full" type="search"      placeholder="Search here...">
      </form>
                </div>
       </div>
    </div>
    </header>

    As we mentioned earlier in this chapter, we used an input search type to serve a better user experience. This input will show the mobile screen keyboard with a special key that allows users to hit the Search button and immediately run the search. We also added placeholder text with the HTML5 placeholder attribute to show the users that they can perform a search in the blog through the input field.

  10. After constructing the header blog, we will construct the blog navigation. Here we will use the HTML5 nav element to define a new section as navigation. Create a nav element along with the supporting classes to style. Add the nav element below the header construction as follows:
    ...     
    </div>
    </header> 
    <nav class="blog-menu row">
      
    </nav>
  11. Inside the nav element, create a div element with the container class to align the navigation content to the center of the browser window:
    <nav class="blog-menu">
    <div class="container">
    </div>
    </nav>
  12. In accordance to the wireframe, the blog will have five items on the link menu. We will lay out this link with the ul element. Add the links within the container, as shown in the following code snippet:
    <nav class="blog-menu row">
      <div class="container">
           <ul class="link-menu">
             <li><a href="/">Home</a></li>
             <li><a href="#">Archive</a></li>
             <li><a href="#">Books</a></li>
             <li><a href="#">About</a></li>
             <li><a href="#">Contact</a></li>
          </ul>
    </div>
    </nav>
  13. Having done with constructing the navigation, we will construct the content section of the blog. Following the wireframe, the content will consist a list of posts. First, let's add the HTML5 <main> element to wrap the content below the navigation as follows:
    ...
    </ul>  
    </nav>
    <main class="blog-content row">
      
    </main>

    We use the <main> element as we consider the posts as the prime section of our blog.

  14. Similar to the other blog sections—the header and the navigation—we add a container <div> to align the blog posts to the center. Add this <div> element within the <main> element:
    <main class="blog-content row">
       <div class="container">
    
    </div>
    </main>
  15. We will now create the blog post markup. Think of the blog post as an article. Thus, here we will use the <article> element. Add the <article> element within the container <div> that we will add in step 17 as follows:
    <main class="blog-content row">
    <div class="container">
      <article class="post row">
    
      </article>
    </div>
    </main>
  16. As mentioned, the <header> element is not limited to define a header. The blog can be used to define the head of a section. In this case, apart from the blog header, we will use the <header> element to define the articles head section that contains the article title and publishing date.
  17. Add the <header> element within the article element:
    <article class="post row">
    <header class="post-header">
    <h1 class="post-title">
    <a href="#">Useful Talks &amp; Videos for Mastering CSS</a>
      </h1>
          <div class="post-meta">
         <ul>
            <li class="post-author">By John Doe</li>
            <li class="post-date">on January, 10 2014</li>
         </ul>
         </div>
    </header>
    </article>
  18. A picture is worth a thousand words. So, it's the norm to use an image to support the post. Here, we will display the image below the post header. We will group the featured image together with the post excerpt as the post summary, as shown in the following code:
    ...
     </header>
     <div class="post-summary">
    <figure class="post-thumbnail">
    <img src="image/village.jpg" height="1508" width="2800" alt="">
    </figure>
    <p class="post-excerpt">Lorem ipsum dolor sit amet,   consectetur adipisicing elit. Aspernatur, sequi, voluptatibus, consequuntur vero iste autem aliquid qui et rerum vel ducimus ex enim quas!...<a href="#">Read More...</a></p>
      </div>
    </article>

    Add a few more posts subsequently. Optionally, you may exclude the post featured image in the other posts.

  19. After adding a pile of posts, we will now add the post pagination. The pagination is a form of common page navigation that allows us to jump to the next or previous list of posts. Normally, the pagination is located at the bottom of the page after the last post item.

    The pagination of a blog consists of two links to navigate to the next and previous page, and a small section to place the page numbers to show what page the user is currently in.

  20. So, add the following code after the last post:
    ...
    </article>
    <div class="blog-pagination">
    <ul>
      <li class="prev"><a href="#">Prev. Posts</a></li>
      <li class="pageof">Page 2 of 5</li>
      <li class="next"><a href="#">Next Posts</a></li>
    </ul>
    </div>
  21. Finally, we will construct the blog footer. We can define the blog footer using the HTML5 <footer> element. The footer structure is identical to the one for the header. The footer will have two columns; each respectively contains the blog footer links (or, as we call it, secondary navigation) and copyright statement. These columns are wrapped with a <div> container. Add the following footer in the main section, as follows:
          …
    </main> 
    <footer class="blog-footer row">
       <div class="container gutters">
         <div class="col span_6">
    <nav id="secondary-navigation"  class="social-   media">
              <ul>
               <li class="facebook">
    <a href="#">Facebook</a>
      </li>
               <li class="twitter">
    <a href="#">Twitter</a></li>
               <li class="google">
    <a href="#">Google+</a>
       </li>
             </ul>
           </nav>
         </div>
       <div class="col span_6">
    <p class="copyright">&copy; 2014. Responsive  Blog.</p>
       </div>
       </div>
    </footer>
What just happened?

We have just finished constructing the blog's HTML structure—the header, the navigation, the Have a go hero – creating more blog pages

In this module, we only build the blog's home page. However, you are free to extend the blog by creating more pages, such as adding an about page, a single post content page, and a page with a Pop quiz – HTML5 elements

Let's end this chapter with simple questions regarding HTML5:

Q1. What is the <header> element used for?

It is used to represent the website header.
It is used to represent a group of introductory and navigational aids.

Q2. What is the <footer> element used for?

It is used to represent the website footer.
It is used to represent the end or the lowest part of a section.

Q3. Is it allowed to use the <header> and <footer> elements multiple times within a single page?

Yes, as long as it's semantically logical.
No, it's considered redundant.