Having trouble linking two divs together

I've been struggling with connecting the divs topnav and subbanner in my code. No matter what I try, there always seems to be some space left between them.

Picture alignment has also been causing me some issues, but I'm confident that I'll figure that out eventually. However, this particular problem is proving to be quite stubborn.

Below is the code snippet:

body{ 
background-color: #0066CC; 
} 

#top{
background-color: #333399;
border-bottom: 1px #eeeeee solid;
height: 200px;
width: 900px;
padding-bottom: 20px;
margin: auto;
}

#logo{ 
margin-left: 20px;
margin-top: 30px ;
padding: 0;
float: left; 
overflow: hidden;
clear: both;
vertical-align: middle;
}

#logo img{
margin-top: 20px;
vertical-align: middle;
margin: auto;
position: relative;
width: 170px;
height: 170px;
}

#title {
float: right;
margin-top: 10px;
margin-right: 155px;
text-align: justify;
height: 150px;
}

#title h1 {
line-height: 60%;
color: #ffffff;
text-align: center;
font-family: Arial, Arial, Helvetica, sans-serif;
}

#title p {
color: #ffffff;
text-align: center;
font-size: 12px;
font-family: Arial, Arial, Helvetica, sans-serif;
}

#topnav {
width: 900px;
margin: auto;
background-color: #333399;
height: 40px;
border-top: 2px white solid;
}

#topnav ul { 
margin-top: 0;
float: left; 
height: 40px;
padding: 0;
}

#topnav ul li { 
display: inline; 
background-color: #339999;
}

#topnav ul li a{ 
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
text-decoration: none;
float:left; 
padding: 10px 20px;
text-align: center;
height: 20px; 
width: 140px;
}

#topnav a:link{ color:#ffffff; }
#topnav a:visited{ color:#ffffff; }
#topnav a:active{ color:#ffffff; }
#topnav a:hover { background-color: #0077CC; }
#topnav a:focus{ color:#ffffff; }

#subbanner {
height: 200px;
background-color: #2687D7; 
width: 900px;
margin: auto;
padding-bottom: 5px;
overflow: hidden;

}

#subbanner h2 {
text-align: center;
text-decoration: none;
color: #ffffff;
font-family: Arial, Helvetica, sans-serif;
}

#subbanner p { 
margin: 0px 150px;
font-family: Arial, Helvetica, sans-serif; 
}

#dobrodosli{ 
float: left;
margin-left: 10px;
margin-right: 15px;
border-width: 5px;
border-top-style: outset;
border-right-style: inset;
border-bottom-style: inset;
border-left-style: outset;
border-top-color: DodgerBlue;
border-left-color: DodgerBlue;
border-right-color: Cyan;
border-bottom-color: Cyan;
vertical-align: middle;
align: middle;
}

#picture1{ 
float: right;
margin-left: 15px;
margin-right: 10px;
border-width: 5px;
border-top-style:outset;
border-right-style:inset;
border-bottom-style:inset;
border-left-style: outset;
border-top-color: cyan;
border-left-color: cyan;
border-right-color: DodgerBlue;
border-bottom-color: DodgerBlue;
}
<!DOCTYPE html>
<html>
<head>
<title>Modent - naslovna</title>
<link href="CSS/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
    <div id="top">
    <div id="logo">
        <a href="index.html"><img src="Slike/logo2.png" /></a>
        </div>
    <div id="title">
        <h1>Zdravstvena ustanova</h1>
        <h1>stomatolo&#353;ka ambulanta</h1>
        <hr/>
        <h1>M O D E N T &nbsp; &nbsp; L O P A R E</h1>
        <p>Cara Du&#353;ana 32 A Lopare</p>
    </div>
    </div>
    <div id="topnav">
    <ul>
<li><a href="index.html">Naslovna</a></li>
<li><a href="about.html">O nama</a></li>
<li><a href="team.html">Tim</a></li>
<li><a href="galerija.html">Galerija</a></li>
<li><a href="contact.html">Kontakt</a></li>
</ul>

    </div>
    <div id="subbanner">
    <h2>Dobrodo&#353;li u Modent!</h2><br />
        <img id="dobrodosli" src="Slike/dobrodosli.jpg" /><img id="picture1" src="Slike/op_1.jpg" />
        <p>Zdravstvena ustanova stomatoloska ambulanta <b><i>MODENT Lopare</i></b> pocela je sa radom 03.02.2004.            godine. Organizovana je na taj nacin da strucnim radom i visoko profesionalnom stomatoloskom aparaturom           pruzi sve usluge pacijentima iz oblasti stomatoloske zdravstvene zastite.</p>

Answer №1

CSS Tips:

Try removing the overflow property and adding padding to the top

#subbanner {
    height: 200px;
    background-color: #2687D7; 
    width: 900px;
    margin: auto;
    padding-bottom: 5px;
    padding-top: 1px; 

}

Alternatively:

#subbanner {
    ...
    //overflow: hidden;
    ... 
}
#subbanner h2{
    ....
    margin-top: 0
    ...
}

Answer №2

By default, browsers apply a margin to ul elements which can be overridden by specifically setting 'margin-bottom: 0;' for '#topnav ul' in the following code snippet:

#topnav ul {
  margin-top: 0;
  margin-bottom: 0;
  float: left;
  height: 40px;
  padding: 0;
}

Answer №3

Include margin-bottom:0 in the following manner :

#topnav ul { 

    margin-bottom: 0;

   //More code...

}

Complete Code :

body        { 
            background-color: #0066CC; 
            }        
                
#top        {
    background-color: #333399;
    border-bottom: 1px #eeeeee solid;
    height: 200px;
    width: 900px;
    padding-bottom: 20px;
    margin: auto;
     }
     
#logo       { 
    margin-left: 20px;
    margin-top: 30px ;
    padding: 0;
    float: left; 
    overflow: hidden;
    clear: both;
    vertical-align: middle;
    }
    
#logo img   {
    margin-top: 20px;
    vertical-align: middle;
    margin: auto;
    position: relative;
    width: 170px;
    height: 170px;
    }
    
#title {
    float: right;
    margin-top: 10px;
    margin-right: 155px;
    text-align: justify;
    height: 150px;
    }

#title h1 {
    line-height: 60%;
    color: #ffffff;
    text-align: center;
    font-family: Arial, Arial, Helvetica, sans-serif;
    }

#title p {
    color: #ffffff;
    text-align: center;
    font-size: 12px;
    font-family: Arial, Arial, Helvetica, sans-serif;
    }
    
#topnav {
    width: 900px;
    margin: auto;
    background-color: #333399;
    height: 40px;
    border-top: 2px white solid;
    }
    
#topnav ul { 
    margin-top: 0;
    float: left; 
    height: 40px;
    margin-bottom: 0;
    padding: 0;
    }

#topnav ul li { 
    display: inline; 
    background-color: #339999;
    }
    
#topnav ul li a { 
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    text-decoration: none;
    float:left; 
    padding: 10px 20px;
    text-align: center;
    height: 20px; 
    width: 140px;
    }
    
#topnav a:link      { color:#ffffff; }
#topnav a:visited   { color:#ffffff; }
#topnav a:active    { color:#ffffff; }
#topnav a:hover     { background-color: #0077CC; }
#topnav a:focus     { color:#ffffff; }

#subbanner {
    height: 200px;
    background-color: #2687D7; 
    width: 900px;
    margin: auto;
    padding-bottom: 5px;
    overflow: hidden;
    
    }

#subbanner h2 {
    text-align: center;
    text-decoration: none;
    color: #ffffff;
    font-family: Arial, Helvetica, sans-serif;
    }

#subbanner p { 
    margin: 0px 150px;
    font-family: Arial, Helvetica, sans-serif; 
    }
     
#dobrodosli { 
    float: left;
    margin-left: 10px;  
    margin-right: 15px;
    border-width: 5px;
    border-top-style: outset;
    border-right-style: inset;
    border-bottom-style: inset;
    border-left-style: outset;
    border-top-color: DodgerBlue;
    border-left-color: DodgerBlue;
    border-right-color: Cyan;
    border-bottom-color: Cyan;
    vertical-align: middle;
    align: middle;
    }
        
#picture1           { 
    float: right;
    margin-left: 15px;
    margin-right: 10px;
    border-width: 5px;
    border-top-style:outset;
    border-right-style:inset;
    border-bottom-style:inset;
    border-left-style: outset;
    border-top-color: cyan;
    border-left-color: cyan;
    border-right-color: DodgerBlue;
    border-bottom-color: DodgerBlue;
    }
      
 <div id="top">
        <div id="logo">
            <a href="index.html"><img src="Slike/logo2.png" /></a>
        </div>
        <div id="title">
            <h1>Zdravstvena ustanova</h1>
            <h1>stomatolo&#353;ka ambulanta</h1>
            <hr/>
            <h1>M O D E N T &nbsp; &nbsp; L O P A R E</h1>
            <p>Cara Du&#353;ana 32 A Lopare</p>
        </div>
    </div>
    <div id="topnav">
        <ul>
            <li><a href="index.html">Naslovna</a></li>
            <li><a href="about.html">O nama</a></li>
            <li><a href="team.html">Tim</a></li>
            <li><a href="galerija.html">Galerija</a></li>
            <li><a href="contact.html">Kontakt</a></li>
        </ul>

    </div>
    <div id="subbanner">
        <h2>Dobrodo&#353;li u Modent!</h2><br />
        <img id="dobrodosli" src="Slike/dobrodosli.jpg" /><img id="picture1" src="Slike/op_1.jpg" />
        <p>Zdravstvena ustanova stomatoloska ambulanta <b><i>MODENT Lopare</i></b> pocela je sa radom 03.02.2004. </p>

Answer №4

Modify the CSS code #topnav ul by setting the height to 10px.

#topnav ul { 
    margin-top: 0;
    float: left; 
    height: 40px; /*update the height to 10px for desired effect */
    padding: 0;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Positioning the comments box on Facebook platform allows users to

Need assistance, I recently integrated the Facebook comments box into my Arabic website, but I am facing an issue where the position of the box keeps moving to the left. Here is an example of my website: Could someone please suggest a solution to fix the ...

Is the Bootstrap navigation bar collapse button visible on larger screens?

How can I make my Bootstrap navbar collapse button work on big screens the same way it does on mobile devices? <nav class="navbar navbar-expand-md navbar-light bg-light"> <a class="navbar-brand" href="#">Default</a> <button ...

Utilizing Jquery's fadeIn() function to make elements appear gradually on the webpage, whether

New Question: Is there a way to smoothly transition the visibility of a div element without using display:none or CSS, as these methods remove the div from view rather than simply hiding it, causing elements below to shift? If I try setting opacity:0 or v ...

Troubleshooting Django: Issue with template extension causing static image not to be found in child template

For my personal project, I decided to learn Django. Initially, I created two separate apps, "API" and "Search". As development progressed, I merged the search functionality into the API app and updated the views accordingly. I also designed a base template ...

The whole navigation bar vanishing unexpectedly after executing a jQuery click function on a mobile-friendly website

I am in the process of designing a responsive website that features a collapsible navigation bar specifically for small screens. However, I encountered an issue where the nav bar disappears when I resize the screen to a larger size after toggling the menu ...

The navigation menu dissolves into hiding at the uppermost part of the page upon scrolling upwards on iOS devices

I am currently working on creating a navigation menu that will automatically hide when scrolling down and reappear when scrolling up. This functionality works perfectly fine on desktop and Android browsers, but I have encountered an issue specifically with ...

Issues arising from code that computes percentages

I currently have three boxes in my HTML template that are meant to calculate and display various values. The first box is calculating a score, the second box represents the total amount of points possible, and the third box is supposed to show the percenta ...

What is the best way to create a border that surrounds a collection of pictures?

I'm currently facing a challenge in getting a border to perfectly fit around a collection of images. The issue can be observed in this Jsfiddle I shared, where the border aligns with the top and left edges, but not with the bottom and right edges. Her ...

Testing the local transmission of form data via Javascript: A Step-by-Step guide

Currently studying how to send forms using JavaScript by manually creating an XMLHttpRequest. Towards the end of the provided example, there's a note: Note: If you want to send data to a third party website, keep in mind that this use of XMLHttpRequ ...

For JavaScript to run, it must be included in the HTML document and invoked externally using the <script src=...> tag

When it comes to my JavaScript code, I've encountered an interesting scenario where it only seems to run properly when it is both included in the HTML file and called externally like so: <script type="text/javascript" src="{{ url_fo ...

Guide on making a custom page by substituting specific text with user-provided input based on an existing sample page

I'm looking to create a webpage with a form <form class="col s12" method="POST" action="addtask.php"> <div class="row"> <div class="input-field col s6"> <input placeholder="Username" id="user" type="text" class="v ...

Looking for a solution to fix the VueJS calculator that only works once?

My calculator project using VueJS, HTML and CSS is almost complete. However, I'm facing an issue where it only works once. For example, if I input 6x3, it correctly gives me 18. But if I then clear the result and try to input a new calculation like 3 ...

Arrangement of a pair of elements within a single sequence

Can someone help me align the text and icons (login, shop) to be at the same level as the 'Logo,' but on the right side? I attempted to adjust the '.shop-icon' with {margin: -30px auto;}, but it ended up messing up the entire page layou ...

How can I ensure that my Overlay doesn't obstruct my dropdown content?

I'm trying to create a dropdown in my fixed navbar. When I click the open button, I want the overlay to cover everything except the dropdown content. Even after setting the z-index of my dropdown content to 10000, it still didn't work. $("#dr ...

JS will reach its stopping point at the specified style.zIndex

I am currently in the process of setting up button elements. I have two scripts that correspond to different types of buttons - one script runs a simple collapse menu, while the other executes a more complex collapse by shifting depths and sliding one div ...

Customizing Navigation Color on Laravel Websites for Staging and Live Servers

I am seeking a solution to change the color of the Laravel navigation bar depending on whether it is the live or staging server. Our current setup involves testing code on a staging server before pushing it to the live server in production via Bitbucket. ...

What's the best way to adjust the height of a textarea to completely fill the column?

Currently, I am in the process of creating a simple contact form using Bootstrap-4. The layout consists of 1 row with 2 columns: the left column contains input text fields and selection menus, while the right column includes a textarea. The challenge I&apo ...

Arrangement of words within a silhouette

I am looking to insert text into a specific shape. The parameters I have include the font, text width, text height, and margin of the text. The text is positioned within a shape with coordinates x and y. Here is an example image: https://i.sstatic.net/Mpq ...

A guide to smoothly transition box-shadow with jQuery's addClass() function

UPDATED I have a div with the class .shadow-circle-lg: <div class="shadow-circle-lg"></div> To add a different border styling to the div, I am using another class called .circle-highlight: .circle-highlight{ box-shadow: 0 0 0 1px rgba(0,0, ...

Is there a way to retrieve the id of the parent element containing the PHP code using PHP?

I need to verify if the php code being executed is located within a div named "parent2". Currently, I am customizing a Joomla HTML override and attempting to place one module in two different positions. If the module is contained within parent2, then spe ...