Display an image overlaying a div

I am attempting to position an image outside of its parent div in such a way that it appears to be sitting on top of the div without affecting the height of the parent. However, no matter what I attempt, the image consistently gets clipped by the parent div and does not display correctly.

I have set up a jsFiddle to better illustrate the issue:

Check out the jsFiddle here

#navWrap{
    float: right; 
    overflow-x: visible;
    overflow-y: visible;
    height: 50px;
}
#navLogo{
    float: left;
}
#navLogo img{
    width: 200px;
}

Snippet below:

.gridContainer {
  width: 89.0217%;
  max-width: 1232px;
  padding-left: 0.4891%;
  padding-right: 0.4891%;
  margin: auto;
}
#navWrap {
  float: right;
  overflow-x: visible;
  overflow-y: visible;
  height: 50px;
}
#navLogo {
  float: left;
  height: 100px;
}
#navLogo img {
  width: 200px;
}
#LayoutDiv1 {
  clear: both;
  float: left;
  display: block;
  position: absolute;
  width: 400px;
  height: 400px;
  left: 50%;
  top: 45%;
  margin-left: -200px;
  /* half of the width  */
  margin-top: -50px;
  /* half of the height */
  ;
}
.menu {
  list-style-type: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  font-family: 'Archivo Black', sans-serif;
  opacity: 0.7;
}
/* Remove margins and padding from the list, and add a black background color */

ul.topnav {
  list-style-type: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  font-family: 'Archivo Black', sans-serif;
  opacity: 0.7;
}
/* Float the list items side by side */

ul.topnav li {
  float: left
}
/* Style the links inside the list items */

ul.topnav li a {
  display: inline-block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  transition: 0.3s;
  font-size: 17px;
}
/* Change background color of links on hover */

ul.topnav li a:hover {
  background-color: #269C1E;
}
/* Hide the list item that contains the link that should open and close the topnav on small screens */

ul.topnav li.icon {
  display: none;
}
<div class="menu">
  <div id="nav-anchor"></div>
  <nav class="gridContainer clearfix" id="nav">
    <div id="navWrap">
      <div id="navLogo">
        <img src="http://graphxnation.com/gxn_logo_large.png" alt="" />
      </div>
      <ul class="topnav" id="myTopnav">
        <li><a href="#home">Home</a>
        </li>
        <li><a href="about.html">About Us</a>
        </li>
        <li><a href="products.html">Products</a>
        </li>
        <li><a href="services.html">Services</a>
        </li>
      </ul>
    </div>
  </nav>
</div>

Answer №1

You have the option to precisely position the image:

  1. Specify width: 200px - matching the size of the image to navLogo

  2. Add position: absolute to navLogo img (adjust the position using left and top)

  3. Eliminate any floating elements by using overflow: hidden for navLogo, navWrap, and gridContainer. Remove it from menu

  4. Introduce position: relative to menu

Take a look at the demo below - including a section to mimic scrolling content beneath the header nav:

.gridContainer {
  width: 89.0217%;
  max-width: 1232px;
  padding-left: 0.4891%;
  padding-right: 0.4891%;
  margin: auto;
  overflow: hidden;
}
#navWrap {
  float: right;
  overflow: hidden;
  height: 50px;
}
#navLogo {
  float: left;
  height: 100px;
  width: 200px;
  overflow: hidden;
}
#navLogo img {
  width: 200px;
  position: absolute;
  left: 10px;
  top: 0;
}
#LayoutDiv1 {
  clear: both;
  float: left;
  display: block;
  position: absolute;
  width: 400px;
  height: 400px;
  left: 50%;
  top: 45%;
  margin-left: -200px;
  /* half of the width  */
  margin-top: -50px;
  /* half of the height */
  ;
}
.menu {
  list-style-type: none;
  margin: auto;
  padding: 0;
  /*overflow: hidden;*/
  background-color: #333;
  font-family: 'Archivo Black', sans-serif;
  opacity: 0.7;
  position: relative;
}
/* Remove margins and padding from the list, and add a black background color */

ul.topnav {
  list-style-type: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  font-family: 'Archivo Black', sans-serif;
  opacity: 0.7;
}
/* Float the list items side by side */

ul.topnav li {
  float: left
}
/* Style the links inside the list items */

ul.topnav li a {
  display: inline-block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  transition: 0.3s;
  font-size: 17px;
}
/* Change background color of links on hover */

ul.topnav li a:hover {
  background-color: #269C1E;
}
/* Hide the list item that contains the link that should open and close the topnav on small screens */

ul.topnav li.icon {
  display: none;
}
section {
  height: 150vh;
}
<div class="menu">
  <div id="nav-anchor"></div>
  <nav class="gridContainer clearfix" id="nav">
    <div id="navWrap">
      <div id="navLogo">
        <img src="http://graphxnation.com/gxn_logo_large.png" alt="" />
      </div>
      <ul class="topnav" id="myTopnav">
        <li><a href="#home">Home</a>
        </li>
        <li><a href="about.html">About Us</a>
        </li>
        <li><a href="products.html">Products</a>
        </li>
        <li><a href="services.html">Services</a>
        </li>
      </ul>
    </div>
  </nav>
</div>
<section></section>

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

Tips for aligning hyperlinks in the navigation bar using CSS3 and HTML5

Struggling to center the links in the navigation bar has been a challenge. I really want those buttons smack dab in the middle of the header bar, but despite trying everything, they stubbornly remain on the left-hand side. .header { overflow: ...

Can child elements be centered using their pseudo-elements using CSS alone?

Consider the code snippet below: <div class="example-container"> <p class="example">a</p> <p class="example">bbb</p> <p class="example">cc</p> </div> and the cor ...

Tips for updating text in a freshly opened window using JQuery or JavaScript

I have a function that is triggered by a button click to open a new window or tab, display an alert, and update text. Here is the code snippet: function nWin(p) { var setStyle = "<style rel='stylesheet'>\ .vTop {\ ...

The relationship between columns in MySQL is determined by the values they hold

I have 2 tables with the following structure: mysql> select * from customer; +-------+-------+ | name | code | +-------+-------+ | John | c1 | | Mary | c2 | | Sarah | c3 | +-------+-------+ mysql> select * from supplier; +-------+----- ...

Creating a dynamic Bootstrap navigation bar using PHP

I created a website using bootstrap, but now I want to add more dynamic features. The tutorial I'm following for this does not involve the use of bootstrap. Am I missing something obvious here? Could you please review my code? (To avoid overloading t ...

Photo not completing the table

Hey there, I'm currently working on creating a table to showcase some products but I am struggling with ensuring that the images display at the correct size. Any assistance on this matter would be greatly appreciated. #tbldesktops { width: 100%; ...

Issues with Internet Explorer

I am currently working on an aspx page that displays perfectly in Mozilla Firefox but looks distorted in Internet Explorer. The layout in Mozilla appears like this: <form> some stuff <div class="left"> <div class="right> </form> H ...

Triangles without their pointed tips

The left arrows next to the carousel blocks are missing their tips. I'm not sure what else needs to be added in the CSS to complete the triangle shape. Here is the live URL: (located next to the large image, specifically in the information carousel) ...

Utilize ASP to limit the application of a CSS file exclusively to the child page

My website consists of a master page and several child pages. I have created specific CSS classes for styling. However, I only want certain child pages to utilize these styles while the master page should always use them. How can I limit the access to th ...

Highlight the menu item when you reach a specific section

I am facing difficulties in creating a scrolling menu that highlights the respective item when a specific section is reached. As a beginner in design, I am struggling to achieve this effect. Any insights or guidance on how to implement this would be grea ...

How to use Vue.js to automatically redirect to a URL when a button is clicked

I have created a button that, when clicked, should redirect to a URL passed in it. Below is the code snippet: <template> <button type="button" v-on:click="gotosite(modalDetails.final.product_url)">Buy</button> </template> <s ...

Creating PDFs using Puppeteer in the presence of `link` tags

On my website, students have the ability to create their own notes using a RichText editor where the content can be quite complex. I want to provide them with an option to download these notes as a PDF file. To achieve this, I am planning to use the "puppe ...

Tips for implementing jQuery on a CSS selector's :before pseudo-element

My dilemma involves creating a div using CSS with an added X at the top-right corner using the before pseudo-class. How can I implement a function to close this div by clicking on the X with the assistance of javascript? https://i.sstatic.net/Z5uSq.png C ...

I am curious about when the CSS of my website will start impacting its search engine ranking

Initially, my perception of CSS was that it was only used for styling the appearance of a document when viewed in a browser. However, I soon came to realize that search engines also utilize CSS for indexing web pages. It is said that search engines do not ...

Tips for resolving flickering animations in CSS and JavaScript

Is it possible to dynamically set a scale and margin for an element in order to center it fluidly using the wheel event? I am aiming to achieve a smooth transition while also adjusting scroll position on the wrapping element in a fluid manner. In the prov ...

Mobile devices are unable to properly implement the Jquery show/hide feature

Currently, I am working on a small Russian project and facing some challenges with the mobile version of my website: php8098.github.io/breakfast. The issue lies within the first slider where the play button should trigger a modal window to open. I urgentl ...

Images in CSS not copied to the output directory when using Webpack

Using Webpack to bundle various javascript and css files on a website includes bundling bootstrap.css and chosen.css as part of the bundles. To achieve this, there is a main.js file serving as an entry point for importing all necessary files. The process i ...

Tips for organizing ng-repeat information according to a condition of true or false

Apologies if this question has already been addressed, but I have not been able to find a solution. I am attempting to organize an ng-repeat based on the selection of radio buttons, but I am struggling with hiding and showing items within the ng-repeat. ...

Can someone provide guidance on creating a JavaScript function that locates an image within an <li> element and sets that image as the background-image property in the li's CSS?

Let's dive deeper into this concept: <li class="whatever"> <img src="/images/clients/something.jpg"> </li> <li class="whatever"> <img src="/images/clients/whatever.png"> </li> He ...

Identifying the method of navigation using PerformanceNavigationTiming

Previously, I was able to determine if a user had arrived on the page by clicking the back button in the previous page using window.performance.navigation.type like this: if (window.performance.navigation.type === 2) { window.location.reload() } Howe ...