What is the best way to position a banner image behind the navigation bar on my website?

I'm struggling to position the banner image behind the navigation bar on my website. It keeps appearing below the navigation bar, but I want it to be positioned behind the navigation bar instead.

Here is the code I'm using:

* {
  margin: 0;
  padding: 0;
}

header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 89px;
}

nav {
  overflow: hidden;
  background-color: rgba(28, 28, 28, 0.4);
  width: 1368px;
  height: 89px;
}

ul {
  display: flex;
  justify-content: space-around;
  list-style-type: none;
  margin: 0;
}

li a {
  display: inline-block;
  color: #ffffff;
  text-align: center;
  vertical-align: middle;
  padding: 37px 33px;
  text-decoration: none;
  font-family: 'Open Sans';
  font-size: 15px;
}

ul .search-container {
  margin-top: 18px;
  margin-bottom: 24px;
  padding-right: 41px;
}

::placeholder {
  font-family: 'Open Sans';
  font-size: 15px;
  color: #1c1c1c;
}

ul input[type=text] {
  width: 382px;
  height: 38px;
  border: none;
  outline: none;
  border-radius: 3px;
  font-family: 'Open Sans';
  font-size: 15px;
  color: #1c1c1c;
  background-color: #ffb606;
  background-image: url("Images/Search.png");
  background-repeat: no-repeat;
  background-position: 10px;
  padding: 14px 45px 14px 45px;
}

button {
  background-color: transparent;
  outline: none;
  border: none;
}

#CartIcon {
  padding-right: 31px;
}

#AccountIcon {
  padding-right: 44px;
}

.SpecialOffer {
  position: relative;
  overflow: hidden;
}

.background {
  position: absolute;
  width: 100%;
  height: 426.5px;
  background-image: url("Images/Banner.png");
  background-size: cover;
  background-color: center center;
  background-repeat: no-repeat;
}
<body>
  <header>
    <div class="container">
      <a href="home.html" title="Home"><img src="Images/Logo.jpg" alt="Logo" width="152 px" height="87px"></img>
      </a>
      <nav>
        <ul>
          <li><a href="home.html" title="Home">Home</a></li>
          <li><a href="#" title="Products">Products</a></li>
          <li><a href="#" title="About">About</a></li>
          <li><a href="#" title="Contact">Contact</a></li>
          <div class="search-container">
            <form action="/action_page.php">
              <input type="text" placeholder="Search..." name="search">
            </form>
          </div>
          <button type="submit"><a href = "#"><img src = "Images/Cart.png" id = "CartIcon"></a></button>
          <button type="submit"><a href = "#"><img src = "Images/Account.png" id = "AccountIcon"></a></button>
        </ul>
      </nav>
    </div>
  </header>
  <main>
    <div class="SpecialOffers">
      <div class="background">

      </div>
    </div>
  </main>
</body>

If anyone has a solution to fix this issue, it would be greatly appreciated. Thank you!

Answer №1

When using the img tag, it automatically adds a line break. To avoid this, adjust the img style to "display:inline" or inline-block. This adjustment will remove the unwanted line break.

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

Ensure that when adjusting the height of a div, the content is always pushed down without affecting the overall layout of the page

My webpage contains a div element positioned in the middle of the content, with its height being adjustable through JavaScript code. I am seeking a way to manage the scrolling behavior when the height of the div changes. Specifically, I want the content t ...

What is causing vertical-align:middle to not function in the same way as text-align:center?

Is there a reason why vertical-align:middle doesn't seem to work as easily as text-align:center? It's frustrating that it's so challenging to get it right. I'm curious why the folks at W3C haven't created something like text-alig ...

A clever way to transfer data between HTML and Java classes

I have recently built a HTML form with multiple fields for adding new items to a list. Here is a snippet of the code: <form v-on:submit.prevent="addItem" class="mt-3"> <div class="container"> <div class="input-field"> <div ...

Tips for uploading an image file from Django Admin to the HTML

If I have already used a for loop in my code, how should I write the image address if I don't want to use 'for'? Can I directly write something like '/img/1.jpg'? Here is the directory where my images are stored: https://i.sstatic ...

Learn the method of showcasing a JavaScript variable value within an HTML href tag

Currently, I am in the process of rewriting my URL and category name to be passed into the URL. For this purpose, I am creating a URL friendly string using the following JavaScript function: function getUrlFriendlyString(str) { // convert spaces to &ap ...

Can you see the visible area tag?

Is there a way to make an HTML element visible at all times, not just on focus? It seems like it should be as easy as this: HTML: <img src="image.png" width="100" height="100" usemap="#Map" /> <map name="Map" id="Map"> <area shape="circl ...

Ensure that the div is completely filled by the button and input elements

My dilemma involves filling a div element with a button and an input field. I'm struggling to set the exact width of the button, which is causing the input field to overflow the parent container. Despite many attempts with various properties, includin ...

Updating Bootstrap modal content based on button clickExplanation on how to dynamically change the content

I am looking to dynamically change the content displayed inside a modal based on the button that is clicked. For example, clicking button one will only show the div with the class 'one' while hiding the others. $('#exampleModalCenter&a ...

Android not showing scroll bar in ion-scroll feature

I am experiencing an issue where a div with a fixed height displays a scroll bar on browsers but not on an Android phone. <ion-scroll style="height:300px;" scrollbar-y='true'> //content </ion-scroll> ...

What is the best way to connect multiple web pages together?

Hello everyone, I could really use some assistance with a problem I'm facing. As a newcomer to web development, I have a question about navigation bars. I've successfully created a basic webpage with a navigation bar, but now I'm unsure how ...

Unable to include an additional parameter within a JavaScript function

I'm having trouble adding a parameter to the Openpopup() function - every time I try, I get an error. Can someone help me out with this? Thanks in advance. return "<a onclick='return Openpopup()' class='btn btn-info btn-lg clickBtn& ...

Vertical centering menu adjustment

Can anyone help me with centering an image on my website? I've tried the following code: top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); You can see what's happening on my site here: ...

Angular state correctly maps to the controller but is not reflected in the HTML

I'm currently in the process of setting up a basic Angular application, something I've done many times before. I have defined a home state and another state for a note-taking app, but I am facing an issue where neither state is displaying or inje ...

What might be causing my animation to not run as expected?

I recently tried to create a bouncing arrow following a tutorial, but the code I used is almost identical with minor differences. However, when I try to incorporate it into my hero unit, the animation does not work as expected. The issue could be related ...

How to Stop Element Flickering While Hovering in Selenium IE Webdriver

My code is functioning perfectly in Firefox, but when I try it on Internet Explorer, there is flickering. Here is my code: WebElement mouseOver= driver.findElement(By.linkText("abc")); //I'm locating the element by link text. Selenium finds the ...

Troubles arise with IE8 when using Position: fixed styling

Here is the CSS code I am using: background-color: White; border: 2px solid black; padding: 10px; position: fixed; right: 5px; top: 0; width: 250px; While this code works well in Chrome, Firefox, and Safari, I am facing issues with IE8. The position of t ...

Intersecting interactions: Mouse events on flex boxes

I am facing a challenge in my React application where I have two panels with buttons displayed using flex properties. Below is a simplified version of the HTML/SCSS code that illustrates the setup: <div class="bottom-panel left"> <butt ...

Position an element with absolute positioning to the right edge of a relative element

I have a situation where I need to align the end of a position absolute element with the end of a relative element, but the relative element's width is not fixed and may vary based on content. https://i.sstatic.net/L2sLP.jpg This scenario arises as ...

Unusual occurrence: unexpected positioning issue with iOS and Chrome (Windows)

My website looks perfect on Firefox, but unfortunately, it's not displaying correctly on Safari (iOS) and some Chrome devices. The Menu-Bar, which should be position fixed, is not showing properly. I'm not sure what the issue is. Screenshots: ...

Display the latest item using React

I've encountered a problem with displaying the last message in my pet chat application. Currently, I have to manually scroll to the bottom every time I open the chat in order to see the latest message. This scrolling behavior is not very user-friendly ...