Tips for placing a div within a flex item

Struggling to get it right, here's my query:

This is how my DOM looks:

<div id="content">
  <div class="listitem">
    <img class="thumbnail"/>
    <div class="option_icon"></div>
  </div>
  <div class="listitem">
    <img class="thumbnail"/>
    <div class="option_icon"></div>
  </div>
</div>

CSS:

#content {
  position: absolute;
  overflow: auto;
  width: 100vw;
  top: var(--header-height);
  left:0;
  bottom: var(--footer-height);
  display: flex;
  flex-direction: row;
  place-content: start;
}

.listitem {
  width: var(--image-size);
  height: var(--image-size);
  display: flex;
  flex-direction: row;
}

.thumbnail {
  align-self: flex-start;
  height: var(--image-size);
  width: var(--image-size);
}

.option_icon {
  height: calc(var(--icon-size)*0.75);
  width: calc(var(--icon-size)*0.75);
  background-color: grey;
  mask-image: url("icons/options.svg");
  position: absolute;
  align-self: flex-end;
  z-index: 999;
}

I'm aiming for the option icon to stick to the bottom right of each thumbnail image, creating a gallery view effect with square pictures.

It works in the first column, but as the options-div isn't affected by the flex-grid of listitems due to its absolute positioning, all icons end up stacked in the first column instead of spreading out with their siblings. I'll include an image to illustrate the current situation.

How do I keep the red option icons aligned with their siblings while being correctly spread out?

https://i.sstatic.net/2kd90.png

Answer №1

I was able to achieve the desired outcome by implementing the following steps.

To ensure that absolute items stay within the .listitem, I included a position relative property. Then, I positioned it on the right side by adding right: 0.

#content {
  position: absolute;
  overflow: auto;
  width: 100vw;
  left: 0;
  display: flex;
  flex-direction: row;
  place-content: start;
}

.listitem {
  width: 60px;
  height: 60px;
  display: flex;
  position: relative;
  flex-direction: row;
}

.thumbnail {
  align-self: flex-start;
  height: 60px;
  width: 60px;
}

.option_icon {
  height: 20px;
  width: 20px;
  background-color: grey;
  mask-image: url("icons/options.svg");
  position: absolute;
  align-self: flex-end;
  z-index: 999;
  right: 0;
}
<div id="content">
  <div class="listitem">
    <img class="thumbnail" />
    <div class="option_icon"></div>
  </div>
  <div class="listitem">
    <img class="thumbnail" />
      <div class="option_icon"></div>
  </div>
</div>

If this does not meet your expectations, please inform me so I can further investigate.

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

Is it possible to add a border to both the tbody and td

I currently have a table that is organized with tbody elements to group rows together. In order to create a grid-like structure, I applied borders to each individual td element within the tbody. However, I also desire to show that the tbodies themselves ar ...

Experiencing the issue of receiving unexpected commas following a div

Here is the code written in TypeScript for creating an HTML table that displays items from nested objects. The code is functional, but there seems to be an issue with extra commas being printed which are not part of any specific line being executed. im ...

Is anyone else seeing a mysterious gray outline surrounding the image?

When visiting my website, I encountered an issue with the main menu. Specifically, when hovering over 'Populaire boeken', the first 2 menu items display properly with an image on mouseover. However, there seems to be a pesky grey border surroundi ...

Ways to unlock all the information windows in Google Maps

Is it possible to automatically display all info windows on the map when it is first opened, eliminating the need for users to click on markers? In other words, I would like all info windows for all markers to be shown by default when the map is opened. ...

Selenium web scraping falls short in fully extracting all the data needed

Struggling to extract bond information from a webpage using Selenium. Despite successfully retrieving data for some rows in the table, certain rows and columns remain unscraped. The reason behind this inconsistency is unclear. The target webpage can be fo ...

What could be causing my jQuery script to malfunction?

After scouring through numerous Stack Overflow questions and conducting countless Google searches, I am still stumped by the issue at hand. As a beginner in web development, all I want is for this simple page to function properly. Can someone please point ...

Flickering in CSS transitions on Microsoft Edge

There seems to be a peculiar issue with CSS transitions in Microsoft Edge. The problem arises when there is a transition, such as between hover states, but the styles specified for those states are overridden by other styles in the CSS hierarchy. In such ...

Transform the numerical character into a checkbox within a table using AngularJS

In my HTML code, I am utilizing AngularJS to present data in a table. <div ng-controller="CheckCtrl"> <table class="table table-hover data-table sort display"> <thead> <tr> <th class="Serial_"> ...

How can I update the color of a list item when it is clicked within a foreach loop using knockout js?

Currently, I am encountering an issue with changing the color when a user clicks on a list item using the latest version of knockout js. My goal is to change the color of a list item when it is clicked and maintain that color until another item is clicked, ...

Can you make two columns in CSS that are left floated and maintain their original order?

While the title may not provide much clarity, I am struggling to put into words exactly what I am trying to achieve. I have created a layout in Photoshop which I have shared below to help illustrate my goal. Essentially, I have a blog that displays my sto ...

Execute PHP function by clicking on an HTML anchor tag

I'm curious - can a PHP function be triggered simply by clicking a link, or is it better to stick with the form submit method? If linking works, where should the reference point to? Check out this code snippet: <?php session_start(); func ...

Having trouble locating a method in $scope following angular $compile

Apologies for the simple question, I am a beginner in AngularJS and front-end development. I am attempting to create a modal using bootbox as shown below: In Service: function _modalData(){ let element = "<div onclick=\"saveSelecti ...

Streamlining Tailwind CSS styles in your React/Next.js components for maximum efficiency

Since implementing Tailwind CSS in my React/Next.js project, I've noticed a decrease in maintainability compared to using traditional CSS or styled-components. Previously, I could easily consolidate style changes, but now I find myself duplicating cla ...

How to incorporate HTML 5 video into your Angular 2 project using Typescript

How can I programmatically start an HTML video in TypeScript when the user clicks on the video area itself? Below is my HTML code: <div class="video"> <video controls (click)="toggleVideo()" id="videoPlayer"> <source src="{{videoSource ...

"Unexpected behavior: PHP+JS getElementById() function is returning an integer value instead of a

EDIT: Apologies for the PHP section not displaying correctly. I am attempting to extract a decimal value from PHP/HTML in JavaScript using getElementByID().value. However, despite the PHP value being decimal, it is represented as an integer in JavaScript ...

Raise the image above the wrapping div, positioning it at the very bottom

I'm struggling to position an image within a div in a way where: it protrudes above the div it begins at the very bottom of the div (with a small gap that I can't eliminate) Below is the relevant HTML code snippet: <div class="teaser-imag ...

Swapping stylesheets using a hyperlink - a simple guide

Currently, I am creating a website that utilizes PHP, XHTML strict, and jQuery. The main goal is to ensure the site is adaptable for mobile and desktop devices by implementing the principles of Responsive Web Design. This involves serving different stylesh ...

Creating a seamless full-page grid layout with CSS to eliminate the need for scrolling

My goal is to have 20 items on the grid of this page, each taking up full width and height with a fluid layout. Currently, I have successfully set up the page with 20 items spanning full width in a fluid design. However, the content of the grid is being p ...

Transferring HTML information to Flask

I'm struggling with passing a value from a text box in a web application to a Flask application. Despite my efforts, the request object in Flask does not seem to contain the data I need. Can anyone provide assistance with this issue? Below are the rel ...

Issue: Invalid element type detected: expected a string (for built-in components) or a class/function

Currently, I am in the process of learning how to make API calls using React Redux. I decided to practice by implementing an example in StackBlitz. However, I encountered an error after selecting a channel and clicking on the 'Top News' button. C ...