Header image misalignment

Seeking a solution to have the image fill up the remaining space in the .container class

I attempted setting the width of the image in CSS to width: 100%, but encountered two different results: Image with attribute set: https://ibb.co/9yKJgvF

If I remove the attribute, it produces this outcome: Image without attribute: https://ibb.co/K0HpkvJ

HTML

<header>
    <div class="container">
        <div id="logo_container">
            <h1>Hotel<span>Inn</span></h1>
        </div>
        <img src="../images/sample1.jpg" alt="Image of Hotel">
    </div>
</header>

CSS

header{
    width: 100%;
    height: 100px;
    display: block;
    background-color: lightblue;
}

.container{
    width: 80%;
    height: 100%;
    display: block;
    margin: 0 auto;
    background-color: white;
}

#logo_container{
    height: 100%;
    display: table;
    float: left;
}

#logo_container h1{
    display: table-cell;
    vertical-align: middle;
}

.container img{
    height: 100%;
    float: right;

Attempting to achieve an image height similar to Picture 2 while ensuring that it fills the available space until it reaches the words 'HotelInn'

Answer №1

To achieve the desired layout, it is recommended not to use float but instead opt for absolute positioning.

Ensure that you remove the float in the .img class.

Within the .container class, include the following:

position: relative;
z-index: 0;

Update the .img class as follows:

 position: absolute;
    width: 100%;
    height: 100%;
    right: 0;
    z-index: 0;

By implementing these changes, the image will stretch accordingly. It is advisable to select an image that suits this layout.

If you wish to maintain the image's aspect ratio, utilize height : auto and apply overflow : hidden in the .container class.

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

What is the best way to halt Keyframe Animation once users have logged in?

To enhance user engagement, I incorporated keyframe animation into my login icon on the website. The main objective is to capture the attention of visitors who are not registered users. However, once a user logs in, I intend for the keyframe animation to c ...

What is the process for excluding or removing an input once the PHP code has been run?

I am working on a project with a post input field where I submit simple data. <form method="post" action="result.php"> <input type="url" name="url" class="form-control" placeholder="http://example.com/"> <input type="submit" name="s ...

Choosing several buttons in typescript is a skill that every programmer must possess

I need help with selecting multiple buttons in TypeScript. The code I tried doesn't seem to be working, so how can I achieve this? var input = document.getElementById('input'); var result = document.getElementById('result'); v ...

The Bootstrap nav-link class functions perfectly in Firefox, smoothly guiding users to the appropriate section. However, it seems to be experiencing some issues

I am currently working on customizing a one-page web template and I don't have much experience with Bootstrap. The template can be found at . My issue is that the menu items are not functional in Chrome. When I click on any menu item, nothing happens ...

Enhancing WordPress Menus with Icons in PHP

Is there a way to customize the HTML output of a menu created with wp_nav_menu()? I want to include < i > tags within the link < a > of each < li > item in the menu. I understand that I could achieve this using background-images in the C ...

Trouble with updating scope values in the view within IONIC 1 and AngularJS

I recently implemented a feature to save the two most recent login details. The functionality works correctly, but I'm facing an issue where my view only updates upon refresh even though the scope values are being updated. I've tried using $scop ...

Deck.gl's StaticMap component from Mapbox fails to resize properly, causing it to overwrite other elements on the screen

I am encountering an issue while trying to integrate a basic deck.gl (mapbox static map) into a react project. Although I can successfully add the map, it ends up taking over the entire page and hides any other content that should be visible above it. Spec ...

Customizing TinyMCE's font style menu options

Our platform utilizes TinyMCE as in-place editors to allow users to make live edits to content. However, a challenge arises when using a dark background with light text, as TinyMCE defaults to using this text color rather than black. https://i.sstatic.net ...

Encountering a problem while verifying pattern using regular expressions

I'm facing an issue when manually checking if my inputs match the specified patterns. Below is the function I am using for this check: if (!$element.attr("pattern")) return true; let pattern = $element.attr("pattern"); le ...

Keeping the header fixed on a sticky div (tocbot)

While working on my website, I decided to implement a Table of Contents section using tocbot. However, I encountered an issue where the Title I added above the table doesn't stay fixed when scrolling. https://i.stack.imgur.com/vCm1K.gif Here's ...

Expand the div width to the specified measurement horizontally

Is there a way to horizontally collapse a div (container) to a specific width that I can adjust, effectively hiding its content? The collapse effect should move towards the left. <div id="container"> <button type="button" id="myButton"> ...

How can I detect a click event on an SVG element using JavaScript or jQuery?

Currently, I am developing a web application that utilizes SVG. However, I have encountered an issue: I am struggling to add a click event to each element within the SVG using jQuery. The problem arises when attempting to trigger the event; it seems like t ...

Newbie Query: How can I apply various font weights to a single font within the same stylesheet?

Twice I have inserted the font Acumin Pro Condensed, once with a weight of 400 and again with a weight of 700. I attempted to use both weights separately; assigning the 400 weight to an h3 tag and the 700 weight to an h2 tag. However, only the 700 font we ...

The function insertAdjacentHTML does not seem to be functioning properly when used with a

I am working with a parent element that contains some child elements. I create a DocumentFragment and clone certain nodes, adding them to the fragment. Then, I attempt to insert the fragment into the DOM using the insertAdjacentHTML method. Here is an ex ...

Angular error TS2531: Object may be null

Within my Component.html file, I have an input field set up like this: <input type="text" (change) = "setNewUserName($event.target.value)"/> The code within the component.ts file looks like this: import { Component } from "@ ...

Is there a distinction between em and percentage measurements and do their defaults have specified definitions?

Both em and percentage are defined in relation to other elements or properties. For example, with text-indent, it is related to the width of the paragraph, while with font size, it is related to the browser's default size. The question arises - wh ...

I am currently facing an issue with validating forms in JavaScript Document Object Model (DOM)

Whenever I click on a field and move to another one, the span tag turns red. Then, after pressing the submit button, an alert message pops up. However, if I turn the span red, fill in the field, and press the submit button, it shows success even if other f ...

Is there a way to prevent the context menu from appearing when tapping on an image on a mobile phone?

When attempting to move an image on the screen with a touch event, a popup appears in Chrome when pressing and holding the image. This popup usually includes options to save the image. Is there a way to disable this popup so I can freely move the image w ...

Generating a PDF from a CSS3 multi-column layout with the help of snappy (a wrapper for wkhtmltopdf)

I am attempting to create a PDF with three columns using barryvdh/laravel-snappy and wkhtmltopdf. Since the text that will populate these columns varies in length, I need a method that allows the text to flow freely within the columns. I have attempted to ...

Unusual spacing issue observed between <div> elements on Internet Explorer, but not on Firefox or Opera

I am facing a common question that many others may have asked before, but I haven't been able to find a solution to my specific issue. When viewing my website on FF, Opera, and IE on Windows 7, everything displays correctly. However, when using IE7 o ...