coadreamweaver.files.wordpress.com  · web viewwell, what's going to happen if i go back into...

10
Creating a layout that fits all browsers A recent movement that's going on in the web today's what is called a responsive design, and that's having your content respond based on the browser window size as well as even the device you view your content on. So say for instance, if I scaled down this browser window, you can see that everything is static. So if you're viewing this on a smaller monitor, the user would actually have to scroll, so that's not very usable. What if they're on an iPad that's more like this? Well, again, you have the same issue where they're going to have to scroll, and it gets even worse as we go down to even a mobile device. So we need to make sure our content is flexible and responds based on the browser window size. So that's what I'm going to do. I'm going to start off first with this Nav bar. With that Nav bar selected, notice right down here, all of these sizes and positions are fixed. So they're fixed sizes and positions. And what I can do is I can say, hey, you know what? From the left side, let's make it 5% of that total width will be 5%. What about the width of the bar entirely? Well, let's make that 90%.

Upload: lemien

Post on 28-Nov-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Creating a layout that fits all browsers

A recent movement that's going on in the web today's what is called a responsive design, and that's having your content respond based on the browser window size as well as even the device you view your content on. So say for instance, if I scaled down this browser window, you can see that everything is static. So if you're viewing this on a smaller monitor, the user would actually have to scroll, so that's not very usable. What if they're on an iPad that's more like this? Well, again, you have the same issue where they're going to have to scroll, and it gets even worse as we go down to even a mobile device.

So we need to make sure our content is flexible and responds based on the browser window size. So that's what I'm going to do. I'm going to start off first with this Nav bar. With that Nav bar selected, notice right down here, all of these sizes and positions are fixed. So they're fixed sizes and positions. And what I can do is I can say, hey, you know what? From the left side, let's make it 5% of that total width will be 5%. What about the width of the bar entirely? Well, let's make that 90%.

So now we have 5%, 90% and then another 5% there. So I just made it more flexible. In fact, if I save this and even view it in a browser and resize this window, you can see how that reacts. That's exactly what I want. In fact, going from there I want this section to move accordingly. Maybe I wanted to always be 60% of the width of the browser window and still give it that 5% padding on the side.

To keep in mind it's actually floating on the right side so this will be a little bit different. Going in here to this item right here, I can select. It happens to be this div and what I can do for this tag, I can change this say for instance, from the left-hand side. Well, I don't want it to be fixed at 425. So I'm just going to delete at entirely, just like that. Well, that doesn't seem quite right, but we'll get there. The width, well, we can make it 60% just like that.

Well, okay that's good. But how do I make it float on the right-hand side? Well, I need to go beyond this Properties panel. Again, it's for this section tag. I can double-click on it to edit the CSS Rule definition, and I can go down in here to the Box category, and I can say, hey, you know what? Go ahead and float to the right-hand side. Float it on the right. In fact, for the Positioning, don't make the Position absolute, make it relative.

That's going to be the Position. Clicking Apply, it floats it over there. Also, right down here from the right- hand side, let's give it that 5% padding. Clicking Apply, we can move that in. That will line up. With all of that in place I can save this and preview it in a browser. There is my section, and it expands and contracts accordingly. So far so good.

I'm going to do two more things really fast, and that's these elements. I always want these elements to be flush with this nav. So closing that I will come in here for this particular item. Again from the left side don't make that fixed, make it always 5%. For this element it happens to be the header. Don't make it

100 pixels from the side. Make that 5% as well of the total browser width, saving that, previewing it in browser, and now we have that nice and flexible. It's all locked down, and now we can go from large to small.

But what's also happening here--and this is really the last thing I'm going to visually--is I don't want this background to get cut out. I really like it. I want the background to scale down. I wanted to still cover, but I want it to make sure it fills that browser window. So I'm going to have the background scale, closing that. Now I got to find my background first. So right in here as I select this body tag, you're going to see it right down here, and I can double-click on it, and I can go in to the Background right here, and you will start to look in here, and you'll notice, well, there is this Background-repeat, Background-attachment. Well, I can change that to fixed.

So it's always going to stay in a fixed position so the content will scroll. So I like that, but that background cover is not in here. So I'll just click OK. What I can do is I can Add a Property, because there is actually even more properties available in here. In fact, to look at all these various CSS properties I can add to this element. So I'll scroll up. I want to locate the background. Quite a few in here, quite a few properties, and background size is what I want to select.

So selecting that. I am going to check out my options for it to make it automatic. Contain which means it will always be contained. You will see the entire image that I wanted to cover, regardless of the size or aspect ratio of the browser. So selecting cover. I think that will do it, and I will save this page. Here's the

fun part. It's previewing it in a browser. I see that nice full image. Well, what if you're a on a small browser window, or on a small monitor? That's looks good. It scales.

So this is what I mean when I say responsive design. Having this flexible layout, you can see how wonderful this works and how beneficial this will be for your end user, making sure they can see all of the content.

Making CSS more flexible

Just like you want your web page to be flexible and fit different screens, different sizes, you also need your CSS, or your cascading style sheets, to be as flexible as possible. And luckily, CSS does just that because it enables the separation of the content from the design. And the CSS styles can be internal or external, so this is great. You can have that separation be, say, at the top of an HTML page--still internal to that HTML page--or it can actually be a separate page entirely and they're just linked together.

So, this is obviously great because you can have multiple pages that use that one style sheet, and that CSS will affect all of those pages. Makes it easy to update, everything will be consistent, the file size will be smaller since you're just referring to that one file. So, let's take a look at how we do that, even moving some CSS from one web page out of it to a separate CSS file. Here I am in Dreamweaver, and I want my CSS and quite frankly all of my code to be as flexible as the layout.

And currently, if I take a look at my CSS, well, I'm wondering where does this CSS live? How is it set up? Well, if I right-click and go to code, I can see the CSS right in here. Well, where is it? It's actually inside of my HTML page. It's all embedded. So, if I happen to need to make multiple pages, they're all going to have those same CSS styles in each and every HTML page.

When really what I need to do is take all the CSS and put it in an external style sheet, and that happens to be what's going on here is there's an external style sheet from when I used a web font. So, that's what this is right here, that stylesheet.css is this style sheet. So what I can do is I can take all of these CSS styles just Shift-select them, do a right-click, and I can move the CSS Rules.

When I do that, note that it's automatically selected that CSS style sheet right here, and note if you didn't import any sort of web font, you can create a new style sheet from scratch. But in this case, since I already have one, I'll just point to it and select OK. Oh! What just happened? Oh! It indented everything. Says, hey! You know, I am part of this CSS now. So I can open that up. In fact, if I take a look at my code, I can see it's all moved. It's no longer in my HTML.

In fact, it's inside of this CSS. And check this out, it's linkable right here. So, I can click on stylesheet.css. This is nice! As I go into Code View, I can see all of my code nice and neat just like that. So, that looks pretty good. I'm going to save this document, and that's one thing you'll have to be aware of is you're going to want to start saving all your related files, because as you make changes in here, you want to make sure that it reflected in the source code.

But one thing I've noticed in here is, well, to be honest with you, I'm not crazy about where this stylesheet exists. It's within this Font folder. That's where the stylesheet.css is. And a good practice is to have it in a separate CSS folder. So, if I take a look at this specific folder, I can go ahead and move it, in fact, rename that folder. So, let me do that now. Here I am, here is my Font folder, and I'm going to just rename this to CSS just like that.

It doesn't bother me that there are some web fonts in here. It's perfectly fine. I just want to be really clear that these are my CSS files--will all exist right in the CSS folder. So I've changed it there. Well, what's going to happen if I go back into Dreamweaver and go to Design View? If I take a look at it, turn off this Live View, even turn it back on, you can see that I don't see it initially, and that's because I need to change this to CSS just like that. All right! There we have it.

I'm going to save all, or I can save all related files. But I'm saving everything. My style sheet is now in a CSS folder. If I go to Design View, everything looks good in Design View, and everything looks good in Live View. Another thing I want to point out as I take a peek at this CSS is that Dreamweaver was aware of the fact that there were images that were linked. So, when I moved all these styles into the style sheet, it knew to change the path to that JPEG.

So it actually has to go out a folder and then back into that Images folder. Let me show you what that looks like. It will go out a folder--so that's what those two dots are--go out a folder and then go into that Images folder to find that Background Home, okay? So that's how that works. I like how Dreamweaver is intelligent on knowing where items are, we can see that everything looks seamless and works seamless, and now what I can do is I can reuse this CSS across multiple pages.