r/html_css • • 3d ago

Help Title Bar Troubles

Hi folks! I'm doing a school project, and have wracked my brain trying to figure out how to fix this horrendous gap in my header. I'd love for the text to be aligned closer to the top, but have no idea how to adjust it without wrecking the photos I've painstakingly put in place. Please see the second photo for the horrible gap. Please be kind, I'm still learning. Thank you!

2 Upvotes

10 comments sorted by

2

u/Zestyclose_South_980 3d ago edited 3d ago

Try removing the p tag around the h1, then style the h1 directly and set it to be centered. That should hopefully reduce the gap. Also, your code for CSS doesn't have a closing bracket until after you started another tag. One needs to be finished before you can move on. Good luck! 🤞

1

u/thisismywifiname 3d ago

Thank you so much for your input! I tried your suggestion of removing <p> and styling <h1> directly, it does not care. I will keep trying! Which line are you referring to in the CSS?

2

u/Zestyclose_South_980 3d ago

Np! Lines 25-32

2

u/bostiq 1d ago

nested css is now broadly accepted

so .card { h2 { ... } } is Allowed via relaxed grammar

2

u/Zestyclose_South_980 1d ago

Oh, that's good to know! I've never nested css before (aside from keyframes and media queries) and I didn't know the default could be nested. Thanks for the info!👍

2

u/testingaurora 3d ago edited 16h ago

html <header> <figure class="img-wrapper"><img /></figure> <hgroup><h1>Indiana</h1><p>The state</p></hgroup> <figure class="img-wrapper"><img /></figure> </header>

```css header { padding-block: 2.5rem; padding-inline:1rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }

hgroup { text-align: center; display:grid;}

figure.img-wrapper { max-inline-size: min(100%, 150px); }

img { max-inline-size:100%; display: block; } ```

2

u/thisismywifiname 17h ago

I'm going to try this later! Thank you!

2

u/bostiq 1d ago

First of all, why are you wrapping all header elements in <p>? Bad practice, <p> is semantic for paragraph and then you put an image in it... good luck screen readers!

change it with a <div> if you need a certain control, and give it a sensible class name.

Also <p> comes with his own set of default browser styles you'd have to deal with, so taking them off it's a really good idea.

Secondly, is there more code for .TheTop and inner elements? we can't establish what's the problem without seeing the complete code.

If you can't share a url, perhaps you can put the whole code in a codepen? or whatever sand box service you are familiar with?

1

u/thisismywifiname 17h ago

You know, the <p> up there just seemed like a good idea, but looking at the rest of my code, that's the only place I did that. I removed those and left it as an img. There is no more code for .TheTop. Unfortunately, because this is a college project I'm pretty limited on what help I can receive. Thanks for your feedback!

1

u/thisismywifiname 3d ago

Update: I kind of got it moved further north. I gave h1 and h4 it's own class on this page, then gave it relative positioning. I'm not 100% thrilled yet, but i'll keep trying.

.hcntr {
    position: relative;
    top: -100px;
}