Positioning a div at the bottom of the viewport, centered with 2 rows of 6 elements, and adjusting its size to fit the page

I've searched for answers but haven't found anything that works for me. I'm looking to have 2 rows of 6 elements at the bottom of the page and have them stick there as the page scrolls. I tried using a table, which almost worked.

.center {
  position: -webkit-sticky;
  /* Safari */
  position: sticky;
  bottom: 10px;
  margin-bottom: 10px;
  flex-shrink: 2;
  padding-bottom: 10px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee8c81819a9d9a9c8f9eaedbc0dfc0dd">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="71131e1e05020503100131445f405f42">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>

<div class="fixed-bottom center">
  <table border="1" class="center">
    <tr>
      <th>
        <h4>Val1</h4>
      </th>
      <th>
        <h4>Val2</h4>
      </th>
      <th>
        <h4>Val3</h4>
      </th>
      <th>
        <h4>Val4</h4>
      </th>
      <th>
        <h4>Val5</h4>
      </th>
      <th>
        <h4>Val6</h4>
      </th>
    </tr>
    <tr>
      <th>
        <input type="text" />
      </th>
      <th>
        <input type="text" />
      </th>
      <th>
        <input type="text" />
      </th>
      <th>
        <input type="text" />
      </th>
      <th>
        <input type="text" />
      </th>
      <th>
        <input type="text" />
      </th>
    </tr>
  </table>
</div>

If you have any tips on how I can achieve this, please let me know!

Thank you

J

Answer №1

To achieve the desired layout, there is no need for external CSS apart from the spacer that was added for demonstration purposes. It is recommended to utilize a flex-box approach to ensure elements wrap appropriately when the screen size decreases, rather than getting lost on the sides or becoming too small to be functional.

The fixed-bottom feature is functioning as intended, providing stability to the bottom section even while scrolling.

Another suggestion is to remove default padding from input fields to prevent any interference with the layout. This can be achieved by using the p-0 class on each input field.

For more details on the classes used, refer to the Bootstrap 5 documentation available at: https://getbootstrap.com/docs/5.0/getting-started/introduction/. Bootstrap 5 offers a wide range of classes catering to various design needs.

.spacer {
  height: 1000px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f3919c9c878087819283b3c6ddc2ddc0">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f99b96968d8a8d8b9889b9ccd7c8d7ca">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>

<body class="bg-dark">
  <div class="spacer">
  </div>
  <div class="fixed-bottom d-flex flex-wrap pt-2 pb-2 justify-content-center align-items-center w-100 border bg-light gap-3">
    <div class="row-sm">
      <h4>Val1</h4>
      <input class="p-0 border-dark form-control" type="text" />
    </div>
    <div class="row-sm">
      <h4>Val2</h4>
      <input class="p-0 border-dark form-control" type="text" />
    </div>
    <div class="row-sm">
      <h4>Val3</h4>
      <input class="p-0 border-dark form-control" type="text" />
    </div>
    <div class="row-sm">
      <h4>Val4</h4>
      <input class="p-0 border-dark form-control" type="text" />
    </div>
    <div class="row-sm">
      <h4>Val5</h4>
      <input class="p-0 border-dark form-control" type="text" />
    </div>
    <div class="row-sm">
      <h4>Val6</h4>
      <input class="p-0 border-dark form-control" type="text" />
    </div>
  </div>
</body>

Answer №2

  • To keep an element at the bottom of the screen, you can set the class .keepAtBottom to have a position: fixed with bottom: 0. You can also set the same value for left and right, as I have done here with 0. Feel free to adjust these values according to your specific needs, ensuring that both left and right have the same positive value.

.keepAtBottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #f5f5f5;
}
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1d3dedec5c2c5c3d0c1f1849f839f819cd3d4c5d080">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="container">
  <div class="row">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit... (continued lorem ipsum text)
      ... gravida velit quis, molestie viverra nisi. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus... (more lorem ipsum)</p>
  </div>
  <div class="row keepAtBottom">
    <div class="col-4">
      <h1>value
      </h1>
      <input type="text" class="form-control" />
    </div>
     (additional code snippet) 
  </div>
</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

What causes slow performance in Asp .Net MVC? What specific steps occur between Application_BeginRequest and the start of processing the shared view?

I have come across several questions on this platform, all with responses suggesting to "set profiling and you got answer". However, I am unable to set profiling on my destination server. What happens between Application_BeginRequest and shared view proces ...

Tips for rotating a responsive table on a mobile device's screen

I am currently managing a blogger website that features an HTML table on the homepage. I am struggling with making this table responsive for mobile devices, and I would like it to look similar to the image provided below. Can someone guide me on how to ach ...

The Reliability of Using CSS Pixel Font Sizes

Imagine I need to display two capital 'T's, each exactly one inch tall. One 'T' appears on a Macbook Pro with Retina Display (220 DPI, CSS pixel ratio 2), and the other on an iPhone 4S (326 DPI, CSS pixel ratio 2). To achieve this, I se ...

The Datatable is only displaying a single record

After fetching data from a firestore collection and storing them in an array, I encountered an issue where only one entry is displayed in the datatable despite retrieving all documents from the firestore collection. What could be causing this problem? Belo ...

Guide to changing the background colors of multiple elements when hovered over by the mouse?

I want to customize my website's search bar by changing the background color when it is hovered over. Currently, the search bar has two main elements: the text box and the submit button. I have successfully programmed the text box element to change to ...

Unable to click on hyperlink and image not adjusting in size

I am having an issue with the anchor tags inside a div. For some reason, the width and height are set to 0px, and I have tried to adjust them with no success. Each dot in my onepage scroller is meant to navigate to a different page. .dotstyle-scaleup{ f ...

How can I prevent clearQueue() from removing future queues?

In my code, I have a button that triggers the showing of a div in 500ms when clicked. After the div is shown, a shake class is added to it after another 500ms. The shake class is then removed after 2 seconds using the delay function. However, if the user c ...

Enhance the aesthetics of placeholder text in Semantic UI React using CSS styling

Currently, I am utilizing Semantic UI dropdowns within my React application to generate drop-down menus similar to the ones showcased in their documentation found here: The initial text displayed is "Select Friend", and it appears with a semi-transparent ...

Using a CSS nth-child selector to eliminate the bottom margin of the final row

As I work on creating lists that are displayed in columns of two, each .customer-review-container includes a margin-bottom CSS property like this: <div class="col-md-6"> <div class="customer-review-container"> </div> <!-- en ...

Conceal a list of items within a div that has a particular class

This is a sample of my HTML code: <div class="row"> <div class="col-md-12"> <div class="scrollbox list"> <ul class="list-unstyled"> <li id="articulate.flute">articulate flut ...

Click on a div in AngularJS to be directed to a specific URL

I'm currently working on developing an Angular mobile app and I want to be able to navigate to a specific URL, like www.google.com, when a particular div is clicked. Unfortunately, I'm still new to the world of Angular and struggling to achieve t ...

What is the best way to create a floating navigation bar that appears when I tap on an icon?

As a beginner in the realm of React, I recently explored a tutorial on creating a navigation bar. Following the guidance, I successfully implemented a sidebar-style navbar that appears when the menu icon is clicked for smaller screen sizes. To hide it, I u ...

Adjusting the size of drop-down options

I'm currently experimenting with Bootstrap and trying to create a dropdown list of country flags for language switching on a small static webpage. However, I'm facing an issue with the size of the dropdown items appearing too large. Can anyone su ...

Efficiently utilizing CSS classes

My dilemma involves styling a textfield in two different locations on my website, each with its own parent element. The second location requires an additional margin-top that the first does not. What is a clever way to adjust the original margin-top withou ...

The lengthy email exceeds its limits

https://i.sstatic.net/juD2P.png https://i.sstatic.net/WQo8o.png Take a look at this code snippet: <div className='mt-[3vh] flex h-1/3 min-h-fit w-[80%] min-w-[300px] flex-col content-center items-center justify-center rounded-2xl bg-white shadow ...

What is the most effective way to add HTML from a dynamically loaded document using AJAX?

I am attempting to attach the information from a .html file to the body of my main webpage. Essentially, I am striving to create a reusable section of html that can be loaded into any page with a basic JavaScript function. Below is the content of my navig ...

Troubleshooting: Font-Face Won't Load on Any Browser

I'm completely new to using @font-face and I'm encountering some issues. Despite going through numerous posts and tutorials, I can't seem to get my fonts to load properly. I've tried activating and deactivating the font on the server, b ...

The `tailwind.min.css` file takes precedence over `tailwind.css` in my Nuxt

Having trouble configuring Tailwind to use a custom font without it overriding the tailwind.css file and not displaying the changes? https://i.stack.imgur.com/ExDCL.png Check out my files below. // tailwind.config.js const defaultTheme = require('ta ...

Enhanced button effect: image shaded on hover

Can someone help me figure out how to make the button and image darker when hovered over? I tried something but it didn't work... Here is a demonstration: http://jsfiddle.net/h2o8w5y6/ <!--- example code snippet --> <div class="col-lg-4 ...

"Struggling with getting the text color to change on hover in Tailwind

Today has been a frustrating day as I am diving into the world of tailwindcss and have been struggling with a particular issue. My code is below: <button className="bg-yellow-500 px-4 py-2 hover:text-black text-white"> Some Text Her ...