Dynamic header feature that maintains the aspect ratio of the logo image

Currently, I'm faced with the challenge of fixing the main grid on a website that I am currently working on. My objective is to minimize the use of media queries as much as possible.

I am looking to ensure that the Logo Image maintains the height of the header without scaling down.

Similarly, I want the Timeline Header to retain the width of the Timeline while maintaining its size.

I have experimented with various solutions, but unfortunately, none have been effective for me. Could it be time to consider using JavaScript? (resize)

$(window).resize(function() {
    var windowHeight = $(window).height();
    var headerHeight = $('div#header').outerHeight(true)
    var footerHeight = $('div#footer').outerHeight(true);

    var contentHeight = windowHeight - (footerHeight + headerHeight);
    var contentMargins = $('div#content').outerHeight(true) - $('div#content').height();
    var contentInnerHeight = contentHeight - contentMargins;

    $('div#content').height(contentInnerHeight);
}).resize();

If anyone has any insights or suggestions, that would be greatly appreciated. :)

You can find a fiddle showcasing the basic grid layout here: https://jsfiddle.net/hansgohr/62xLfewa/

Additionally, the "full" version of the website can be accessed here: - where the Timeline Header seems to be functioning well.

Answer №1

If you want to maintain the height of the header image, try using 7.9vh (viewport height) as the height for both the header and the header image.

.logo-space img{
  height:7.9vh;
}

Check out this Fiddle for a live example: https://jsfiddle.net/xyz123/abc456/

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

Using CSS and Semantic UI CDN may encounter issues when testing in a localhost environment

My website's html code is structured as shown below, and the directory path is correct: <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> < ...

No firing event issue with Cordova's In App Browser on IOS

Seeking help to authenticate users on my Ionic application using an external service, and I need to utilize Cordova's InAppBrowser. The code functions correctly on Android, but on iOS, the "loadstop" event never triggers, preventing the browser from r ...

Is the initial carousel element failing to set height to 100% upon loading?

If you take a look here, upon loading the page you will notice a DIV at the top. It is labeled "content" with "content_container" wrapped around it and finally, "page" around that. Clicking the bottom left or right arrows reveals other DIVs with similar ta ...

JavaScript Array Randomizer with the Ability to Add Names to the List

I've been working on a JavaScript program lately. It's supposed to randomly select two characters from Once Upon A Time and match them up. The randomizing part is fine, but I'm struggling with the "Add Name to Array" feature. Here's my ...

What techniques can I implement to optimize the speed of this feature in JavaScript?

I have developed a feature that highlights any text within a <p> tag in red based on a user-specified keyword. The current implementation works well, but it is slow when dealing with over 1000 lines of <p>. Is there a faster way to achieve this ...

Use jQuery to create a toggle effect with unique attributes and incorporate AJAX functionality

When using this jQuery plugin for creating toggles, I encountered an issue with multiple toggles having the same IDs and classes. This made it difficult to identify a specific toggle to apply auto load ajax when the value changed. I'm wondering how I ...

Issue NG1006: Class has two conflicting decorators applied

I encountered an issue while compiling my project: PS C:\Users\hasna\Downloads\A La Marocaine git - Copie\ALaMarocaineFinal\frontend\src\app> ng serve Compiling @angular/forms : es2015 as esm2015 An unhandled exc ...

Tips for resolving the issue of 'no serverless pages built' during deployment of a Next.js application on Vercel

Recently, I've been encountering the same two errors while trying to deploy my NextJs app: // and will just error later on Error: No serverless pages were built. You can learn more about this error here I'm stuck and unsure of how to resolve bo ...

Using JavaScript to Remove Specific HTML Tags

Is there a way to remove specific tags <font style="vertical-align: inherit;"> </font> while preserving the contents with JavaScript? <div id="Box"> <h1><font style="vertical-align: inherit;"> ...

Set maximum size for background image in div

I'm facing some challenges with setting the maximum height of a background image within a div. I want the max height to be equal to the actual height of the image, without stretching it. Ideally, if there is excess content in the div, it should stop a ...

Do jQuery events get replicated?

Suppose I create a division with a button in the following way: var generateDivision = function() { // formulate division HTML... // add event $('.btn').on('click',function(e) { e.stopImmediatePropagation(); ...

Error: Attempted to export 'e', however it was not defined in the module (located at vite.js?v=d59cec13:236:3) - occurring in the three.js/vite combination

After dabbling in javascript, I decided to explore three.js and found it quite intriguing. However, after hours of setting everything up, I encountered a roadblock. When I attempted to create geometry and render it, the code stopped working. Upon investiga ...

Convert JSON data into a compressed single row format

I have a JSON file generated from PhantomJS, and it appears as follows: { "startedDateTime": "2015-04-27T12:48:47.107Z", "time": 281, "request": { "method": "GET", "url": "http://www.example.com/DE/de/shop/welcome.html;jsessio ...

Using style binding and ngStyle doesn't appear to be effective for setting a background image within a DIV element in Angular5

After facing difficulties in customizing the spacing of Angular material cards, I decided to create my own cards. However, during this process, I encountered an issue where I needed to set an image as a background inside a div. Despite trying various CSS ...

Guide to integrating a legend with ngb-timepicker form?

Is there a way to add a specific tag to the fieldset of ngb-timepicker? I'm having trouble finding a solution for this. Has anyone else tried to do this before? ...

Tips for adding event listeners to dynamically-loaded content using AJAX

I need help with the following code snippet: $("#contantainer").load("some_page.txt"); Inside some_page.txt, I have the following content: <div class="nav"> <ul id="nav_ul"> <li><a class="nav_a" href="#home" id="home"> ...

Attempting to use the getCurrentUrl() function to retrieve the current URL and subsequently opening it in a new tab

I am attempting to retrieve a URL and open it in 3 new tabs, but encountering errors in the process: browser.getCurrentUrl().then(url => { browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('t').perform(); browser.sleep ...

Is it possible for parameters to still be filled even when they start off empty

Currently, I am enrolled in a javascript course and struggling to comprehend how the parameter in my example below is populated with the "correct stuff" without actually calling the function with a corresponding element? success: function(result) { ...

Looking for a demonstration of jQuery accordion functionality

Seeking recommendations for a sleek and lightweight jQuery Accordion with CSS that is simple to set up. Preferably not using jQuery UI. Any suggestions? ...

To activate the on click event with jQuery for Ajax-generated content, you need to double click instead

When my view is loaded with ajax: <a data-name="notes" href="#" data-type="text" data-pk="{!! $v->id !!}" class="vpUpdate">{{ $v->notes}}</a> How I handle it in jQuery: $(document).on('click', '.vpUpdate', function ...