Ensure that div elements in a container only occupy the required amount of space

I'm struggling to generate images with dashes in between them while ensuring that each div only occupies the necessary space within the container. However, my attempts so far have resulted in all the divs taking up an equal amount of space, which is not intended for the last div. The issue arises when the width of the hr is set to 100%, causing it to disappear if the width of the div is not specified.

Any suggestions on how to resolve this?

Here's what I currently have:

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

And here's the code snippet:

.hr {
border-top: 10px dashed black; 
background-color:transparent;

.div2 {
align-items: center;
padding: 0;
flex-grow: 1;
margin-bottom: 0;
display: inline-flex;
}

.div1 {
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
text-align: center;
position: absolute;
display: flex;

}
<div class="div1">
 <div class="div2">
  <img src="circle.svg">
  <hr class="hr">
 </div>
 <div class="div2">
  <img src="circle.svg">
  <hr class="hr">
 </div>
 <div class="div2">
  <img src="circle.svg">
  <hr class="hr">
 </div>
 <div class="div2">
  <img src="circle.svg">
 </div>
</div>

Answer №1

To enable the resizing of .div2, include the CSS property flex-shrink: 1;

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

Image with a custom background color and div overlay

Is it possible to have a colored background with an image in the content div? <body style="background-color: black; "> <div id="header" style="background: url('xxx11.png') repeat left top;"> </div> <div id="#containe ...

What is the best way to enable an element to be dragged from just a single point?

I am facing a challenge with a parent div (such as "#strip17") that contains multiple child divs. Most of these child divs consist of a canvas where the user can draw using their mouse. However, the last child div should act as a handle that allows the use ...

Webpage not resizing when WebView orientation changes

While developing my android app, I encountered an issue with the WebView. When I am at the very top of the WebView and switch my phone to landscape mode, the webpage does not resize properly to fit the screen. It only takes up half of the screen. However, ...

Extracting Data from Input Box Using Query

In my HTML setup, I have five <textarea> tags with IDs text1,text2,text3,text4, and one additional <textarea> tag with ID output. I want to query based on the values of text1,text2,text3,text4 (referred to as field1, field2, field3, field4). F ...

Enlargement animation when hovering over a "next-link" button featuring an SVG file of a social media platform

The following code snippet demonstrates how to import an Instagram icon and create a footer component: import InstagramIcon from './assets/IG.svg'; export const Footer = ({ footer }: FooterInterface) => { return ( ..... <Link href={`${fo ...

After migrating the Django website to a new instance, the CSS ceased to function properly

I recently made the switch from hosting my website on Redhat to Amazon Linux on EC2 due to the cost savings. After configuring the Apache server and Django settings, the website seemed to be functioning properly except for the layout of the HTML. The CSS w ...

Two divs with floated attributes and equal heights

My unique HTML is below: <div class="container"> <div class="box"> <div class="float"> <img src='http://media-cdn.tripadvisor.com/media/photo-s/03/9b/2f/db/miami-beach.jpg' /> </div> ...

Padding-left may cause text to not wrap correctly

Every link in the left menu has a padding-left: 15px;. This is done to accommodate a background image (the blue arrow). However, when text wraps (like in "Paintings, prints, and watercolours"), it seems to ignore the padding. I've searched extensive ...

Executing a pair of AJAX calls and combining their results within a single div element

My project entails utilizing two AJAX requests The first request loads all the streams The second request retrieves information about online streams Due to lack of combined data from APIs for both online and offline streams, I have successfully loaded ...

What is the proper way to ensure a pull right display appears correctly?

This is the code I am currently using .tag-container.bottom-border.col-middle h1.text-center {{ tag.name }} button.btn.btn-follow.pull-right(ng-hide="hasFollowed" ng-click="tagArticles.followTag()") Follow I am trying to align the tag name in th ...

Update the variables upon a click event following the completion of an AJAX request

Despite my efforts, I am unable to find a solution to the issue I am currently facing. To address this problem, I have created a script using PHP and jQuery that enables users to promote their "listings" on my website. When users visit a specific page, the ...

Apply a new class to all Radio buttons that were previously selected, as well as the currently

Struggling with a simple code here, trying to figure out how to add color (class) to the selected radio button and the previous ones. For example, if button No3 is selected, buttons 1, 2, and 3 should get a new color. Below is the basic code snippet: < ...

Experimenting with alterations to link styles

A particular test we are conducting involves examining the style changes of a link (a element) after a mouse over. Initially, the link is displayed with a black font and no decoration. However, upon hovering the mouse over it, the font color changes to bl ...

Using jQuery to Extract HTML Content from a JSON Object

I'm completely lost on what I'm doing incorrectly, but the JSON string I have looks like this: jsonp443489({"content":"<!DOCTYPE html><html><head><title>Title</title></head><body><p>Hello World< ...

Having trouble getting the CSS transition effect to work properly

With the click of a button, I alternate the opacity of an element between 0 and 1. A transition effect is supposed to take place for the opacity property. However, the transition effect does not seem to work as expected. Check out this link to see the p ...

javascript limitation on self-executing code

I am facing an issue with my HTML file that contains self-executing JavaScript code (I specifically need the JavaScript to be internal, not from an external file). Upon inspecting in Chrome, I encountered the following error message: Refused to execute ...

Navigating on Blogger can be a tricky task when it comes to searching and

I recently added a Table to my blogger post, along with an input form for readers to easily search data. After finding the code on W3Schools (link here), I implemented it successfully. However, I am looking to make some improvements. Here is my question: ...

The navigation bar is positioned at the forefront, blocking any elements from being displayed beneath it

I just started using Bootstrap and I'm facing an issue with my navbar. No matter what I do, anything I place goes behind it. Even with margins and the native padding from Bootstrap, I can't get the distance right because the div that I want to mo ...

Disabling the button add-ons functionality in Bootstrap 3 for mobile devices

I am facing a challenge with my website that has a visually appealing jumbotron and an enticing email signup call to action bar. The issue arises from the fact that my site is bilingual, catering to both German and English speakers, causing confusion with ...

Having trouble aligning a div to the right in Bootstrap?

While working on my Bootstrap website, I encountered an issue where I wanted to align the second div (containing lorem text) to the right side of the webpage. Despite trying options like ms-0 and CSS text-align, the div kept going down. Can someone pleas ...