Responsive Images in Bootstrap 4
Hello there we are. Going to work with responsive images. We've done it before earlier on so we're going to use those sweet new skills to work it with bootstrap. Okay, we're going to add this image here and we're going to get it so that it's stretchy. You see changes sizes and different media queries, watch it kinda stacks down underneath. We're gonna work through all of the different options with Bootstrap four envious code right now. Okay, so we want, we're looking at the mock up now so we've got our text and I want to actually put this image in over on this side. So there's a couple of ways of doing it and they will be will cover cover them in this video. Okay. And it really depends on the implementation. What I really want to do is this image to break down onto its own line. Okay, after it goes down to mobile you can see here, I want to kind of underneath the same sort of thing with the founder message. Okay, starts up their moves down but these little slider guys, okay, I'm just g...
oing to turn off. Okay, so there's lots of different implementations depending on what you want to do. So let's add the image to V S code, I wanted to be inside my jumbotron which finishes there, which is not quite lined up. There we go. Okay, so I want it just afterwards and I'm going to type it in here. I'm gonna say let's line it up with everything else in there. Image. Okay. Image Source. This one's going to images slash and this one is called Hero one dot PNG. Okay, because it needs a transparent background, I'm gonna make sure put my old text in their dans meet Yogurts. Yogurts, you can spell out a couple of ways. I'm destined to fail on that word, but there's my old text. Okay, so I've got an image. Let's see what it looks like by naturally by naturally and its habitat naturally. Okay, it's massive. Okay, by default and bootstrap images, try and stretch all the way out. You're like, that's not what I want. I want it small and over here there's a couple of things we can do. Let's look at the bootstrap documentation. Okay? And let's look under content. I know it's under content and images, you're gonna have to click around for a long time or do a search. Okay, so in images, all we need to do is we need to make, yeah, it kind of tells you what you need to do. So in our case if we want to make a responsive image, we need to add this tag called image or I. M G hyphen fluid. Okay, so that it kind of moves around, there's other ways we can turn into thumbnails by calling it. It's just have a look at this just because it's interesting, so we add the class I MG thumbnail to this thing so we've got you you you before the closing of the image tag, we're gonna put it in the class thumbnail. Let's have a look at her now. There you go. He's in a big white box with white background with rounded corners. Still too big but just so you know there are some strange classes but just other use cases we don't know what for this so this might be interesting. Okay I want it to be I want the class of maybe float right so I can push it over to that right hand side. Let's see how that works. So let's do that one. Let's see what happens. Okay still not working because it's too big. So what a lot of people do with bootstrap is they'll just give it a width in here. So let's say it's a width of let's say 500 pixels. Okay so it fits up the side and I'll give it a height okay of auto so that yeah the width you define and it'll just be whatever equivalent ratio is for the height and that's a way of kind of doing it. You're like okay we're getting there. Now I know in this case I wanted to be up so we're gonna have to add like negative margins and trying to pull it up this way maybe some absolute positioning. So I am going to show you a different way because you might be exactly where you need to be. You've got an image, it responds to different sizes and have a look. Get down. Okay doesn't get down small enough to fit and I haven't actually added the image responsive. Okay so let's go in there and do that. So I've floated it to the right but I also want is that I. M. G. Fluid. Okay so it actually changes size. Okay so you can see they're kind of getting bigger and smaller. Let's actually turn on the Inspector Adele device preview and now we're going to slide it in and out and you can see the image move that down a bit. Okay? It gets bigger and smaller because I've added that image responsive and that's kind of working for us, right gets to here and I just want to pop it up that way and you could chase the negative margin to pull it up maybe absolutely position it. So it kind of forgets about this and kind of moves up to the top but I know that's going to cause me problems when I want to on mobile remember break it down into its own line, okay to kind of separate it here. So what I want to do is actually just put it into two, like into a row. Like we've done lots of things right, put into a row and then have two columns that I can break on these two parts and we can just take like this one seems a little bit wider than this one. So this may be can be I don't know seven and this one could be five columns and then I can just On mobile devices make it 12 and 12. So let's give that a go. So let's have a look. And often you only get to this point where you're like actually be better in two columns after you've had a fight with float ride and negative margins and you're like give up, you're like actually, so let's get rid of height with okay that stuff we're gonna keep the image fluid and we're going to get rid of float white. So we're back to kind of just having it sitting there, no height, no width. We're gonna let the column width decide how big it is. Okay, so let's, first of all we're going to need this. Okay, so I'm going to cut it into my clipboard. Okay so I've gone to edit cut. Okay so I've got it somewhere. You can paste it, another document if you're worried about losing it. I always do or worry about it at least. And inside of here I want a row with inside of that. I want to columns please. Okay and these columns are going to have my, this first column is going to have all that stuff that I pasted. It's gonna have my H1 in my p. Tag and my a tag and all that sort of stuff except the image. He's going to go in this other column here now. One question you might have is like hey you didn't put like that internal diff we made the coal and then normally we put in, remember my box, we only added that my box. If we needed to change the column some way, we've been adding lots of color to the background and changing it a lot. We're not going to do any of that. We're just using it as a simple old container and we're doing stuff with this within it. I don't need to mess with the column. Does that make sense If I wanted to add margins to the column to the top or the bottom? Okay. I would actually put an internal Devyn here called my box and do it to that. Because remember, we don't like to mess with the coal cole knows where you live and we'll find you All right. So, it's gonna kind of work. Let's have a well, I hope it's gonna work. Let's have a little look. So, it's there. Okay. It's doing half and half. Ok. So, they're kind of 50 50. It's not quite what I need. So, I need it to be actually, I wanted to be not 50. About seven and five. We get to 12 columns, which is cool, Okay. And that's gonna kind of work. It's gonna work perfectly. Except now we want to work out the mobile. So that was great for this view when I get down to kind of, this sort of size. Okay, see this media career here, I guess is what this was, I think in your head. Okay. Which which media query is that? Is that the L. G. No, it's not. It's the S. M. So small, you know that you got it. All right. So, I want to so both this one and this one, I probably want them to be stacked on top because the image gets small, it's wrecking this and okay, it's got enough room here. It looks good. So let's attack that. So, what I want to do is instead of saying this one here is going to be my medium and above probably the thunder in the background. Very exciting here today. And not so good because I'm in a tin shed, exciting enough. Um so we are going to I'm distracted by the thunder and the realization that I'm gonna 10 big metal shed anyway, so what are we doing? Okay. We've decided that at large it's going to do it, but down here, okay. It's not doing anything. It's gonna we're gonna force it to be 12. So flustered. Okay, So we're going to say a coal 12, which assumes, okay, you mean extra small. And because I don't say small, it's going to assume it's 12 on small as well. And then finally, when it gets to the medium, it's going to say actually I'm going to override you. I'm going to go to five. So mobile first you got it have a look. I know it does it by default, but sometimes it's only because the content forces it to you're not really doing it. Okay. So it looks good. It's all stacked on top of each other and then boom and it gets to there kind of moves this, that's why I went for the two column approach because it makes this nice and easy. There's a few other things I want to do. Maybe lower the font size. Okay. When I get down to this one because it's kind of breaking in weird places and we need to play with padding and we need to center it because my kind of mock up here has the text centered on mobile. So we'll do that in the next video. That's of course if I'm here in the next video and not struck by lightning.