Creating a responsive grid division

.subcategory-main-wrapper {
  display: grid;
  grid-template-columns: repeat(4, max-content);
  position: absolute;
  width: 100%;
  column-gap: 4%;
  justify-content: center;
  height: 360px;

  @media @tabletScreens {
    height: 280px;
  }
  
  @media @mobileScreens {
    height: 450px;
    row-gap: 30px;
    column-gap: 7%;
    grid-template-columns: repeat(2, max-content);
  }
}

.subcategory-image-container {
  width: 278px;
  height: 278px;
  border-radius: 50%;
  background-color: black;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}
<div class="category-container">
  <div class="subcategory-main-wrapper">
    <div class="subcategory-container">
      <div class="subcategory-image-container">
      </div>
    </div>
    <div class="subcategory-container">
      <div class="subcategory-image-container">
      </div>
    </div>
    <div class="subcategory-container">
      <div class="subcategory-image-container">
      </div>
    </div>
    <div class="subcategory-container">
      <div class="subcategory-image-container">
      </div>
    </div>
  </div>

I'm facing an issue with making this circle Div resize proportionally to maintain its aspect ratio. The desired look when the screen is resized can be seen in this image, and the current appearance can be viewed in this image.

The width of this grid expands to match the browser width, but I want the columns and their contents to adjust based on the screen size. Here's my code:

.subcategory-main-wrapper {
    display: grid;
    grid-template-columns: repeat(4, max-content);
    position: absolute;
    bottom: 25px;
    width: 100%;
    column-gap: 4%;
    justify-content: center;
    height: 360px;
    
    @media @tabletScreens{
        height: 280px;
        bottom: 12px;
    }
    
    @media @mobileScreens {
        height: 450px;
        bottom: 35px;
        row-gap: 30px;
        column-gap: 7%;
        grid-template-columns: repeat(2, max-content);
    }
}
.subcategory-image-container{
    width: 278px;
    height: 278px;
    border-radius: 50%;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
}

HTML structure:

<div class="category-container">
<div class="subcategory-main-wrapper">
        <div class="subcategory-container">
        {% if model.config.titleSubCategoryImageOne %}
        <div id="image-1-{{model.id}}" class="subcategory-image-container">
            
        </div>
            <div class="subcategory-title">
                <a href="{{model.config.subCategoryLinkOne}}">
                    {{model.config.titleSubCategoryImageOne}}
                </a>    
         </div>
    </div>
</div>

I've attempted using flex display, but the columns get squeezed. Grid seems to work best for all screen sizes as it ensures the circle does not get distorted.

Answer №1

I successfully resolved the issue in my code by making the following changes: I modified the line below from

grid-template-columns: repeat(4, max-content);

to

grid-template-columns: 20% 20% 20% 20%;
and

.subcategory-image-container{
    width: 100%;
    height: auto;
    aspect-ratio: 1/1;
    border-radius: 50%;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
}

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

Incorporating a vertical slider alongside a fullPage.js section for a dynamic user experience

Is there a way to achieve a transition effect similar to this example for fullPage.js section-elements? <div id="fullpage"> <div class="section"></div> <div class="section"></div> </div> I have experimented with var ...

Tips on assigning html actions/variables to a flask submit button

I am facing an issue with my Flask app where the form submission process takes a while for the backend to process. In order to prevent users from refreshing or resubmitting, I want to display a loading gif during this time. The current HTML code for my fl ...

Lineup of pictures aligning with the consistent left margin of surrounding content

I am looking to create a row of images that aligns with the same margin-left as other content on my webpage, similar to the title in the example image provided. This row of images should scroll horizontally and extend all the way to the edges of the page. ...

Encountering an unforeseen issue with my code

I am currently developing a web application in advanced Java and incorporating various external libraries such as choosen.js, summernote.js, Bootstrap, BootstrapValidator, etc. I have encountered some errors and am struggling to pinpoint the root cause of ...

Challenge encountered in handling AJAX response data for presentation

Currently, I am immersed in a project and decided to implement AJAX for smoother form submissions. My initial attempt was trying to display text from a .txt file below the "submit" button, but unfortunately, that approach didn't yield the desired resu ...

What issue can be identified in this HTML/CSS code?

Here is the code snippet I am working with: http://jsfiddle.net/7jGHS/1299/ This is the HTML code: <div class="text1"><h2><span>THIS IS A TEST</span></h2> <p>1800 - 1570 - 000</p> <h2><span>T ...

Modify the background color of the entire page when the main div is clicked

I am attempting to alter the background color of my entire page when the div with id main is clicked. You can view the code here: $(document).ready(function() { var color = 1; $('#main').click(function(){ if (colo ...

Steps to Hide Pop-Up Cookie Module in HTML with Bootstrap 5

Could someone please assist me in figuring out how to close the popup module in bootstrap when the user accepts or cancels? I can't seem to remember how to do it. <div class="cookie-consent"> <span>This site uses cookies to enhan ...

What is the simplest method to create a scroller for engaging narratives?

I am in the process of creating a static but responsive storytelling website using HTML. My objective is to create an effect similar to this: https://i.stack.imgur.com/zIEpU.gif The idea is to have text on the left and a *.jpg image fixed on the right. As ...

How about placing one element above another? What sets apart using the margin property versus the position property for achieving this effect?

As I pondered the concept of stacking context, a question arose in my mind. Through my readings, I learned that by not applying any CSS properties that create a stacking context (such as position), it is possible to stack elements on top of each other usin ...

Compressed search bar when in mobile mode

My search bar is getting squashed on mobile devices. Any suggestions for fixing this issue? <div id="menu" class="py-4 d-flex justify-content-center"> <div class="row "> <div class="col-sm-auto "> ...

Unable to retrieve input value from dynamically-generated field with JQuery

There seems to be an issue with receiving a value from a static field when using the keyup method based on the input field class (.inputclass). Once a field is added dynamically, it does not get the value. Below is a sample code. Any help would be appreci ...

I'm looking to create a Triangle shape with CSS, any tips on how to achieve

Similar Question: Understanding the mystery behind this CSS triangle shape Please provide me with your valuable suggestions. ...

Exploring the differences between pseudo-elements when styled as display:block versus display:inline

I'm currently honing my CSS skills by following a Youtube tutorial from freecodecamp.org Here's the code I've been working on: p::before{ content: "hello "; color: white; font-size: 60px; background: salmon; margin-bottom: 20px ...

Crafting an iframe that dynamically adjusts with Tailwind CSS

I'm having trouble ensuring that an iframe fits properly within a div while using tailwind CSS. I'm struggling to make the iframe responsive, no matter what class I try. Can anyone suggest a class that would help me achieve responsiveness for an ...

strange occurrences of bootstrap.min.css.map popping up

While working on my e-commerce website using Node, Express, Mongoose, and Bootstrap, I encountered an unexpected issue related to "bootstrap.min.css.map". The error 'Cast to ObjectId failed for value "bootstrap.min.css.map" at path "_id" for model " ...

Having trouble updating the value in the toolbar?

Here is an example that I added below: When I click the add button, the value of the "newarray" variable is updated but not reflected. I am unsure how to resolve this issue. This function is used to add new objects: export class AppComponent { ne ...

Overlay a semi-transparent gray layer onto the background color

My Table has various TDs with different background colors, such as yellow, red, green, etc., but these colors are not known beforehand. I am looking to overlay a semi-transparent gray layer on certain TDs so that... The TD with a yellow background will t ...

Deleting a hyperlink within a content-editable area

Presently, I am in the process of working on a straightforward project where users can format text using contenteditable. I have successfully implemented a feature that allows users to add hyperlinks to selected text by clicking on the "Create Link" button ...

Inject a snippet of temporary code at the end of the CSS file using JavaScript or JQuery

I am looking to dynamically add temporary CSS code to the end of an external CSS file or modify it using JavaScript or jQuery. For example, let's say my mystyle.css file looks like this: //mystyle.css p{color:red} Now, when a user interacts with the ...