Why do I have extra space between elements? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do I have extra space between elements?

I'm practicing creating layouts with CSS, and somehow I ended up with this space between the banner image and the navigation bar. Can someone tell me how to get rid of it? Neither element has top or bottom margins. https://code.sololearn.com/WySGfy7UDHdO/?ref=app

26th May 2020, 2:54 AM
Lucas Smith
Lucas Smith - avatar
6 Answers
+ 2
Here your <ul> element has margins so: /* Styles for main navigation */ #navbar { list-style-type: none; height: 25px; width: 100%; background-color: #36688d; margin: 0; } You should add margin: 0; It helps 80% avoid extra spaces.
26th May 2020, 3:08 AM
Muhammadamin
Muhammadamin - avatar
+ 1
Your image can't fill its parent div with id #banner. There lots of ways, try this Add in your image margin-bottom: - 5px; (maybe 6px ...) #banner img { height: 140px; width: 100%; margin-bottom: -5px; } And check, may be it looks different in mobile and computer displays. And you can find another ways Try again and again.
26th May 2020, 6:07 AM
Muhammadamin
Muhammadamin - avatar
0
Muhammad Thank you, that helped! There is still a gap, but it's smaller now. Is it possible to completely remove it?
26th May 2020, 3:48 AM
Lucas Smith
Lucas Smith - avatar
0
And I think your JQuery scripts do nothing now, if you remove your code nothing will change.
26th May 2020, 6:13 AM
Muhammadamin
Muhammadamin - avatar
0
Thanks Muhammad ! And yes, the JQuery script was part of a separate experiment lol
26th May 2020, 1:40 PM
Lucas Smith
Lucas Smith - avatar
0
Not at all good luck!
26th May 2020, 2:22 PM
Muhammadamin
Muhammadamin - avatar