Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Welcome back! I hope you had fun working on the flexible version of the desolve.org layout. Now, flexible layouts are difficult, especially the more complex your pages get, so don't feel bad if a few of the steps didn't work out the way you wanted them to. Let's go through our finished code together, and then we can compare the results. So I have the index and the main.css files open, so index.htm, main.css, and you can find these in the finished_files directory of 06_06. And of course the CSS one is in its own little directory there, _css. Okay.
So I am just going to start with the steps and work my way down. I'm first going to scroll down in the finished_code to about line 167 or so. I gave the body a width of 90%, and then I gave it a maximum width of 1180 and a minimum width of 860. I am guessing your values probably differ from mine a little bit. That's one of the things about setting a minimum- and a maximum-width value. Generally, a lot of times, it just goes down through personal preference. But I did find that below 860 my layout broke, for a number of different reasons.
I am going to switch over to the browser here and I notice that once I started getting below this value, the navigation really started to run into each other. You can see that the centering of the navigation is still a little off right here, but it got even more off the further down I went. So at about 860 pixels, I decided to sort of freeze it at that point. All right! Now going back into the code, I am going to scroll down a little bit down to the article and the aside. I noticed that the widths are set to the values that I gave you up in the comments, 70.1 for the width for the article, 3.9% padding for both of them.
The article of course is padding to left, because it's the left-hand column; and the aside has padding placed on the right, because it's the right-hand column. Remember, we don't really need to specify any space between the two of them because we're letting the layout itself sort of form that space. So that's something that we don't need to do. Now, I also told you to go down and in the mainNav banner and header elements, go ahead and line up their content with the content of these columns. And if I scroll down to line 199, you can see for the header, all I had to do was place padding-left of 3.9%, because they're all top-level elements.
Same thing for mainNav. About line 237 or so, you can see that has a padding-left of 3.9%. And then the banner selector, which is a little bit further down here, around 295 or so, it has a padding-left of 3.9%. So because these were all top-level elements, meaning they're sitting right inside the body tag, I didn't need to do any further calculations on them. I could just go ahead and use the exact same padding values that the columns and cells were using. Had they been nested inside of them, I would have had to recalculate those values. Now, speaking of that, those two news items, if I go back into the browser of course, these two news items right here that are floating side by side each other, you were tasked also to find out the padding values, the margin values between them, and the width of them, again so that you can arrive at sort of equal spacing between all of those elements.
Now, this is totally a judgment call. You probably did a lot of tweaking, and your values might not necessarily match mine, and that's okay as long as you're happy with the results. So if I scroll down, I can find, on line 360, the news selector for this. Now, you'll notice that for both of these, I used a width of 44%, and I used a padding on both sides of 2%, on the left- hand side of 2%, the right-hand side of 2%. Add up to a total width for both these elements of 48%, which of course is going to leave about 4% space between the two of them, which is why the margin-right is set to 4%.
Now, it doesn't matter that your values match mine precisely. You could use some decimal points. Maybe you did 45% for the width, or 48%. It doesn't really matter. As long as you're comfortable with the spacing and you like the way that it looks, that's fine! What's important here, however, is that all those values add up to 100%, so that you're taking up all the available space within the column. Now, the contest images, the last task that I gave you, to make sure those images displayed at their natural size if they were able to and then scale down if the browser was scaled down, that was a little trickier.
I played a little trick on you there. That's a little harder than it seems, because in the previous exercise where we did that, remember we set the maximum width to 100%. But the maximum width there, in order for it to be that size, is not 100%. Let me show you what I mean. If I go down to, all the way down, let's go down to about line 650 here in our code, I can find content image. Now, here is how I solved it. For these content images, I placed their maximum width at 82%. All right! How many people got 82%? Show of hands. A couple of people. Anybody, 82%? So how in the world did I get 82% and I didn't just give it 100%? Well remember, 100% would have made it fill the entire right-hand column, which is going to scale it up, and it's not the way I want that to look.
So I placed two images side by side just like I did in the previous fluid images exercise, and I began playing around with the width until I got a width value that was equal to the 200 pixels of width that the image actually was, and that turns out to be 82%. So I am saying, okay, you can be your normal width, but any other time I want you to be 82% of that column, and that way it's going to maintain that sizing-spacing relationship with all the other elements. Now, of course I also had to modify the code, so if I went back to index and took a look at these images, you can see that I got rid of the height property.
Now I left the width property in here. Some of you probably stripped it out. If you did, that's fine. That's no problem. So essentially, what this is doing now is it's telling the browser, hey! I need to be 200 pixels wide. And then the CSS is overwriting that, and saying okay, yeah, 200 pixels is fine as long as you're not above 82% of the column width. And that's how that's working. So it will appear at 200 pixels wide if it can. It's going to calculate its height based on the aspect ratio, and that it will never be wider than 82% of the column. So now, when we scale this, the images display at their natural size until you start scaling it down, and then they maintain that relationship at 82% the entire time.
Okay. Of all the labs I've given you, I'll be honest with you, this one took the most time for me to actually put together. To convert the fixed version of the deslove.org site that I was working with before this to the fluid versions, I had to make significant changes to the overall layout, and in more than just one area. So if you want to take this lab a little bit further, if you really want to dig it apart, compare this layout to the finished layout in our floats lab, which is the previous lab where we used the fixed version of this layout. See if you can identify all of the formatting changes from the fixed layout to this one, and there a lot of them, and think about why they were necessary in order for this fluid layout to work.
Now, that should give you some insight into some of the issues that you'll need to think about as you begin to create fluid layouts in your own work.
Get unlimited access to all courses for just $25/month.Become a member
58 Video lessons · 59616 Viewers
61 Video lessons · 92425 Viewers
82 Video lessons · 104131 Viewers
56 Video lessons · 106949 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.