Incorrect behavior of responsive background images

For the first time, I am working on a school project that requires me to create a responsive website. I am following the "mobile first" approach. On stackoverflow, I came across a helpful way of making background images responsive:

background-image: url(./assets/img/bg-blue-sm.png);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;

However, the images are behaving strangely when I increase the screen size. How can I resolve this issue? You can observe the behavior here: https://i.sstatic.net/qVk9T.jpg

.container {
  display: inline-block;
  cursor: pointer;
  background-color: var(--beige);
  border-radius: 100%;
  padding: 2rem;
}

.bar1,
.bar2,
.bar3 {
  width: 35px;
  height: 5px;
  background-color: var(--pink);
  margin: 6px 0;
  transition: .4s;
  border-radius: 1rem;
}

.change .bar1 {
  -webkit-transform: rotate(-45deg) translate(-9px, 6px);
  transform: rotate(-45deg) translate(-9px, 6px);
}

.change .bar2 {
  opacity: 0;
}

.change .bar3 {
  -webkit-transform: rotate(45deg) translate(-8px, -8px);
  transform: rotate(45deg) translate(-8px, -8px);
}

.navigatie {
  text-transform: uppercase;
  font-family: 'Abrade Heavy';
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-image: url(./assets/img/nav-sm.png);
  background-repeat: no-repeat;

  background-size: cover;
  background-position: center;

  padding: 1rem .5rem;
}

.navigatie li:nth-child(2) {
  margin-top: -2rem;
}

a {
  text-decoration: none;
  list-style: none;
  color: var(--beige);
}

.header {
  background-image: url(./assets/img/header-bg-sm.png);
  background-repeat: no-repeat;

  background-size: cover;
  background-position: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 40rem;
  padding-top: 8rem;
  margin-top: -7rem;
}

.hide {
  display: none;
}

.date {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-left: 10rem;
  margin-top: 2rem;
}

.date-txt {
  font-family: 'Abrade Heavy';
  text-transform: uppercase;
  color: #b3b3b3;
  font-size: 1.5rem;
  margin: 0;
}

.intro-article {
  background-image: url(./assets/img/bg-blue-sm.png);
  background-repeat: no-repeat;

  background-size: cover;
  background-position: center;
  height: 40rem;
  margin-top: -11rem;
  padding-top: 8rem;
}
<header>
            <ul class="navigatie">
              <li><a href=""><img src="./assets/img/logo-sm.png" alt=""></a></li>
              <li><a href="">programmatie</a></li>
              <li>
                  <div class="container" onclick="myFunction(this)">
                      <div class="bar1"></div>
                      <div class="bar2"></div>
                      <div class="bar3"></div>
                    </div>
              </li>
            </ul>

              <div class="header">
                  <h1 class="hide">INTERNATIONAAL STRAATTHEATER</h1>
                  <img src="./assets/img/titel.png" alt="IBS header background">

                  <div class="date">
                      <p class="date-txt">alle ogen gericht op</p>
                      <img src="./assets/img/datums-sm.png" alt="VRIJ 24/08 ZAT 25/08 ZO 26/08">
                  </div>
              </div>
          </header>

          <main>
            <article class="intro-article">
              <h2 class="hide">een wereld vol fantasie</h2>
              <img src="./assets/img/wereld-sm.png" alt="Een wereld vol fantasie">
              <p class="intro-txt">Een arsenaal aan gekke wezens of vriendelijke gastheren nodigen u nu al uit op een weekend vol verwondering en bewondering. Een combinatie van walking acts en tentoonstellingen zorgen voor een onvergetelijke ervaring.</p>
            </article>
          </main>

Answer №1

That's just how the cover feature operates.

The cover command instructs the browser to ensure that the image completely covers the container, even if it means stretching or slightly cropping the edges. - CSS Tricks

When you widen your screen, the image attempts to cover the entire width by sacrificing some of its height.

Refer to the link I shared to explore other options for the background-size property and choose the one that best fits your requirements.

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

Exploring the GitHub Repository API with React

I am currently developing a feature that allows users to enter a username and view all the github repositories for that user in a separate react component within a repolist component. Although I can retrieve the JSON data for all the repos, I am facing is ...

Regex pattern to replace the zero preceding two times within a string based on distinct criteria

I need to transform the string XY4PQ43 using regex in JavaScript. The output should be XY04PQ0043. Specifically, I want to add a zero prefix to the first number if it is a single digit to ensure it has 2 digits, and for the second number in the string, I w ...

Substitute empty spaces and organize the text layout

I'm struggling to figure out how to substitute the whiteSpace in an aggregate request using MongoDB and also how to remove a specific part of a string (most likely requiring regex). Here's an example of my document: { "_id": "57dfa5c9xxd76b ...

Shifting gradient hues for illustrations?

One technique I have mastered is creating dynamic gradient colors for text elements using the following CSS: a { &:hover { background: linear-gradient(-45deg, green, yellow, red, blue); background-size: 200% 200%; animation: gradient-movi ...

Initiate gapi.auth2 upon VueJs initialization

I am currently developing a Vue.js web application that allows users to connect with their Google accounts. The login process, both front-end and back-end, is functioning properly: the Google sign-in button is displayed, the user clicks on it, and their a ...

Enforcing object keys in Typescript based on object values

I'm looking to design a structure where the keys of an object are based on values from other parts of the object. For example: type AreaChartData = { xAxis: string; yAxis: string; data: { [Key in AreaChartData['xAxis'] | AreaChart ...

What is the best way to create a case-insensitive search feature in Node.js?

I have implemented a search function that takes input from the client as Str. If it matches with content in a file, I send that response. For example, if I have text in a file labeled Lorem, and the client searches for lorem, it returns an empty array due ...

Instructions on how to add an ExternalLink to a webpage linking back to the previous page

I'm in the process of creating an error page for my app, and I'm trying to figure out how to add a Wicket ExternalLink that takes users back to the previous page. I believe I need to store the parameters or entire URL of the last visited page, b ...

The issue with using the jQuery blur() event on a Div element

I am facing an issue with hiding specific popups that are based on divs. When I click outside those divs, they do not hide. Here is a sample code of what I am currently attempting: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

Having trouble getting your Raspberry Pi web server to display the background image?

Recently, I successfully set up a LAMP server on my raspberrypi which was quite exciting. One of the first things I did was configure an FTP server to transfer webpage files to the Pi. I managed to create a basic form of the final webpage and transferred i ...

What steps should I take to ensure that flex aligns the inner-divs on the same row?

I have observed that flex can easily align input tags, regular text, and other elements perfectly on a single line with the flex-direction:row; property. However, this alignment seems to get disrupted when one of the elements is a div. For example: <ht ...

What is the best method for modifying an array variable?

I am working with a variable array named data for my IGcombobox datasource. I need to update the array when I click on my #select element, but the current code is not changing the variable. Is there a way to achieve this without using PHP? <div id="c ...

Using JSON data to populate a select menu in AngularJS using the ng-options directive

UPDATE: I have successfully resolved my issue. Thanks for the assistance, everyone. I am working with an array of JSON objects that are structured like so: [{"id":"id1", "text":"text1"}, {"id":"id2", "text":"text2"},....] My goal is to populate an Angul ...

Improving my 'Adaptive' layout

Check out my website at kylesethgray.com. I've created a 'somewhat responsive design', but there are two issues that need fixing: Whenever I have a list, whether it's an <ul> or <ol>, the bullets get cut off when the bro ...

What is the best method to invoke a function recursively with a delay of 1 second following the completion of an ajax

I am facing a situation where I need to implement a delay of 1 second after an ajax request is completed, regardless of the outcome. Instead of calling a method every second, I specifically want to call a function 1 second after the ajax request finishes. ...

How does Node.js contribute to the MEAN stack ecosystem alongside JavaScript and Express, in contrast to Django and Python?

Having experience in developing web applications with Python, Django, and PostgreSQL, I have now shifted my focus to JavaScript and the benefits of the MEAN stack. MongoDB serves as the database for MEAN, similar to how PostgreSQL is used with Python. Expr ...

Associating functions with events within objects

I am encountering a unique issue with jQuery and JavaScript in general. Currently, I am developing a JS file that allows me to create portlets for a client's website. I am utilizing SignalR to send updates to the users. The code snippet below is cau ...

Is there a way to determine if JavaScript is responsible for triggering the update on my update panel?

To ensure that the update panel with a user control in it only fires after the page has fully loaded, I have implemented the following javascript code: <script type="text/javascript"> function pageLoad(objSender, args) { Sys.WebF ...

Adjust the CSS property dynamically based on the quantity of items within a div container

Can CSS3 be used to style the children divs of a parent div with specific conditions, such as: If there are 3 divs, apply property x to divs 1 and 2. If there are 2 divs, apply property x to div 1. If there is 1 div, do not apply property x to it. Is jQ ...

Effective ways to transmit a variable array from an HTML document to a PHP server

Is there a better method for transferring a variable array from HTML to PHP? I attempted to use the serialize function, but it doesn't seem to be functioning correctly. Any suggestions would be greatly appreciated. //HTML var arrayTextAreasNames = [ ...