There is a space above the second div when using display inline-block

I'm encountering an issue with the display inline block property. I have two divs that I want to position next to each other, but there's a strange gap above the second div (#store_header_text) that I can't seem to explain. I've tried removing the position: absolute and relative on the surrounding divs, but it doesn't solve the problem.

Here is my HTML code:

<div id="store_header">
    <div id="store_header_logo">
        <a href="http://www.amazon.co.uk">
            <img class="store_header_img" src="/images/tiles/amazon.png" title="Amazon"></img>
        </a>
    </div>

    <div id="store_header_text">
        Amazon Coupons & Deals
    </div>
</div>

And here is my CSS:

#store_header {
    width:100%;
    border:1px solid #ccc;
    background-color:#fff;
    border-radius:3px;
    padding:5px;
}

#store_header_logo {
    height: 100px;
    width: 200px;
    position: relative;
    border:1px solid black;
    display: inline-block;
}

#store_header_logo img {
    max-height: 90px;  
    max-width: 180px; 
    top: 0;  
    bottom: 0;  
    left: 0;  
    right: 0;  
    margin: auto;  
    background: #3A6F9A; 
    position: absolute;
    border:1px solid black;
}

#store_header_text {
    height:100px;
    width:300px;
    line-height: 90px;
    padding-left:20px;
    font-size:25px;
    font-family: 'Roboto', sans-serif;  
    font-weight:400;
    color:#004d6e;
    display: inline-block;
    border:1px solid black;
}

Answer №1

Make a small adjustment to your existing code by including

vertical-align: top;

inside the #store_header_logo ID selector

Check out the code on JsFiddle

Answer №2

Modified a few elements. Swapped inline-block for primarily inline

#store_header {
  width: 100%;
  border: 1px solid #ccc;
  background-color: #fff;
  border-radius: 3px;
  padding: 5px;
}
.store_header_logo {
  height: 100px;
  width: 200px;
  position: relative;
  border: 1px solid black;
  display: inline;
}
.store_header_logo img {
  max-height: 90px;
  max-width: 180px;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  background: #3A6F9A;
  border: 1px solid black;
}
.store_header_text {
  height: 100px;
  width: 300px;
  line-height: 90px;
  padding-left: 20px;
  font-size: 25px;
  font-family: 'Roboto', sans-serif;
  font-weight: 400;
  color: #004d6e;
  display: inline;
  border: 1px solid black;
}
<div id="store_header">

  <div class="store_header_logo">

    <a href="http://www.amazon.co.uk">
      <img class="store_header_img" src="/images/tiles/amazon.png" title="Amazon"></img>
    </a>


  </div>

  <div class="store_header_text">
    Amazon Coupons & Deals
  </div>


</div>

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

Does the content='text/html; charset=gb2312' html meta tag attribute impact the GET Query String?

Here's the question: When making a standard HTTP Request to a server (non-ajax), does the Query String passed by the GET method to the server get affected by the encoding specified in this meta tag: <meta http-equiv='Content-Type' conte ...

How can a JavaScript code be used to navigate to a different HTML file within the same directory that is stored within a folder?

Here is the sample HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewpor ...

Is there a way to give only the left corners of a button a rounded look?

Here is the visual representation of the button: https://i.stack.imgur.com/Bjlkp.png ...

What is the process for inserting a hyperlink onto an image within a query slider?

I am experiencing difficulties when attempting to add hyperlinks to the images in my slider. I have come to understand that images cannot be clickable in jQuery sliders, so I have tried the following in the HTML: <div class="wrapper"> <div class= ...

How to use CSS to dynamically adjust the maximum width of an overflow container based on its children's content

I have a container with an overflowing <div> that displays multiple <ul> <li> lists. Each list always contains the same number of bordered <li> items, resembling a table. However, there may be instances where a <ul> has only ...

Using jQuery to reset the position of animated divs

I am currently working on a code that expands and centers a div when hovered upon using the following script: $(document).ready(function(){ //animation on hover $('#sliding_grid li').hover(function() { ...

Seamless scrolling experience achieved after implementing a header that appears when scrolling up

My goal is to create a header with the following functionalities: Initially displays with a transparent background Upon scrolling down the page by 25px, it will dynamically add the header--maroon class to the header, which alters the background color and ...

What is causing this issue with the basic HTML and CSS code that is preventing it from displaying correctly

What does the HTML code look like? <html> <head> <title>Homepage</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="container"></div> </body> </html> ...

Inquiries regarding jQuery's functionality and efficiency

I was wondering about the best way to improve performance? Would it be more efficient to have two images written in HTML, one visible and one hidden, and then use jQuery to toggle their display (hiding the visible one and showing the hidden one)? <img ...

Unique form validation process: utilizing JSON

Attempting to validate JSON input using Angular's FormControl. The typical approach, such as validating an email address, would involve: <form name="form"> <textarea ng-model="data.email" type="email" name="email"></textarea> &l ...

leveraging embedded jetty for developing a web-based interface

As a newcomer to web development and using embedded Jetty, I have created the source code below in Eclipse IDE. I need to programmatically start the Jetty server and cannot use the command line to do so. The web interface must be lightweight due to the li ...

What is causing the variations in line heights on this webpage?

I have recently created a test webpage, and I noticed that despite using the same CSS style, the line heights are different. This discrepancy is more prominent when viewing the page in Chrome and highlighting the usage of the .instruction class. It appears ...

Horizontal navigation bar encroaching on slideshow graphics

I'm encountering difficulties aligning the horizontal menu below the image slider. When I have just an image without the slider, the menu aligns properly (vertically), but as soon as I introduce the code for the slider, the menu moves to the top and d ...

Issue with Jekyll (seems like the stylesheet is missing?)

While attempting to fork a Jekyll theme and build the Github Page, I noticed that the generated page looks different https://i.sstatic.net/Emq3p.jpg from the original one https://i.sstatic.net/RX90P.jpg I followed the instructions to change the baseurl ...

Is there a way to include text beneath the navigation bar and other elements on the page?

I am stuck trying to add some text below my header and navigation bar. Here is the code I've been working with: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta htt ...

Troubleshooting issues with custom global components failing to apply styling in NuxtJs

I have designed various components such as buttons that I want to be able to use and reuse across my entire website. I have already developed plugins Object.entries(components).forEach((([name, component]) => { Vue.component(name, component) })) and ...

Using JQuery to load a table and inject it with html()

I am looking to populate an HTML table within a specific div element. The HTML code is being loaded using the following jQuery function: $("#table_wrapper").hide(); $.get("<?echo base_url();?>schichtplan/employee_fields/"+plan_id+"true",function(da ...

CSS is functioning properly on a local level, but fails to take effect once the "npm run build" command is executed in the React application's build

I am attempting to override the CSS of Muidrawer-paper. It works locally after running "npm start", but it does not take effect when building the package. .css-12i7wg6-MuiPaper-root-MuiDrawer-paper { position: absolute !important; top: 50px !import ...

Reset input fields while retaining placeholder text

Seeking advice on how to use this handy jQuery tool properly: $('.myDiv input').each(function () { $(this).val(""); }); Though it clears my form, I'm struggling to maintain the placeholders of the inputs. Any suggestions? C ...

Enable the feature for users to upload images to a specific folder within the Chrome extension without the need for

I need to implement a feature in my Chrome extension that allows users to upload images directly to a specific folder named "upload" without needing a submit button. <form action="/upload"> <input type="file" name="myimages" accept="image/*"> ...