Tips for creating a header image that adjusts to different screen sizes

The banner image on my website adjusts to smaller screen sizes, but doesn't adapt when the screen size increases.

Link: Removed

If you shrink the screen, refresh, and then expand it again, you'll notice that the bottom of the image gets cut off with a black space filling the gap.

HTML:

<div class="intro">
    <div class="intro-inner">
        <div class="intro-bg">
            <div class="intro-bg-item"> 
                <div class="intro-bg-item-image" style="background-image: url(css/images/pb/home-banner.jpg)"></div><!-- /.intro-bg-item-image -->
            </div><!-- /.intro-bg-item -->
            
        </div><!-- /.intro-bg -->
    </div><!-- /.intro-inner -->
</div><!-- /.intro -->

CSS:

.intro { position: relative; text-align: center; color: #fff; background-color: #000; max-height: 100vh; overflow: hidden;}
.intro-inner { position: absolute; bottom: 0; top: 0; left: 0; right: 0; }
.intro:after { content: ''; display: block; padding-top: 45%; }
.intro:before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: linear-gradient(rgba(0, 0, 0, .5), rgba(0, 0, 0, 0) 40%); z-index: 3; }

.intro-bg { position: fixed !important; height: 100% !important; }

Answer №1

When utilizing bootstrap, make sure to incorporate the "img-responsive" class for your logo and customize the logo width by implementing media queries tailored to different screen sizes.

Answer №2

The issue persisted specifically when accessing the website from a mobile device. To address this, I implemented a creative yet imperfect solution by adjusting the image height to match the screen width when the display size is smaller than that of a laptop.

CSS:

@media only screen and (max-device-width: 1024px) and (orientation: landscape) {
  .intro-bg {
    height: 100vw !important;
  }
}

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 maintaining grid width when columns are rearranged in the column menu

Is it possible to stop jqgrid from changing its width to full screen after column selection? I attempted the code below, following guidance from How to change column name in column chooser pop up in jqgrid? My aim was to create a column switcher function ...

What is the correct way to update an empty object within the state using setState?

I'm currently dealing with a state that looks like this: this.state={ angles:{} } I need to know how to use setState on this empty object. Specifically, if I want to add a key and value inside my empty 'angles'. How can I achieve that? Fo ...

What are the disadvantages of using getBoundingClientRect() in ReactJS?

I recently incorporated the getBoundingClientRect() method into my project. However, a fellow React developer expressed concerns about its browser compatibility. In theory, shouldn't Webpack or Babel handle such compatibility issues? ...

Using javascript, retrieve the JSON values for each level

I need help using a recursive function in JavaScript to retrieve the last key value pair from a simple JSON object. Here is an example JSON object: { 'a': { 'b': { 'c': 12, 'd': 'Hello World& ...

Exploring CryptoJS in a Vue.js project

https://github.com/brix/crypto-js I successfully installed CryptoJS using npm i crypto-js. However, I am facing difficulty in integrating it into my project. When I attempt to use the following code: // Decrypt var bytes = CryptoJS.AES.decrypt(cipher ...

What is the best way to format this information within a JSON document?

I am looking to incorporate a Json file containing data into my HTML document in order to use it for creating a dynamic select option form. For instance, if the initial select option asks whether you are a man or a woman and provides the choices of man an ...

Why is there a blank white space under my image in Safari?

I am struggling to understand why Safari is adding a white space at the bottom of the image on my current website project. Interestingly, Firefox and Chrome display it correctly. The image should stay fixed at the bottom of the page even when resized. He ...

What is the best way to change an int32 to a float32 in Deeplearn.js?

In December 2017, this code did the job perfectly. However, after updating Deeplearn.js to the latest version, it no longer functions as expected: math.scope(function(keep, track) { var i = track(dl.Array3D.fromPixels(rawImageData, 4)); i = math.multi ...

Custom AngularJS menu directive using a JSON file to generate submenus

As a newcomer to angularJs, I am looking to create a dynamic menu with submenus using a .json file. It's important for me to be able to easily add new menus and submenus through the same .json document. <a href="#" ng-repeat="item in menuHeader"&g ...

Inconsistency in @nuxtjs/i18n locales after refreshing the page

I am currently working on an application where I am implementing language management, but I have encountered a difficulty. I am using the latest version of @nuxtjs/i18n. Changing the language successfully updates the URL and labels, yet upon refreshing the ...

Inaccurate window dimensions on iOS Chrome are causing issues with innerWidth and inner

After rotating my iOS device, Google Chrome version 104 seems to be reporting incorrect values for window.innerWidth and window.innerHeight. The discrepancy is noticeable when comparing the dimensions before and after rotation: Initially in portrait mode: ...

Is it possible to utilize filter in place of forEach in Javascript?

Is there a way to refactor the function below that currently uses forEach to instead use filter? I've searched online but couldn't find a suitable solution. pendingPaymentsUtils.getPendingPayment = paymentId => { const payments = pendingPay ...

Guide to automating email communication through server-side programming

Are there any resources available for sending automated birthday e-mails to clients? I have experience with SMTP in iOS development, but I am now looking for a solution using JS or .NET (or possibly HTML). It seems like this functionality would require s ...

Leveraging SVG filters for enhancing text with unique borders

I recently discovered a helpful tip on adding a background to text in SVG using a source. However, I am still unsure how to incorporate a border around the text. <svg width="100%" height="100%"> <defs> <filter x="0" y="0" width="1" ...

Two adjacent divs positioned next to each other, where the right-hand div occupies the remaining space within its

I am facing a common issue with two side-by-side divs, which I usually solve without any problems by floating both divs left and adding a clear:both div after them. However, my requirements have made this problem more complicated to solve... What I would ...

Determine the data attribute values of all checkboxes using jQuery and store them in a string

I am faced with a challenge involving a series of checkboxes that are structured like this: <input type="checkbox" class="pcb" value="1" data-id="99"> <input type="checkbox" class="pcb" value="2" data-id="98"> <input type="checkbox" class=" ...

Error: Unable to access the 'login' property of an undefined object

An error occurred: Uncaught TypeError: Cannot read property 'login' of undefined........... import Login from '../components/Login.jsx'; import { useDeps, composeWithTracker, composeAll } from 'mantra-core'; export const com ...

What is the best way to create distance between my buttons?

Can anyone help me with an issue I'm facing where adding margin to my buttons is causing the last button to jump down a row? I have an idea of what might be happening but I'm unsure how to solve it. Below is the CSS code for the buttons, any sugg ...

Leveraging jQuery plugins within an AngularJs application

I am currently trying to implement the tinyColorPicker plugin from here in my Angular app, but I am facing difficulties with it. An error message keeps appearing: TypeError: element.colorPicker is not a function In my index.html file, I have included th ...

Troubleshooting problems with image display following jQuery animation

Check out this awesome page I found: where you can see a neat list of blog posts displayed in rows of 4. I've added a cool jQuery animation to the 'cards' so that they fade in one by one: jQuery('.fade-in-post-container .elementor-po ...