Width of element while applying the transform: translate()

I am currently using absolute positioning to align a ul list at the bottom center of a container. However, I have noticed that when the window or container is resized, the list seems to shrink as if there is some sort of margin, padding, or max-width applied somewhere. Check out this fiddle for reference.

Objective My goal is to ensure that the list maintains an auto width (depending on its content) and only shrinks when it exceeds 100% of the parent's width.

I have observed this issue occurring specifically when using transform: translateX(-50%).

UPDATE The wrapper div contains additional elements. The list serves as a navigation menu or toolbox.

HTML

<div id="wrapper">

  <p>Additional content here</p>

  <ul id="list">
    <li><span></span></li>
    <li><span></span></li>
    <li><span></span></li>
    <li><span></span></li>
    <li><span></span></li>
  </ul>
</div>

CSS

* {
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

#wrapper {
  position: relative;
  height: 100%;
  width: 100%;
  background: #fff;
}

#list {
  list-style: none;
  position: absolute;
  padding: 2px;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0;
  background: #555;
}

#list li {
  display: inline-block;
  margin: 1px;
}

#list span {
  display: block;
  height: 40px;
  width: 40px;
  background: #222;
}

Answer №1

Flexbox can be used as an alternative to the traditional method of absolute positioning.

#container {
  background: #fff;
  height: 100%;
  width: 100%;
  position: relative;
  display: flex;
}
#items {
  margin: 0;
  padding: 0;
  list-style: none;
  align-self: flex-end;
  margin: 0 auto;
  border: 1px solid #222;
}

The updated fiddle is available at http://jsfiddle.net/uLj5raoq/

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

Unable to apply a border to the button

I'm having trouble adding a border to my button on the website. I've tried setting the color, which works fine for the font color within the button, but the border properties are not working. Despite trying some highly rated solutions, none of th ...

Positioning the label for a Material-UI text field with an icon adornment when the shrink property is set

https://i.stack.imgur.com/E85yj.png Utilizing Material-UI's TextField, I have an Icon embedded within. The issue arises when the label "Your good name here" overlaps the icon instead of being placed beside it. This problem emerged after I included ...

Adjust the text color of a div element by clicking a button with the help of JavaScript

I am trying to change the font color of my div when a button is clicked using JavaScript. The two buttons I have are 'Green' and 'Red'. <button type="button" class="green">Green</button> <button type="button" class="red" ...

What is the best way to combine a bootstrap 4 table with Angular?

Currently, I am facing some challenges while trying to incorporate a bootstrap 4 table into my Angular project. It appears that jquery is not functioning properly in this integration. You can view my current implementation here. The issue arises when any c ...

Chrome causing the vanishing act of floated iframes

I encountered an unexpected issue on my website recently. For the past three years, everything was working smoothly until I updated Chrome to version 60. Now, whenever I try to load iframes from Archive.org, they momentarily appear and then vanish instantl ...

<!--[if IE]> does not function properly on any web browser

Hello, I am experiencing a perplexing issue and despite searching extensively on Google, I have been unable to find a solution! I am trying to change the body background color to red only in Internet Explorer, but it is not working as expected. Here is t ...

Dynamic background scaling for Wordpress sections - is it responsive?

I am in the process of creating a WordPress website and I have set a section background with an image that has a width of 1920px. However, when viewing it on my 1366px screen, the image does not scale properly and gets cut off from the right due to the p ...

Navigational elements, drawers, and flexible designs in Material-UI

I'm working on implementing a rechart in a component, but I've encountered an issue related to a flex tag. This is causing some problems as I don't have enough knowledge about CSS to find a workaround. In my nav style, I have display: flex, ...

The Stripe card element seems to be missing from the form

I'm a newcomer to angularjs and currently working on integrating version 3 of the stripe api into my angular application. I followed the steps provided on the stripe website, but faced an issue when trying to incorporate their code which is primarily ...

I have a parent DIV with a child DIV, and I am looking to use jQuery to select the last child DIV. The parent DIV has an

In my HTML code, I have a parent div called "allcomments_4" which contains several child divs with unique IDs (oneEntry), each with their own children. My goal is to locate and retrieve the content inside the last child of the parent node (lastComment) and ...

What could be causing my HTML footer to not grow from its borders?

Hello there, I need assistance with an HTML document I am working on. Can you explain why my footer is not expanding to the edges even though I have set the width to 100%? Please help. Please note that the code provided is incomplete, and for the full cont ...

I am struggling to properly align the login form in the center of the login page

Can someone please assist me in centering the login form on the login page? I've attempted using align-items-center and justify-content-center but it's still aligning at the top. Any help would be greatly appreciated as I've spent a signific ...

What's the issue with my jQuery AJAX script?

I am experiencing an issue with my ajax pages using jQuery to retrieve content. Only one page seems to be working properly, even though I have multiple pages set up. How can I resolve this problem? $(document).ready(function() { $('.lazy_content& ...

Issue with Nav Bar Toggle not changing text to white color

Query I'm baffled as to why the text in the navigation bar (when opened with the Burger Menu) refuses to turn white. I've exhausted all efforts to change the color to white. Please assist me in pinpointing why the text remains unaffected when t ...

Creating a bespoke scrollbar using Material UI

What is the best way to implement a custom scrollbar in Material UI? I have spent a lot of time researching how to add a custom scrollbar and I finally found a solution that works. Thanks to everyone who helped me along the way. ...

Authenticating with Google using a Custom Application Title

My website currently requires Google+ authentication in the following way - However, I want to revamp it to resemble stack overflow's method - Here are two necessary changes - 1) Replace This app with My App Name 2) Include only View your email ad ...

Count the start and end rows of a table within the <tfoot> using pdfHTML/iText 7

Currently, I am working on a project where I am developing a document generator that utilizes pdfHTML 3.0.3 and iText 7.1.14. The document includes a table displaying 'items'. It's worth noting that these item rows will likely span across mu ...

Include an additional title to the header of the Bootstrap 4 modal

Currently, I am utilizing a basic modal window which was constructed from Bootstrap's (4.4) sample. This modal consists of a header division: <div class="modal-header"> <h5 class="modal-title">Modal title</h5> <button ty ...

Combining KendoUI tables with the power of AngularJS

Currently, I am in the process of developing a versatile table widget (utilizing KendoUI) with data binding integrated through AngularJS. The layout of the table widget will be as shown below in the HTML file (accessible via this fiddle: http://jsfiddle.ne ...

Initiate timer when mouse leaves; pause timer upon mouse hovering using JavaScript

I am currently working on creating a volume bar for a video. The idea is that when you click the volume button, a div will appear allowing you to control the volume level. As soon as you hover out of the div, a timer will start counting down from 7 and the ...