The background image remains the same size even as the webpage dimensions grow

I am facing an issue with two columns on my website - the left column has a background image while the right one contains text. The right column also has a button that reveals more text when clicked. However, after clicking the button, the image in the left column does not resize and leaves white space at the bottom. How can I ensure that the left column's image always fills the full height?

Code provided below:

$(document).ready(function() {
     $("#show_hide").click(function () {
     $("#toggle_tst").toggle()
  });
  });
.left {
  width:50%;
  float:left;
  background:grey;
  height:100vh;
  background-image:url(https://coolbackgrounds.io/images/backgrounds/index/sea-edge-79ab30e2.png);
}

.right {
  width:50%;
  float:right;
  min-height: 100vh;
}

#toggle_tst {
  display:none;
  }

.more {
height: 500px;
display: block;
clear:both;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="left">

</div>
<div class="right">

Some text here

<button id="show_hide">Show/Hide div</button> 
   <div id="toggle_tst">
     The div element with some text.
     Additional Lorem Ipsum content...
   </div>

</div>

<div class="more">
Another section would go here
</div>

Answer №1

The issue with the background image not expanding is due to the .left element not expanding. To solve this, you can create a parent container with flex so that the children will grow to match their heights.

Additionally, make sure to change the CSS from height: 100vh to min-height: 100vh to ensure it expands beyond that point.

$(document).ready(function() {
  $("#show_hide").click(function() {
    $("#toggle_tst").toggle()
  });
});
.wrapper {
    display: flex;
    flex-direction: row;
}

.left {
  width: 50%;
  float: left;
  background: grey;
  min-height: 100vh;
  background-image: url(https://coolbackgrounds.io/images/backgrounds/index/sea-edge-79ab30e2.png);
}

.right {
  width: 50%;
  float: right;
  min-height: 100vh;
}

#toggle_tst {
  display: none;
}

.more {
  height: 500px;
  display: block;
  clear: both;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="wrapper">
  <div class="left">

  </div>
  <div class="right">

    Some text here

    <button id="show_hide">Show/Hide div</button>
    <div id="toggle_tst">
      The div element with some text...
      
    </div>

  </div>
</div>

<div class="more">
  Another section would go here
</div>

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

"Retrieving a unique identifier from a child page by using the href attribute in the parent page

Is it possible to load a specific ID from a child page and display that content in a dialog on the parent page when a link is clicked? I want to load the DIV ID "medical" when the medical link is clicked, and I am looking for a way to add a selector in the ...

Angular Space-Friendly Table

After attempting to code the sample in Angular, I realized it wasn't what I was looking for. <table> <th >Number</th> <th >Merchant Name</th> ...

Conceal list item using Jquery on the beginning of a new month

As someone with experience in CSS rather than programming, I find jQuery a bit challenging. However, I am trying to achieve a specific task and could use some help. I have an unordered list (UL) with one list item (li) representing each month. My goal is t ...

Retrieving JSON data and transforming it into HTML

After reading several examples, I am still struggling with a particular issue. I am receiving a feed from an API that is structured like this: { total:123, id: "1234", results: [ { id: "1234", name: "bobs market", ...

Is it possible to utilize a tracking pixel (invisible GIF) as a background image within a stylesheet?

I'm curious to know if adding a tracking pixel (a transparent GIF with server logging) as a background-image in a linked stylesheet will have the same impact as if it were a regular <img> on a webpage. After conducting a quick test using Chrome ...

Tips for detecting a false return value from a jQuery AJAX script

I am currently utilizing jQuery and AJAX to perform form validation when a new user is being created on my website. My development environment consists of OOP PHP in conjunction with jQuery and AJAX. Here is the code snippet I am using: $.ajax({ ...

Is there a way to bring together scrolling effects and mouse movement for a dynamic user

If you want to see a scrolling effect, check out this link here. For another animation on mouse move, click on this link(here). Combining both the scrolling effect and the image movement might seem challenging due to different styles used in each templat ...

How to center elements vertically within a div using CSS

I am trying to align the contents vertically in a div, but the first div does not seem to be centered like the second one. I need both of them, along with their children, to be vertically centered inside the div. For example: [type='file'] { b ...

How to Use Javascript to Listen for Events on a Different Web Page

Is it possible to open a popup using window.open and then subscribe to page events (such as onload) of the popup from the opener? I am looking for a method in my parent page (opener) that will execute when the popup's onload or ready event fires. Can ...

The HTML Style for implementing HighChart title text does not work when exporting files

I have inserted the <br/> and &nbsp; HTML tags into the HighChart titles. The style changes successfully appear in the chart view, but unfortunately, when exported as PNG or JPEG images, the text style fails to apply in the resulting images. To s ...

Instead of displaying a regular text box, the output unexpectedly shows "Printing [object HTML

There are some HTML and JavaScript files that I have. I've written some functions in my JavaScript file to save the values of different input fields. However, when I try to print the description, it just displays [object HTMLInputElement]. This mak ...

Transform JSON data into an HTML table using PHP

My goal is to dynamically convert a JSON array into an HTML table using PHP. The challenge lies in the fact that this data can vary with each request, meaning the JSON may contain different arrays and/or different associated names. For example, I have two ...

Difficulties encountered when trying to store a checkbox array data into a database

Within my application, I am faced with the task of extracting checkbox items from a list and storing them in my database. Currently, I am assembling these items into an array by iterating through the options, adding a checkbox before each one, and assignin ...

Attempting to achieve the simultaneous display of an image overlay and image zoom when hovering over the mouse

I'm struggling to display an image overlay and image zoom simultaneously when hovering the mouse. After adding the image zoom effect, the overlay disappears. It seems like one transition is overriding the other. Whenever the zoom works, the overlay do ...

Unable to drag and drop functionality is not functioning properly in Android Emulator with Html and jQuery

As a newcomer to Android, I have successfully created a project in HTML that runs perfectly as intended. However, when trying to run this HTML project on an Android emulator, I encountered an issue with drag and drop functionality not working. I utilized ...

The JavaScript for loop using .appendChild() is inserting the values of the final object, represented as [object object], into the HTML document

$(document).ready(function () { GetDetails(); }); function GetDetails() { let albumlist = document.getElementById("album-list"); $.ajax({ url: '/Store/browseajax', type: 'GET', data: { id: '@ ...

I'm struggling to understand why the jQuery find() method isn't functioning as expected

UPDATE: In a twist of events not caused by syntax errors, but rather by a loading issue with the html template, it turns out that the checkbox update was happening prematurely. So if you're searching for an element that seems to be missing, it may sim ...

Dropdown with multiple selections organized in a hierarchical structure

I am in need of the following : Implement a drop-down menu that reflects hierarchical parent-child relationships. Include a checkbox for each node to allow for selection. If all child nodes are selected, their parent node should be automatically ch ...

Is there a way to retrieve the ID by using the autocomplete feature to search for a user's first name and last name in PHP

Check out this code from index.php (all credit to the original owner): <HTML> <HEAD> <TITLE> Ajax php Auto Suggest </TITLE> <link href="css/style.css" rel="stylesheet" type="text/css"> <SCRIPT LANGUAGE="JavaScript ...

Troubleshooting Issue: jQuery Scroll Feature Unresponsive

I'm having an issue with my website where it's not scrolling down when I click on an arrow. You can see the site here. Despite trying on different divs, nothing happens when I click. I've also tested it on other sections with no success. & ...