What is the best way to position one div above another div?

I'm struggling to move the div containing the product name, amount, price, and total to the top of its parent div. Changing the position and vertical alignment properties have not been effective. I've attached a screenshot of the page where the buttons are in the correct position, but the table needs to be at the top of the screen. This div will eventually display various products.

this is the html: 
<div class="checkout">
    
<div class="container-fluid" style="position: absolute; bottom: 0;">

<!-- Added products overview-->
<div class="checkoutTable">
    <div class="row">
        <div class="col-4">Product Name</div>
        <div class="col-2">Amount</div>
        <div class="col-3">Price</div>
        <div class="col-3 ">Total</div>
    </div>
    
    <hr style="background-color:white;">

    <div class="row">
        <div class="col-4">Product Name</div>
        <div class="col-2">Amount</div>
        <div class="col-3">Price</div>
        <div class="col-3 ">Total</div>
    </div>
</div>
  
  
 
<!-- -->

    <!-- Buttons -->
    <div class="row">
        <a class="checkoutBtn"   href="">
            <div class="col-12 checkoutBtn">
                <i class="fa fa-shopping-cart"></i>  Checkout
            </div>
        </a>
    </div>
    <div class="row">
        <a class="addDiscountBtn" href="#">
            <div class="col-6-xs addDiscountBtn">
                % Add Discount
            </div>
        </a>
        <a class="cancelBtn" href="#">
            <div class="col-6-xs cancelBtn">
                <i class="fa fa-ban"></i> Cancel
            </div>
        </a>
        </div>
    </div>
</div>

This is the css:

.checkout{
    background-color: #22303e;
    height: calc(100vh - 50px);
    color: white;
    font-size: 13px;
}
.checkoutBtn{
   background-color: #0090e3; height: 50px;
   text-align: center;
   line-height: 50px 
}

.addDiscountBtn{
    background-color:#f8ac59; height: 50px;
    text-align: center;
    line-height: 50px

}

.cancelBtn{
    background-color: #ed5565; height: 50px;
    text-align: center;
    line-height: 50px

}
a.checkoutBtn{
    width: 100%;
    color: white;
}
a.addDiscountBtn{
    width: 50%;
    color: white;
}
a.cancelBtn{
     width: 50%;
     color: white;
}

a:hover{
    text-decoration: none;
    opacity: 0.9;
}

.checkoutTable{
    vertical-align:top;
}

https://i.sstatic.net/1wOM4.png

Answer №1

It's important to avoid using inline styling with container-fluid, such as style="position: absolute; bottom: 0;"

Check out this example

<div class="checkout">

 <div class="container-fluid"></div>

Answer №2

You are positioning your div inside another div

<div class="checkoutTable">

within a parent div

<div class="container-fluid" style="position: absolute; bottom: 0;">

The style attribute "bottom: 0;" is causing the contents to stick to the bottom of the page.

<div class="checkoutTable">
    <!--content-->
</div>
<div class="container-fluid" style="position: absolute; bottom: 0;">
    <!--content-->
</div>

Answer №3

There are multiple ways to address this problem

One solution is to include the position property in your CSS like so:

.Element {
   position: absolute;
   top: 0;
}
.Element {
   position: fixed;
   top: 0;
}

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

Update the query string in the src attribute of the image tag

I'm facing a challenge with our products loading at specific sizes and quality that I need to address. I am looking to update a portion of the img src code: &wid=128&hei=144&qlt=80 to: &wid=256&hei=288&qlt=100 I have attemp ...

Issue with cancelling a file upload is not functioning properly on Internet Explorer

My experience with file uploads in Internet Explorer is causing some issues. While other browsers work smoothly when canceling file uploads, Internet Explorer seems to have a different behavior. In other browsers, clicking the "Cancel" button during a fil ...

Implementing Dynamic CSS Styles in AngularJS

Essentially, I am facing a challenge on my page where a control needs to toggle two different elements with two distinct CSS classes upon being clicked. While I have successfully managed to toggle one of the controls, the other remains unchanged. Here is ...

Transferring the AJAX response into a JavaScript variable

New to AJAX and JS here. I am implementing an AJAX code that fetches data from a php service. I am trying to figure out how to store the returned data in a JavaScript variable, which I can then display on the UI. Below is my AJAX code snippet: <script ...

AngularMaterial allows the Link to span the entire width of the sidebar

I am attempting to replicate the sidebar layout seen on https://material.angularjs.org/latest/#/. I have extracted some code from the HTML source. The issue I am facing is that the links (which act as buttons) do not span the full width (FOOBAR is being ho ...

The primary content division is trapped behind the side navigation bar

Why is my sidebar fixed on the left of the screen overlapping with the main content? I want the main content to be displayed next to the navbar and scroll up and down while keeping the nav bar in place, but no matter what styling I apply, it doesn't w ...

What is the best way to increase padding in a Vuetify view element?

I have been attempting to increase the padding of my view by utilizing the "px-5" class on the container within the view. However, I am struggling to achieve the desired amount of padding. What I am aiming for is padding similar to what is shown in this sc ...

Using float instead of CSS inline-block is more effective for styling a PHP element

I've been working on styling a page that was generated with App Gini. While I have been successful in editing most elements so far, I am facing an issue with getting inline-block to work properly. Although float:left is functioning correctly, I would ...

Is it beneficial to rotate an image before presenting it?

I am looking for a way to display a landscape image in portrait orientation within a 2-panel view without altering the original file. The challenge I am facing is that the image size is set before rotation, causing spacing issues with DOM elements. Is ther ...

Display three images with titles in a row using CSS

I'm trying to align 3 figures with captions horizontally in the middle of the page, side by side, but so far I've only been able to do it vertically. How can I achieve this using just HTML5 and CSS? This is my current HTML: <div class="r ...

The size attributes on <img> tags do not function as expected

I'm facing an issue with the following code: $("#myId").html( "<img src='" + $(xml).find("picture").text() + "' height="42" width="42"></img>" ); Everything works perfectly until I include the 'height="42" wid ...

Aligning the Bootstrap navbar to the right causes the items to shift to the left

UPDATE: The issue has been resolved. It turns out that the navbar was not extending to 100% width and reaching the edges of the screen. I am currently facing a challenge with a Bootstrap 4 navbar, similar to issues I encountered with the previous version. ...

Only reveal a single div when hovering

I am currently working on a project that involves utilizing the Wikipedia API to allow users to search for and retrieve information from Wikipedia. I have made significant progress, but I have encountered an issue. When hovering over the "each-list" div, t ...

Implementing Content-Security-Policy for a web application embedded in an iframe

Hey there! I've got this cool webapp called myApp, developed using Spring Boot and Vaadin. It's going to be deployed on a Tomcat server at http://tomcatserver:8080/myApp Now, what I want to do is display the webapp in an iframe like this: <if ...

Visualizing Data with HTML and CSS Chart Designs

I'm seeking assistance with creating an organization tree in a specific layout. https://i.sstatic.net/z9LRc.jpg I am having trouble replicating the tree structure shown in the image. I need help generating a similar tree structure where multiple le ...

What could be causing the slider element to select the incorrect value in Firefox and Internet Explorer?

Attempting to test a slider control on a webpage using Selenium, here is the HTML: <div class="slider theme1 ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all" data-action="Slider" data-step="True" da ...

Deleting sections of a string using JavaScript

I've encountered a rather unique issue where I need to address a bug on a website. The problem is that when a string is generated dynamically, it automatically adds 5 spaces before and after the string. Ideally, this should be fixed in the backend cod ...

What is the best way to target elements that have the contentEditable attribute set to true using CSS?

Can someone help me style table cells that have contentEditable set to "true"? I've tried various CSS selectors like td[contenteditable], td[contenteditable=true], and td[contenteditable="true"], but none seem to work. Is there a specific selector for ...

Guide on Deleting Specific Item Using SQL Data Source Delete Statement

I am facing an issue when trying to remove a specific item from a grid view in my SQL server database. I have configured DataKeyNames and linked a sql data source with the grid view. The delete command is set as follows: DeleteCommand="DELETE FROM product ...

Empty vertical space on the right side in iPad view

I am currently working on the development of this website and facing an issue. https://i.sstatic.net/Y7B7Q.png When switching to iPad view in Chrome's developer mode, I noticed a blank column on the extreme right side that spans the entire page. I a ...