What is the best way to position my unsorted list at the bottom of a predefined (a px * b px) container?

When looking at my existing code, I noticed that the ul is positioned all the way at the bottom of the page, extending past the predefined box.

I attempted to resolve this issue by using the CSS properties position:fixed and bottom:0

.box {
    width: 900px;
    height: 450px;
}
.box ul {
    list-style: none;
    text-align: center;
    position: fixed;
    bottom: 0;
}

.box li {
    display: inline-block;
}

.box a{
    text-decoration: none;
    color: blue;
    width: 150px;
    display: block;
}

My expectation was for the ul to be aligned with the bottom of the box initially and then adjust its placement slightly by adding padding or margin, so it doesn't sit directly at the very bottom of the box.

Answer №1

When using the CSS property position: fixed;, the element is positioned relative to the entire viewport, as opposed to position: absolute; which is positioned relative to its parent element. To adjust the positioning of your elements accordingly, consider adding position: relative; to the .box class and changing fixed to absolute within the .box ul styling.

Answer №2

Absolutely, using absolute positioning is the way to go. Have a look at this solution:

.container {
    width: 900px;
    height: 450px;
    position: relative;
}

.container ul {
    list-style: none;
    text-align: center;
    position: absolute;
    bottom: 0;
}

.container li {
    display: inline-block;
}

.container a{
    text-decoration: none;
    color: blue;
    width: 150px;
    display: block;
}

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

Adjusting CSS styling based on screen orientation changes when resizing a browser window on a

I'm uncertain about the functionality on desktop screens when it comes to resizing the browser window. My understanding is that changing the orientation should occur naturally when the height surpasses the width and vice versa after resizing. However ...

Tips for creating line breaks in Google Chart tooltips

I'm having trouble breaking a line in the code snippet below. Here is the complete code: <html> <head> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script ...

A guide on effortlessly reducing a flying draggable popup using jQuery

I have created a pop-up window that appears on the viewport as you scroll, and it can also be dragged around. You can see the code snippet below: var jq = jQuery.noConflict(); var $el = jq(".Box"); var $btnmini = jq(".sessionCD #btnmin"); var isMini = ...

By setting the overflow-x property to hidden on my container, I have inadvertently disabled the sticky positioning

How can I make an element sticky when scrolling and hide horizontal scroll on mobile? I'm having trouble with horizontal scrolling on iPhone. Can you help me troubleshoot this issue? Thank you. .sticky-sidebar { position: -webkit-sticky; posit ...

Retrieve the content of an element within a freshly launched window

I am looking to utilize JavaScript to open an html file and input some data into specific elements. My attempt so far has been: var info_window = window.open('info_print.html') info_window.document.getElementById('new_info').innerHTML ...

Stacked on top of one another are in-line block items

I've been working on this code for a while now, but I can't seem to get it right. My goal is to create a horizontal line of navigation links with the first link aligned to the left and the rest following in sequence like a text line. However, a ...

What could be causing the lag in the animation on my mobile device?

I created a CSS animation that runs smoothly on my computer, but I noticed some jerkiness when testing it on my smartphone. Can someone explain why this is happening and suggest ways to fix it? I would like the animation to work on mobile devices as well ...

When attempting to call a function after an unsuccessful AJAX load, the Jquery

Our catalog results page includes an external JavaScript file that utilizes AJAX - I have a jQuery function designed to change the color of a span when it detects specific text. You can view the code below: function ReInitStockColor(){ $(function() { ...

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 ...

The edge is showcasing a .jpg image in the form of a square randomly colored

I've encountered a new issue recently that seems to be related to a browser bug in Edge. I'm facing difficulties with .jpg images not displaying properly in Edge, although they show up fine in IE, Chrome, and Firefox. Instead of the images, all I ...

Calculate the total sum using the footerCallback function

I've written some code that retrieves data for the tbody of a table. Now, I want to add a tfoot to display the sum of the last column, and here's how I'm attempting to do it: var data = [ {Id: "1", Quantidade: "14", Preco: "3.10", }, ...

Maintaining the proportions of divs containing background images

I'm dealing with a background image that features a large blue diagonal line where we want our content to align. However, I'm encountering difficulties in maintaining the alignment of the content as it resizes (resulting in the background diagon ...

Looking to switch up the thumbs-up button design?

I am a beginner in using jquery and ajax, and I need some assistance. How can I incorporate this jquery code into my logic: $('.btn-likes').on('click', function() { $(this).toggleClass('liked'); }); Can so ...

Uneven gaps in the process of creating a CSV document

I need to extract raw text data from a website using screen-scraping, format it, and then export it to a CSV file. The raw data is correctly formatted, but the line breaks are not being preserved. Servicing Option: Retained/CTOS,,,Servicing Fee Rate: 0.25 ...

Is there a way to nest my form within another form and utilize just one submit button for both?

<form action="<?php $self ?>" method="post"> <h2>LundaBlogg</h2> <div class="fname"><label for="name"><p>Namn:</p></label><input name="name" type="text" cols="20" onkeyup="En ...

Each webpage features a distinct background image, each selected through the use of the div tag

I'm currently developing a multi-page application where I load mainpage.html into index.html using tag. I need to have a different background image for each HTML page, such as mainpage, page1, page2, etc. Can anyone help me with this? index.html & ...

Learn how to effortlessly move a div element by dragging and dropping it into four different div containers with the help of jQuery. Additionally, after dropping the div into the first container, seamlessly drag it into the next div

Is there a way to use jQuery to drag a div and drop it into four different divs sequentially? For example, once the div is dropped into the first div, it should automatically be dragged to the next div. <div id="dragdiv"> </div> <div id ...

Unable to conceal HTML5 video in mobile devices through media query

I've been struggling to find a solution for hiding a video on mobile devices. Despite going through numerous posts and attempting different methods, I haven't been successful in using @media queries to hide the video and show an image instead. He ...

Ways to retrieve various data elements from ajax using PHP

Can you help me with my AJAX code that retrieves data from a PHP script? I want to know how to set multiple echo variables in PHP and display them separately using AJAX without reloading the page. AJAX Code $(document).ready(function() { //el ...

Incorporate text into the URL of the image

Got a URL of an image like this: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg', and looking to add 240x240 within the URL. Current Url: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg Desire ...