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

Making a responsive single-post layout

From: WordPress: Building Responsive Themes

Video: Making a responsive single-post layout

Now that we have a responsive header, it's time to move on to creating responsive layouts for our content, and we'll start with the single post. If I go to a single post, you see that we have the layout that's based on the small screens. We have the title and meta information on top and then we have the content underneath. But on this large screen, that doesn't look very good, because we have way too much space for these lines of text. And when you get text that is above a certain number of words per line, it becomes very hard to read.

Making a responsive single-post layout

Now that we have a responsive header, it's time to move on to creating responsive layouts for our content, and we'll start with the single post. If I go to a single post, you see that we have the layout that's based on the small screens. We have the title and meta information on top and then we have the content underneath. But on this large screen, that doesn't look very good, because we have way too much space for these lines of text. And when you get text that is above a certain number of words per line, it becomes very hard to read.

That's the reason why, in the original design, I created this layout with the header and meta content on the left and the main content on the right. So, what we are going to do now is use that same technique we used to create that responsive header to change the layout of this main content area to make it flow the way it's supposed to. So we'll use that same math formula I showed earlier to find the correct percentages so that we can lay this out. First, we need to identify the elements we are going to move.

You'll remember what we want to do here is first take all the content on the page and shift it to the right so that it only occupies this section of the page. So, the first thing we need to do is find that container. I'll go to my browser and use the Developer Tools to find what container contains everything. And you see here we have three main elements for the single post: we have a header, we have the entry-content, and we have a footer.

And all of those three elements are contained within this article with a class post-container. So this is the element we want to shift to the right first. I'll go to my style sheet and find the main content section, and here, I'll add in a new style for a post container. This style is going to have a margin left, and now I just need to find out what that value is. So, I'll go back to my design. I'll find the total width, which is 940 pixels, and then I'll find the width of the margin we are going to add, and that margin is 320 pixels.

So, in my calculator, I go 320 times 100 divided by 940. That gives me 34.04, et cetera. I'll copy that and paste it in as a percentage. Now, you'll notice I am not rounding this out because computers are incredibly good at math, so there's no point in rounding it out. Ideally, you'd even have a longer percentage than this, but that's what the calculator gave me, so that's what I am using. I'll save this, and when I reload my browser, you'll see the content shift to the right like we want it to.

Now, I want to shift the header-content back to the left. So first, I'll identify the header-content container, and you see here, it's called header class entry-header. So I'll create that style. And I know that in this case I want to have a margin-left that is negative, and I just have to find that value. Going back to the design, I know that I want to shift it the equivalent of 320 pixels to the left, but now that percentage has to be relative to the total width of just this area, which is 620 pixels.

So, I'll go back to my calculator and go 320 times 100 divided by 620. This gives me 51.61, et cetera. I'll copy that, I'll paste it in, make it a percentage, and then I also want the entry header to float left, so I'll say float: left. And when I save this and reload my browser, the header is now floating to the left. However, you also notice that it's shifting everything down, and not only that, but it's spanning into an area it's not supposed to be in.

That's because we haven't yet defined a width for the header, so it's taking up 100% of the space. The final thing we need to do is go back to our design and look at what the total width of this header is supposed to be. You'll see here that we only have this much space for the header, because I left a 20- pixel gutter between the header and the rest of the content, so that it doesn't clash into each other. So, what we want to do is find the percentage equivalent of this width, which is 300 pixels, in relation to the total width, which we've defined here as 620 pixels.

Back to the calculator. We go 300 pixels times 100 divided by 620. We get 48.38, et cetera. I'll copy that and go width 48 point, et cetera, percentage, save, reload it in the browser, and now it lines up properly. More importantly, it will also scale down. So when I change the size of this window and we ignore the image for now, you'll see that these two elements size proportionately when the scale changes.

The final thing we need to do is add the media queries so that when we get below that breakpoint, everything realigns, so we get the title and everything on top and the content below it. So I'll go in here and copy out the styles I just created, go down to my media queries, and find the media queries for the breakpoint, which is here, at 719 pixels. We'll scroll down and find a logical place to place it, which would be right here. And I'll paste in my current styles, do some cleanup, and then I'll just reset everything.

So, the margin-left set to zero, margin-left set to zero, float set to none, and finally, the width set to 100%. Save that, reload the browser again, and everything snaps into place. Small screens, larger screens.

Show transcript

This video is part of

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

39 video lessons · 16972 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.