enumerating elements from the lowest point towards the highest, while maintaining their original sequence

Scenario

In my current project, I am working on a design where the categories are showcased within a square product. The number of categories displayed can range from one to three.

Challenge

The design demands that the categories appear in a bottom-to-top order. Each category is represented as

<div>category-1</div>
with a height of 80px and a customized width (maximum 200px).

Is it feasible to achieve this layout using CSS alone and ensure compatibility with IE9 or higher?

If a CSS-only solution is not viable, I have the option to utilize Angular JS.


Currently, the design looks like this when there are two categories:

https://i.sstatic.net/00TsA.png

I need to transform it to look like this:

https://i.sstatic.net/ApRu9.png

If I add a margin-top in this scenario, it resolves the issue for two categories, but when only one category is present, it appears as shown below: https://i.sstatic.net/oSwRB.png

Consistency in spacing between the FOOTER section and the last category is crucial.

UPDATE:

To clarify, there will always be a minimum of one category and a maximum of three categories.

To illustrate further, I have created an example on jsfiddle:

https://jsfiddle.net/k3ve49uj/

The final result demonstrates the desired outcome. Even if there is only one category, it should align with the bottom, simulated by using a <br/>.

Due to confidentiality reasons, I cannot share the actual HTML & CSS code, as it pertains to a client project. However, I will be able to implement the recommended changes later.

Information

Please do not make alterations to the provided code; it serves only as a reference for understanding the requirement. Essentially, all elements inside a container must be positioned from the BOTTOM to the TOP, not vice versa.

Code Snippet

.pr.product {
width: 380px;
height: 380px;
background-image: url("http://unsplash.it/380/380?random&blur");
margin: 30px;
position: relative;
color: #fff;
text-shadow: 1px 1px 0px rgba(0,0,0,.5);
}
.product .headline {
position: absolute;
left: 20px;
bottom: 60px;
width: 75%;
}

.product .category_wrapper {
position: absolute;
right: 20px;
width: 20%;
bottom: 140px;
background-color: rgba(0, 255, 0, .3);
height: 60px;
top: 255px;
}
.product footer {
text-align: right;
color: red;
font-size: 18px;
text-transform: uppercase;
position: absolute;
bottom: 20px;
right: 20px;
}
<body>
  <h3>
  Looks good, but only if 3 categories are available.
  </h3>
  <div class="product">
    <div class="headline">
      <h1>Test headline</h1>
    </div>
    <div class="category_wrapper">
      <div class="category">category-1</div>
      <div class="category">category-2</div>
      <div class="category">category-3</div>
    </div>
    <footer>
      FOOTER
    </footer>
  </div>

  <hr/>
  <h3>
    Only 2 categories (they stick to the top)
    </h3>
  <div class="product">
    <div class="headline">
      <h1>Test headline</h1>
    </div>
    <div class="category_wrapper">
      <div class="category">category-1</div>
      <div class="category">category-2</div>

    </div>
    <footer>
      FOOTER
    </footer>
  </div>

  <hr/>
  <h3>
      Desired output if only 2 tags
    </h3>
  <div class="product">
    <div class="headline">
      <h1>Test headline</h1>
    </div>
    <div class="category_wrapper">
      <br/>
      <div class="category">category-1</div>
      <div class="category">category-2</div>
    </div>
    <footer>
      FOOTER
    </footer>
  </div>


</body>

Answer №1

Here's a solution that should meet your needs perfectly. However, I can't guarantee it will work seamlessly with your existing CSS without observation. Give this a try or share your CSS code for the list and footer if necessary.

#footer {
  margin-top: 20px;
  width: 100%;
  height: auto;
  color: red;
}

ul{
  margin: 0;
  padding: 0;
}

ul li {
  list-style-type: none;
  
}
<ul>
  <li>Category 1</li>
  <li>Category 2</li>
</ul>
<div id="footer">Footer</div>

UPDATE

Take a look at this fiddle with your revised code and let me know how it works for you.

Simply update your .product .category_wrapper as shown below

.product .category_wrapper {
            position: absolute;
            right: 20px;
            width: 20%;
            bottom: 60px;
            background-color: rgba(0, 255, 0, 0.3);
            height: auto;
        }

Answer №2

By adjusting your CSS in the following way, you can achieve the desired outcome.

.item .type_container {
    position: fixed;
    left: 10px;
    width: 30%;
    top: 50px;
    height: auto;
}
.item .type_container .type {
    background-color: rgba(255, 0, 0, .5);
}

Answer №3

Given that the quantity of elements can range from 1 to 4, the overall height of the list becomes flexible - consider eliminating the height and top attributes from the category_wrapper in your style sheet.

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 is the best way to automatically scroll to the chosen option when a button is clicked?

Is there a way to make the select box automatically scroll and show the selected option when the focus button is clicked? The current method I am using with focus does not achieve this. Are there any JavaScript or jQuery methods that can help me solve th ...

CSS for creating a vertical dropdown in a Bootstrap horizontal navigation bar

I recently delved into the world of twitter bootstrap and decided to construct a website from scratch using it. I've hit a roadblock while trying to develop a horizontal navigation bar with vertical dropdowns where each <li> creates a new row (c ...

Hamburger icon is failing to appear in the collapsed navbar for certain items

My React application is not displaying the items of the collapsed navbar when using the Bootstrap navbar for mobile responsiveness. Can anyone please suggest what might be wrong here? <!-- Bootstrap 4.1.3 library --> <link rel="stylesheet" href ...

Display a different DIV based on the presence of a URL variable, either hiding one or

If the URL contains the word 'email,' I want to hide the <div id="sociallocker"> and display the <div id="emaillocker">. I attempted the following code but it did not work: <script type="text/javascript"> $(function () { ...

Guide to animate/move a tile to a specified location using CSS at 90x90px dimensions

I am trying to achieve a smooth transition for grid[row1][col1] sliding over to grid[row2][col2], followed by an expansion to 90x90px Does anyone have any suggestions on how to accomplish this? Here is an example of the styling: <style type="text/css ...

Stop input-group-append from causing adjacent input-groups to shift right

When I have two input fields next to each other and render a button within an input group, the button pushes the neighboring input field on the right, decreasing its width. This behavior can be observed in this example sandbox: view code sample. To illus ...

How to rotate text direction using JavaScript and CSS

Despite my extensive efforts, I have been unable to find a solution to a seemingly simple problem. In JavaScript, I have generated dynamic text using the following code: context.fillText('name', 10, 10, 20); Now, I need this text to be ori ...

What causes line-height to be overlooked in a span element but effective in a div element?

Take a look at this example: CSS: How to reduce line spacing of text? I've experimented with it, and I noticed that the CSS property line height is not very effective when applied to a span element. Why is this the case? Why does it only work properl ...

How to Resolve the Issue of Projectiles Not Converting into an Image?

When I attempted to convert my projectile class into an image, an error occurred. Here is the error message: File "C:\Users\Habib\Desktop\PYTHONGGAME\py.py", line 320, in <module> bullet.draw(window) File "C:\Us ...

Enhancing text visibility in dompdf by making it bold or increasing its size

Recently, I began using dompdf v0.6.0beta3 along with the dompdf Codeigniter helper in Codeigniter. To address the issue of missing fonts, I manually moved the Arial font family tff files from the Windows 7 font folder to the /lib/fonts directory within do ...

Is it possible to create a responsive iFrame without making changes to the parent page's code?

I am working on creating a webpage that will be inside an iFrame. The code below is what I will be adding to the page. It is designed to be responsive, but unfortunately, the iFrame itself is not. Since I do not have access to the parent or hosting page to ...

Data tables sizing issue occurring across various web browsers

I've recently encountered an issue with my DataTables not filling 100% of their div width. I'm utilizing Bootstrap and jQuery for this project. Any suggestions or tips to fix this problem? HTML <div class="form-group" style="height: 400px; ...

A problem encountered in specific JavaScript code

As a newcomer to JavaScript, I have encountered an issue while trying to run this script: <html> <head> <title>Exploring javascript functionalities</title> </head> <body> <p id="demo">I ...

`Unable to display webpage on Android APK`

I've been utilizing phonegap to create a web page that mimics an app, and while the page functions well in the native browser on Android and works fine in the emulator, it displays only a white blank page when accessed through the actual app (which ha ...

Perform calculations using the provided input values or null values in Javascript/Jquery

I'm a beginner in Javascript and JQuery. Take a look at my code that calculates an average (A) value based on three input values. https://i.sstatic.net/teGkc.png Check out the JQuery snippet below: $(".q-value, .e-value, .t-value").click(f ...

Using AngularJS with ngRepeat allows for the insertion of an extra element every specified number of repeats

I am attempting to establish a layout where every 7 repeated elements, an extra element is inserted. This additional element must be part of the parent container rather than being a child of one of the repeated elements. Simply changing the class is not s ...

Creating dynamic autocomplete suggestions using Jquery and Ajax

I've been attempting to utilize Jquery's Autocomplete feature found here http://jqueryui.com/autocomplete/#default Despite my efforts, the output is not functioning properly. To troubleshoot, I've created a FIDDLE which you can access by c ...

Changing the color of a checkbox in React JS when it is checked: a step-by-step guide

Is there a way to change the color of the checkbox when it is checked? Right now, my checkbox appears with this color: https://i.sstatic.net/mY9Jg.png However, I am looking to change it to red. Any suggestions on how I can achieve that? <input ...

Center align the division within the list item

Check out the fiddle provided here: https://jsfiddle.net/5jnnutg8/ I am looking for a way to center align and display inline the "something #" list items. While the title "Hi" can be centered using text-align: center in css, this doesn't seem to wor ...

Unable to access complete map using ngmap and AngularJS

I am currently working with ngmap and encountered the issue shown in this screenshot https://i.stack.imgur.com/WchKT.png Here is my code: var app = angular.module('dv', ['ngMap']) app.controller('MC', function($scope){ ...