Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Resizing the site title and the description

From: WordPress: Building Responsive Themes

Video: Resizing the site title and the description

When creating a responsive theme, or any theme for that matter, I like to start from the top; that means starting with the header itself. The challenge with a header is that it usually has to contain multiple different components: the site title and tagline, usually a background image of some sort, and also the menu, like you see here. Your job is to make sure each element stacks up nicely, both to match your design and also to be the easy to understand and functional. Out of the box, Anaximander will have the site title and tagline, and then the menu should appear directly under it.

Resizing the site title and the description

When creating a responsive theme, or any theme for that matter, I like to start from the top; that means starting with the header itself. The challenge with a header is that it usually has to contain multiple different components: the site title and tagline, usually a background image of some sort, and also the menu, like you see here. Your job is to make sure each element stacks up nicely, both to match your design and also to be the easy to understand and functional. Out of the box, Anaximander will have the site title and tagline, and then the menu should appear directly under it.

In some cases, in some browsers, the menu will appear shifted to the right here, and that's fine, because we're going to be working on realigning the header right now to make it match the design. If we look at the design, you see that the title and tagline is shifted to the left and the menu is shifted all the way to the right, and that's what we want to achieve. If we were working with a static site, this would be very simple. We'd simply float the title and tagline to the left, and then we'd float the menu to the right.

However, because this is a responsive site, we have to be a little careful about what we were doing here. First of all, we have to use percentages to decide the area that the title and tagline is going to fit and the area that's going to be occupied by the menu so that as the window decreases in width, the proportion of area occupied by the title and tagline in the menu remains the same even though the pixel widths change. But there's an added challenge here. Like I said, the logical thing to do here would be to simply float one component to the left and the other to the right.

What you want to end up with is an area occupied by the title and tagline and another area occupied by the menu. However, if you float this content, what will happen is the browser will assign vertical space for each of these items, and it will say, as long as the item on the right has smaller or the same vertical space as the item on the left, they should float left and right. However, if the item on the right occupies more vertical space than the item on the left, then the item on the right is allowed to float in under the item on the left, and you end up with this.

As a result, while a short menu will look fine because it floats properly, a long menu will float in underneath the header, and that's not what we want to do. We want to ensure that even in the case where the menu is very long, it will stay on its side of the layout. To do that, we have to be creative. What we need to do is float the entire container that contains both, the title, the tagline and the menu to this right space.

Then we're going to use a negative margin to float the title and tagline outside of that space and place it to the left. By doing that, we're ensuring that no matter what happens, the menu will continue to contain the same horizontal space and title and tagline will always stay on the left. To do this, we need to find out what percentage of area the title and tagline is covering and what percentage of area the menu is covering. There is a math formula for this.

What you do is you find the width that you want, so that's the short width. You multiply that by 100 and then you divide the result by the total width of the entire area. This will give you the percentage of the shorter width in relation to the full width. If we look at our design and look at the guides, we'll see that the total width for the entire area is 940 pixels, and the area we want to be occupied by the title and tagline is 320 pixels.

So the first thing we'll do is take the container that contains all the elements and shift it to the right by giving it a margin to the left. So first, we'll find out what container that is. I'll use the Web Developer tools to identify the container. If I just scroll up here, you'll see. Here it is, header-container, and then I have to find the percentage. I will go to my style sheet and find the header-container. Here it is. Then I want to set margin-left and now I need the percentage.

So I'm going to open my calculator and then I want 320 pixels, which is the short width. I'm going to multiply it by 100, and then I'm going to divide that by the total width, which is 940 pixels. We get 34.04, et cetera, et cetera. So I'm going to copy that entire value, paste it in, percentage, and close the style. When I save that and reload my page, you will see that all the content is now shifted over to the right.

The next thing I need to do is move this title and tagline back over to the left. However, now we're working with a smaller total width. So what I need to do now is find out the percentage width that is equivalent to 320 pixels out of this new area. This new area, if you look at it, is 620 pixels. So I'll go and do the math again, this time 320*100/620.

This gives me 51.61, et cetera. I'll copy that, and then I need to apply that to just this header section. So I'll go in, use my Web Developer tools to find out what the section is. It's called id="header-title". Go back into my Style Sheet, find #header- title, and say margin-left again. And this time I want to do a negative margin because I want to shift it outside the box, so I'll say minus and paste in the percentage. I'll save it, reload the page, and you see now my title is on the left and my menu is on the right; however, the title is knocking the menu down.

To avoid this, I'm going to float the title to the left. So I'll go float: left. Save it, reload it, and now the title and tagline are on the left and aligning with the menu. But there is one more thing I need to do. When we resize this window, you'll see that when we get down to a certain point, it looks like that effect I was talking about where the content is floating underneath happens, even though it's not supposed to. But that's not the case. What we're seeing here is the title doesn't have a percentage width yet, so therefore it's pushing the content in the menu to the right.

The final thing we need to do is to give this menu area the correct percentage width. That percentage width is the percentage width of this area in comparison to the total area. In other words, the menu takes up 51.61, et cetera, percentage and we want the other half of that equation. So I'll simply take that number, I'll go to my calculator and say 100-, and I'll paste in that number, and I get 48.387, et cetera.

I'll copy out that value and set the header-title to have a width of that percentage. I'll save that, reload the page one last time, and now when we resize the window again, you'll see that the title and tagline align to keep within its space, while the menu aligns to keep within its space. As you can see, working with responsive layouts is challenging because you now have to work with percentages, and you also have to have an intricate understanding of how CSS works and the different quirks CSS has to offer.

The good thing is, once you know the tricks, like this using a negative margin to assign space for certain content, you're able to create layouts the way you want them to, without too much hassle. We'll be using this same technique further into the course to handle the general content.

Show transcript

This video is part of

Image for WordPress: Building Responsive Themes
WordPress: Building Responsive Themes

39 video lessons · 17146 viewers

Morten Rand-Hendriksen
Author

 
Expand all | Collapse all
  1. 4m 5s
    1. Welcome
      1m 4s
    2. Using the exercise files
      1m 27s
    3. What you should know before watching this course
      1m 34s
  2. 8m 36s
    1. What is responsive design?
      4m 16s
    2. The different faces of WordPress on mobile
      1m 55s
    3. Exploring the finished Anaximander theme
      2m 25s
  3. 9m 38s
    1. Getting and installing the Anaximander theme
      1m 53s
    2. Configuring basic theme options
      7m 45s
  4. 23m 51s
    1. Deciding what screen sizes to design for
      4m 11s
    2. Thinking responsively: Designing for many different screen sizes
      6m 23s
    3. Visualizing content realignment for better markup
      4m 35s
    4. Designing menus
      4m 52s
    5. Adding responsive images and videos
      3m 50s
  5. 26m 8s
    1. What are media queries and how do they work?
      4m 18s
    2. Exploring CSS3, progressive enhancement, and graceful degradation
      3m 27s
    3. Understanding best practices for media queries
      3m 57s
    4. Creating a responsive frame
      5m 12s
    5. Customizing media queries with the Chrome Developer Tools
      5m 28s
    6. Taking device width into account
      3m 46s
  6. 11m 1s
    1. Resizing the site title and the description
      8m 22s
    2. Adding media queries to the header
      2m 39s
  7. 11m 22s
    1. Making the menu responsive
      3m 35s
    2. Creating a different menu design for small screens
      7m 47s
  8. 19m 22s
    1. Making a responsive single-post layout
      6m 11s
    2. Making images responsive
      4m 37s
    3. Making videos responsive by including FitVids
      8m 34s
  9. 7m 45s
    1. Making the sidebar responsive
      5m 10s
    2. Hiding sidebars on mobile
      2m 35s
  10. 7m 28s
    1. Dealing with footer widgets
      5m 11s
    2. Adding navigation links that return to the top of the page
      2m 17s
  11. 12m 54s
    1. Using FlexSlider to create a responsive slider
      6m 2s
    2. Creating a loop to show sticky posts in a featured slider
      6m 52s
  12. 24m 37s
    1. What is jQuery Masonry?
      3m 41s
    2. Installing jQuery Masonry
      4m 45s
    3. Configuring the index page with Masonry
      7m 0s
    4. Using CSS to finalize the Masonry layout
      6m 17s
    5. Adding media queries to the Masonry index
      2m 54s
  13. 9m 11s
    1. Exploring hidden features of the Anaximander theme
      5m 51s
    2. Where to go from here
      3m 20s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed WordPress: Building Responsive Themes.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.