Check out a free preview of the full Introduction to CSS course:
The "Header CSS Solution" Lesson is part of the full, Introduction to CSS course featured in this preview video. Here's what you'd learn in this lesson's course:

Jen first identifies the flex container and flex items within the page and HTML code and then uses flexbox to create the solution header.

Get Unlimited Access Now

Transcript from the "Header CSS Solution" Lesson

>> Jen Kramer: All right, next let's go ahead and tackle this header. This header through a lot of people but this is the flexbox portion of this. This is where I would really recommend using flexbox. So let's think about what's going on here. And it's often helpful just to look at your starting picture, my starting picture went.

Look at your starting picture, and describe what's going on here, okay? Sometimes it just helps to say it out loud, okay? So I've got an image over here on one side, and I have two lines of text over here on the other side. And they're right next to each other, right?

That kind of looks like two boxes, doesn't it? Two boxes side-by-side, on the same row. Doesn't it look that way? Yeah, kinda looks that way. So let's look at your HTML, and sure enough look we have a box here for our leftheader, and we have a box here for our rightheader.

And where's their parent?
>> Jen Kramer: The header tag is their parent, right? So our header is the what? Flex what?
>> Speaker 2: Container.
>> Jen Kramer: Flex container, I know it was a lot of terminology today. [LAUGH] Flex container. Okay, and the div inside of that, the div with the class of leftheader, and the div with the class of rightheader.

They are what?
>> Jen Kramer: Flex,
>> Jen Kramer: Items, flex items, okay? So there are the children. So what we need to do then is put these two things side by side. So what we're going to do,
>> Jen Kramer: Is read about here. We'll go ahead and we're gonna put in our header, we know we're gonna style that.

>> Jen Kramer: And we're gonna need to put in our usual flex properties here, right? So what are the properties we need to put in to make this flexbox?
>> Speaker 3: Display.
>> Jen Kramer: Display.
>> Jen Kramer: What's the value?
>> Speaker 3: Flex.
>> Jen Kramer: Flex, okay. What else do I need to put in?
>> Speaker 3: Flex-flow.

>> Jen Kramer: Flex-flow, and my values here?
>> Speaker 3: Row nowrap.
>> Jen Kramer: Row, nowrap, okay. Anything else?
>> Jen Kramer: Right? So let's just do that launch and see what happens, if we save that.
>> Jen Kramer: Refresh the page, there we go. So we've got our picture, and we've got our text, kinda next to it, right?

So this is good, we're making progress, okay? So what else we can do here? What I did, was I said we'll have a justify if in content, space-between. So that's gonna give me a little bit of space between the two boxes. Then in terms of the boxes themselves, we can write some styles for that.

>> Jen Kramer: And rightheader.
>> Jen Kramer: Okay, and so what are we gonna put in here for leftheader? We probably want to flex basis, right? Flex-basis of 40%. Why 40%? Cuz I played around with it and tried a bunch of different values, and I thought this was prettiest, okay? We can do the same thing here for rightheader flex-basis of 60%.

>> Jen Kramer: Okay, and if we look at page now, all right? So wow, hard to say what's going on here? Do we have any suggestions for debugging?
>> Jen Kramer: The next thing to tattoo on your forehead, stick a border on it, okay? Stick a border on it. We don't know what's going on, put a border on it, border.

3px dotted green, and we're gonna put a border on the right here, border, 3px dotted blue.
>> Jen Kramer: And once we do that we can see much better what's going on, right? So my image is shoved all the way over here on the left side of this box. Where should it really be?

>> Speaker 3: Center.
>> Jen Kramer: Right. On the right side of this box. How can I get it to the right side of the box?
>> Jen Kramer: Anyone have a suggestion?
>> Speaker 2: If you said float, right?
>> Jen Kramer: Float, right, maybe? But there's an easier way.
>> Jen Kramer: It's actually not the left, I'm sorry I need to be on the left side.

How about just text-align? Right, just plain old text-align, right.
>> Jen Kramer: Much better.
>> Speaker 2: So that works even though it's an image?
>> Jen Kramer: Even though it's an image, yep, it's an in-line element. So it's very happily we'll screwed them over to the right-hand side of that box. Yes, Jenna.

>> Speaker 2: I'm just gonna say, for me flow it, and then the right didn't work at all was really nice line.
>> Jen Kramer: Yeah, yeah, cuz it is flex is a flex item and trying to mix a rear flex with your floats and that it's just bad form. Don't do that, don't do that.

Okay, so then I had some padding things that I put in again, it was a lot of trial and error on my part to see what look pretty. But around this sort of out, I'm gonna take out my ugly border, and I'll give you my other values that worked for me.

For the leftheader, I had a flex-basis, a text-align, and a padding- right of 0.5 rem, okay, for the leftheader. And then for the rightheader, and I had the flex-basis of 60%
>> Jen Kramer: And I have the margin-top of 3.75 rem, so that's gonna push it down from the top.

And I had some padding on the left of 0.5 rem, okay. And so what that did was it went ahead and aligned this very nicely in the middle. Although these font sizes needed to change in order for this to completely work. So let me give you those styles as well.

I think I over-deleted some of these styles. Rightheader, h1, what I had going on here for the rightheader h1 was margin 0. That's part of the problem that's going on here. Why do we have that huge gap in between the Blog and My So-called Light Speed Life? That's a margin that's coming from the h1 or the paragraphs by default, right?

So one of the things we need to do in order to tighten up the space between those is turn off that default margin. So we turn that off color of da0090 which is that lovely shade of pink. So that'll make the each one that pink color, and a font-size of 3 rem.

>> Jen Kramer: So that's a good start there, a little bit bigger. And then did I do anything paragraph, I did. I thought that gap was still a little bit big here. So for the paragraph, what I did was I added a rightheader p, and I said the margin on the top should be 0.5 rem, okay?

So that will tighten up that space just a little bit and make it look much prettier
>> Jen Kramer: Cool? So sometimes it's flexbox, sometimes it's default margins that come with it from the browser that you have to get rid of, sometimes you gotta add your own margin and padding.

But it's all boxes, and boxes, and boxes.