CSS: Including an item in a list causes the <div> to expand upwards on the page instead of stretching downwards

Iā€™m currently facing an issue with my list where, upon reaching a certain number of items (in this case 5), the list starts moving up the page instead of extending downwards as expected. I suspect that this problem is related to my use of CSS grid-templates since I am still new to it. Despite my extensive search efforts, I have yet to find any solution!

Here is the code snippet in question:

What could be causing the items in my list to move upward on the page after reaching a specific number?

body {
  margin: 0;
  padding: 0;
  background: #2e112d;
}

.container {
  display: grid;
  grid-template-columns: 20% 20% 20% 20% 20%;
  grid-template-rows: 60px repeat(10, 10%);
  height: 100vh;
}

.nav-bar {
  grid-column: 1 / 6;
  grid-row: 1 / 2;
  background: #ffdbc5;
  text-align: center;
}

.brand {
  font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
  display: inline-block;
  padding: 1.5%;
}

.background-image {
  grid-row: 2 / 9;
  grid-column: 1 / -1;
  overflow: hidden;
  position: relative;
}

img {
  position: absolute;
  display: block;
  height: 100%;
  width: auto;
  margin: 0 auto;
  left: 50%;
  top: 50%;
  -webkit-transform: translateY(-50%) translateX(-50%);
}

workouts {
  grid-column: 2 / 5;
  grid-row: 2 / -1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, 1fr);
}

.new-workout {
  font-size: 200%;
  color: white;
  background: none;
  border: white 10px;
  display: inline-block;
  height: 30%;
  width: 30%;
  grid-row: 1;
  margin: auto;
  z-index: 1;
}

.workout-list {
  display: block;
  position: relative;
  align-self: start;
  grid-column: 1 / 2;
  grid-row: 3;
  z-index:1;
}


button.btn {
  color: #5a5a5a;
  background-color: #e8e8e8;
  margin: 10px 0 10px 0;
  width: 100%
}

span.delete {
  display: inline-block;
  float: right;
  color: red;
}
<div id="app">
  <div data-reactroot="" class="container">
    <div class="nav-bar"></div>
    <div class="brand">Fiery Leaf</div>
    <div class="background-image">
      <img src="/static/media/landscape-banner.67e9e794.jpg">
    </div>
    <div class="workouts">
      <button class="new-workout">New Workout</button>
      <div class="workout-list">
        <div class="workout">
          <button type="button" class="btn btn-default" />
        </div>
        <div class="workout">
          <button type="button" class="btn btn-default" />
        </div>
      </div>
    </div>
  </div>
</div>

original

original + 1

Answer ā„–1

Looks like there is an issue with your HTML code:

One of the buttons (the second one) is not closed properly, and there seems to be an extra closing div tag causing a disruption in the page layout.

Here is a link to the corrected code on jsbin.

My advice: always remember to validate your code before finalizing it.

Answer ā„–2

If you're extending a div, try adding vertical-align: top; to ensure proper alignment.

For example, changing the vertical-align property to bottom will result in the behavior you described:

.container {
  width: 100px;
  background-color: red;
  display: inline-block;
  margin: 0;
  vertical-align: top;
}

p {
  width: 90px;
  display: block;
  margin: 5px 0;
}

.other {
  margin: 0;
  background-color: blue;
  width: 40px;
  height: 50px;
  display: inline-block;
}
<div class="container">
      <p>Test</p>
      <p>Test</p>
      <p>Test</p>
      <p>Test</p>
      <p>Test</p>
      <p>Test</p>
      <p>Test</p>
</div><div class="other"></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

Utilize a single useState hook for managing the filtered results in the search list

Within the file ArticlePage.js, located in my current demonstration available here, I have implemented multiple instances of the useState() hook to render and filter the list of Posts: const [posts, setPosts] = useState([]); const [filteredPosts, setFilter ...

Is there a way to successfully transfer both the event and props together?

For simplifying my code, I created a function that triggers another desired function when the Enter key is pressed. Here's an example of how it works: const handleKeyDown = (event) => { if (event.key === 'Enter') { event.preventDefa ...

SDTT: "Please ensure that the image field has a value before continuing"

I recently added this code snippet to a LocalBusiness listing (using guidance from this resource): <div itemscope itemtype="http://schema.org/LocalBusiness"> <div itemprop="image" itemscope="" itemtype="http://schema.org/ImageObject"> ...

Design flaws occur in Bootstrap Navbar dropdowns when the screen size is reduced

I am experiencing an issue with this JS Fiddle https://jsfiddle.net/uvkt8z7j/16/ where the design gets distorted when I click on the dropdown menu while the screen is small. I want to maintain the same behavior as when the screen is large. <body styl ...

"Implementing a responsive design with a background image and radial gradient - how to

The image currently in use: https://i.stack.imgur.com/piK6l.jpg Here is how I've implemented it using Vue.js, Bootstrap, and CSS: Code Snippet <div class="landing"> <div class="container text-white details h-100"> ...

Animated CSS sidemenu (utilized as a filtering panel for a table)

Hi there, I'm having some trouble with CSS Animation. I recently started developing websites and am using Bootstrap 4 along with Animate.css for animations. My goal is to have an icon button expand sideways to reveal a div containing select elements f ...

Steps to display a variable in JavaScript on an HTML textarea

I'm working on a JavaScript variable called 'signature' var signature; //(Data is here) document.write(signature) Within my HTML document, I have the following: <div id="siggen"> <textarea id="content" cols="80" rows="10">& ...

The Calibri Light font is not supported by Chrome version 37

Yesterday my website was working fine, but today when I checked it, some strange issues appeared. The Calibri Light font that I used extensively has been replaced with the default font, and the width of input fields has changed. How can I resolve this issu ...

Reset the form value in React using Material UI components

Currently, I am working with React Material and hooks, attempting to reset a material form. However, despite my efforts to adjust the state, I am not seeing any changes reflected. <form className="create-account-form" autoComplete="off" onSubmit={onSub ...

Having trouble with Bootstrap 4 card image alignment within a tab panel

Encountering a challenge with nav-tabs nested within a card on a Bootstrap 4 webpage. My goal is to switch both the card text and the card-img-bottom simultaneously when toggling between nav-link options. To achieve this, I'm using a tab-pane that inc ...

Pressing the reset button will restore the table to its original

As a new React developer with experience mainly in hooks, I have been struggling to find a good example involving hooks. Currently, I am working on implementing an antd table with search functionality. My question is, when a user types something into the ...

Whenever I try to launch my React app using the `npm start` command in my command

After successfully creating a Simple React App and getting the happy hacking message on cmd, I encountered numerous errors when trying to run "npm start" on cmd. Despite multiple attempts at uninstalling and reinstalling node and npm, the issue persists. H ...

Understanding how to interpret and manipulate Firebase query results in a React.js environment

I am currently using firebase cloud firestore to store data and I am in the process of developing a web application with reactjs. In order to retrieve documents, I have implemented the following function: getPeoples() { let persons = []; f ...

A Guide to Configuring jQuery UI Slider with Three Distinct Colors

I'm currently implementing the UI Slider on my website. However, I would like to customize the slider with three different colors: Handle Color Previous portion of Handle Next portion of Handle I want it to look something like this: Currently, I h ...

What could be causing the p tag to be displacing the parent div downwards?

Can someone help with an issue I'm having? I have two divs that are supposed to take up half of the screen each. However, when I add a p tag inside the second div, it gets pulled down. I am working on creating an HTML email, so I can only use inline s ...

Button with improperly aligned text

I'm having an issue with two buttons where the text on one button is not centered. .mail_download_csv_btn{ width: 100px !important; font-size: 12px !important; } .margin_right_10{ margin-right:10px; } <link rel="stylesheet" href="https: ...

A bar graph fails to display on d3 visualization

I am struggling with rendering my bar graph using activity tracking data. Even though I believe my data structure is correct, the rects are not being displayed on the graph. Unfortunately, I cannot identify the mistake I might have made. The dataset is ava ...

Can you explain the variance between Next.js and Create React App?

I've been curious about understanding the distinctions between Next.js and Create React App (CRA). Both aim to simplify our lives when developing front-end applications with React. While researching online, I came across a key difference: Next.js o ...

Tips for arranging five images side-by-side in a row

I have a collection of 5 images: Image 1: Image 2: Image 3: Image 4: Image 5: The dimensions of each image are as follows: Image 1: 70x40 Image 2: 80x42 Image 3: 90x44 Image 4: 100x46 Image 5: 120x48 I would like to arrange these images ...

The UseEffect function is displaying an inappropriate value, however, it only occurs once

My goal is to display the state value whenever the password is changed using the useEffect hook in React. It's working fine for the password, but the issue arises when I try to change the email. The console also renders the email value, which is not i ...