Whenever I insert an image into a container, I struggle to get it to be responsive

I'm facing an issue with some HTML & CSS code. When I try to add a simple header with an image and set the properties to image {height:100%; width: auto;}, it works fine. However, when the image is part of more complex code, it stops working. In the simpler code, if I change the height of the header, the image size changes accordingly. But in the second code snippet, if I change the height of the header, the image remains the same size. Could someone please explain why this is happening?

Below are two code snippets to illustrate my point.

header{
  height:80px;
  background:#eee;
}
.header-content{
  display:flex;
}
.header-content img{
  height:100%;
  width:auto;
}
.links-list{
  display:flex;
  margin-top:50px;
}
.links-list li{
  margin-right:4rem;
}
<!-- !Header -->
  <header class="header ">
    <div class="container">
      <div class="header-content">
<img src="http://www.lazarangelov.com/wp-content/uploads/2015/12/logo1.jpg" alt="">
        <div class="menu-links">
          <ul class="links-list">
            <li><a href="#">Home</a></li>
            <li><a href="#">Bio</a></li>
            <li><a href="#">Training</a></li>
            <li><a href="#">Academy</a></li>
            <li><a href="#">Gallery</a></li>
          </ul>;
       
        </div>
      </div>
    </div>
  </header>

nav{
  background:#eee;
  height:80px;
}
nav img{
  height:100%;
  width:auto;
}
<nav>
<img src="http://www.lazarangelov.com/wp-content/uploads/2015/12/logo1.jpg" alt="">
</nav>

Answer №1

To view the codepen example, please visit: https://codepen.io/anon/pen/pmEgaM

If you want to achieve the desired outcome, simply maintain the header styling with a height of 100% and adjust the height of the image in the header-content img styling accordingly.

header{
  height: 100%;  # Ensure the header's height is always 100%
  background:#eee;
}
.header-content img{
  height:100%;   # You can modify this height 
  width:auto;
}

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

The mobile website always displays phone numbers in a crisp white color on the mobile

After creating a mobile version of my Wordpress website, especially for m.mysite.com, I noticed that while the mobile site displayed the correct color (#000) for the mobile number, the actual mobile device showed it in white. Here is the code I used: < ...

Update submenu panel in jQuery Mobile version 1.4.3 following AJAX request

Hello there, I am currently in the process of developing my first JQuery Mobile website. One of the key features I have implemented is a panel for navigation. Each individual page includes the panel, along with an icon in the header that serves as the butt ...

Using XSLT to convert HTML into the desired text format

It has been almost two decades since my last encounter with XSLT. I am attempting to transform documents, like the HTML snippet below, into the desired output. <p> おばあさんは、とても <ruby><rb>喜</rb><rp>(</rp ...

Maximize the efficiency of your layout by using Flexbox to evenly distribute

I am trying to create a layout with two columns inside a bootstrap row using only CSS/flexbox and I want to achieve the design shown in this image: View Result Specifically, I want the left column's space to be distributed so that the two input field ...

Using jQuery for validation using a checkbox

I'm currently working on a registration system that allows users to choose between paying immediately with a credit card or later with a check. Depending on their choice, the fields for credit card information should either be validated or hidden to d ...

Troubleshoot: Issue with Multilevel Dropdown Menu Functionality

Check out the menu at this link: The issue lies with the dropdown functionality, which is a result of WordPress's auto-generated code. Css: .menu-tophorizontalmenu-container { margin: 18px auto 21px; overflow: hidden; width: 1005px; ...

Tips for shifting icons from the left to the right when collapsing a sidebar menu

Trying to solve a challenge with the sidebar width transition! How can I move icons to the right only when the sidebar is at a width of 50px, within the specified area? The current look: https://i.sstatic.net/GIc4n.png Desired outcome: https://i.sstati ...

Creating a hover-activated dropdown menu using only CSS

How can I create a dropdown on hover without the issue of link clicks racing against the hover effect? .dropdown:hover > .dropdown-menu { display: block; } .dropdown > .dropdown-toggle:active { /*To prevent sticky behavior on clicking*/ ...

Using the calc function to define input width may not yield the expected results

I am facing an issue where I have an input element with width: calc(100% - 100px); and no padding/margin/border. Next to this input, I want to place a div with position: inline-block; and width: 100px;. The problem is that the div is going to the next lin ...

Show a confirmation dialog box using bootbox that includes a link when the user selects OK

I am currently experimenting with integrating bootbox.js into a test page. However, I am facing an issue where the href tag in the hyperlink triggers regardless of whether the user selects the Cancel or OK button on the bootbox. Is there a way to include ...

How to implement hover effects using CSS classes for mouse enter and mouse leave functionality

I have a CSS class called "box" that I am utilizing in my project. .box { margin: 5px; padding: 5px; display: inline-block; width: 240px; height: 290px!important; background-color:#FDFEFE; text-align: center; vertical-align ...

Change when the div is shown or hidden

I'm attempting to add a transition effect when the DIV with the class .socialmenu is either shown or hidden. Below is the CSS code I've used, but it doesn't seem to be working: .socialmenu { bottom: 0; left: 0; right: 0; hei ...

Can you explain the process of gathering texts based on CSS selector?

I wanted to place texts next to the div-class as shown in the following code snippets. <div class="review-contents__text">소재가 좀 저렴해 보이지만 그래도 입으면 휠씬 나아보여요</div> Initially, I wrote a code ...

Unable to adjust the dimensions of the image

I recently added two images to my website successfully, but I am facing an issue when attempting to modify their dimensions and shape using CSS. Despite adjusting the height, width, border-radius, etc., the images remain unchanged. Can anyone provide insig ...

Is there a gsub feature available in awk for applying color to characters on unix systems

I have a script that generates an output.txt file. The script contains 4 columns shown below: Filename Date Space status xyz.txt Nov18 3.8M On_time mnp.txt Nov11 8.7M Delayed pqr.csv Nov16 9.0M No_records I automate sending the output file via email, and ...

The CSS module is disappearing before the Framer Motion exit animation finishes when the path changes

Source Code Repository: https://github.com/qcaodigital/cocktail_curations Live Site: I recently deployed my NextJS project to Netlify and everything seems to be working fine, except for one issue. Each page has an exit animation (currently set to change ...

iPhone 5s landscape mode causing issues with media query

I have been testing a media query that looks like this: @media screen and (max-width: 600px) { .blah { font-size: 1.25rem; } } When I test this in responsive mode on browser dev tools, everything looks great. I can see all the changes as I resize ...

Is it feasible to execute exe files within a ReactJS environment?

Hey there! I've created a Game Launcher using ReactJS for my Unity game and was wondering if it's feasible to start the game (an exe file) simply by clicking on the play button. Can anyone please advise me on this? ...

JQuery Validity Customization

I recently came across tutorials demonstrating how to set custom errors for a form's input fields using JavaScript. One example is shown below: document.getElementById('fname').setCustomValidity('Invalid'); However, when I atte ...

Switching up the size of individual components in the Bootstrap grid system: The ultimate guide

Is it possible to adjust the width of specific elements in Bootstrap's grid system without affecting the default customization? Here is an example of what I am referring to: For example, I would like to make col-xs-1 smaller as seen in the top row ( ...