Dynamic Square Layouts in Ionic

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

I am looking to implement responsive square grids in Ionic, similar to the image above.

However, I am currently facing a different outcome as displayed in the image below. I have scoured the internet for a solution that does not involve using images, which is not my desired approach.

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

Answer №1

If you want a CSS-only solution, you can achieve it with the following code:

* {
  box-sizing: border-box;
}

.square-container {
  padding: 8px;
}

.square {
  width: calc(100% / 5);
  float: left;
  position: relative;
  padding-bottom: calc(100% / 5);
}

.square .content {
    width: calc(100% - 16px);
    height: calc(100% - 16px);
    margin: 8px;
    padding: 16px;
    position: absolute;
    color: white;
    background-color: #0095ff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.26);
}
<div class="square-container">
  <div class="square">
    <div class="content">1</div>
  </div>

  <div class="square">
    <div class="content">2</div>
  </div>

  <div class="square">
    <div class="content">3</div>
  </div>

  <div class="square">
    <div class="content">4</div>
  </div>

  <div class="square">
    <div class="content">5</div>
  </div>

  <div class="square">
    <div class="content">6</div>
  </div>

  <div class="square">
    <div class="content">7</div>
  </div>

  <div class="square">
    <div class="content">8</div>
  </div>

  <div class="square">
    <div class="content">9</div>
  </div>

  <div class="square">
    <div class="content">10</div>
  </div>
  
  <div class="square">
    <div class="content">11</div>
  </div>
  
  <div class="square">
    <div class="content">12</div>
  </div>
</div>

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

Targeting all children instead of just the odd ones when using `nth-child(odd)`

In the portfolio, I have a unique requirement where every odd entry should be reversed. These projects are generated dynamically from an array and passed into the component through props. To style it, I'm utilizing styled-components. However, I&apos ...

An external iframe will automatically adjust its settings to have an "overflow: hidden" attribute

My app relies on using iframes to interact with third-party websites. Unfortunately, one of these websites has a feature that automatically changes the "overflow" property to "hidden" when it detects that it is being utilized within an iframe. Is there a ...

What is the best way to apply a CSS class to a div element without affecting its child elements using JavaScript?

Currently, I am using JavaScript to add and remove a CSS class through a click event. Within my div structure, I have multiple similar divs. While I can successfully add and remove the class from my main div, I am facing an issue where the class is also ap ...

Adjust the transparency and add animation effects using React JS

When working on a React project, I encountered an issue where a square would appear under a paragraph when hovered over and disappear when no longer hovered. However, the transition was too abrupt for my liking, so I decided to implement a smoother change ...

I'm struggling to understand why the background-color is affecting the margins as well

Check out this code snippet: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <style type="text/css"> * {border: 0px; padding: 0px;} ...

Fine-tuning components in HTML and CSS

Is there a way to align the asterisk symbol with the text and adjust the positioning of the Yes and No elements as depicted in the image? https://i.sstatic.net/mCsUG.png Check out this fiddle: https://jsfiddle.net/07bd0hda/ and snippet below: <div ...

Access a component within an inactive carousel slide

I'm encountering a problem with the search feature in the carousel within my FAQ system. The search box is designed to locate questions within the FAQ list. Currently, when a user selects a question from the search results, they are redirected to th ...

Tips for creating a table that fills the height of its parent div without surpassing it

Issue: I am facing a challenge with making a <table> element fill 100% of its container's height dynamically, without going over the limit. Context: When the height of the <table> surpasses that of the container, I want the ability to s ...

Responsive CSS for symmetrically-aligned DIVs that float on screens of varying widths

[ 1 ] [ 2 ] [ 3 ] [ 4 ] My design features four floating DIVs, each set to float left with a width and height of 128px. When the screen is narrowed, the last DIV correctly moves to the next line: [ 1 ] [ 2 ] [ 3 ] [ 4 ] However, I want the last two bl ...

"Enhance Your Website with Various Hover Effects Using CSS across Multiple Elements

Has anyone experienced trouble with making the hover effect work in my onHover class and applying a display effect to span.box? Any ideas on how to fix this? .onHover { display: block; width: 200px; height: 20px; background: green; } .onHover:ho ...

The problem with Text Input and Label Effects

This code is currently in use. It seems to be working fine, but there's one issue that needs addressing: when moving from one input field to the next, the labels for each field are getting mixed up with their corresponding inputs. This problem will b ...

In order to check a checkbox, you need to ensure that the scrolling div has been scrolled to the very

I have a situation where I need to ensure that a user has scrolled to the bottom of a disclaimer before they can acknowledge it by checking a checkbox. Our legal department requires this extra step for compliance reasons. Here is an example of how the mark ...

Using JavaScript to Sort and Filter HTML <optgroup> Elements

I am encountering an issue with an HTML <select> element that contains <optgroup> elements with <option> elements nested within them. Here is an example of the structure: <select> <optgroup label="label1">Label 1 <op ...

What is the best way to relocate the box within this HTML/CSS document?

Looking at this specific HTML webpage <html> <head> <title>CSS Structure</title> <link href="layout.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header">Header 900x100 px</div> ...

Generate dynamic concentric rings with either CSS, Canvas, or SVG for a fluid and scalable design

Looking to create a graph similar to these examples: http://bl.ocks.org/cmdoptesc/6228457 or like this Wanting the graph to be able to scale based on browser width without using javascript if possible. Ideally, looking for a CSS-only solution, but open ...

Responsive Div that Resizes Proportionally within Parent Container

Having a div element that adjusts its height based on width to maintain aspect ratio, I aim to place this div within another while maximizing available space vertically and horizontally without any cropping. It seems that object-fit: contain, typically use ...

Receiving a 500 (Internal Server Error) in AngularJS when making a $http POST request

Being a novice in the world of Ionic and Angular, I am currently working on a project using the Ionic framework with Angular.js. My goal is to make a WebApi call using the $http post method. I have referred to the solution provided in this ionic-proxy-exam ...

Tips on incorporating a button to enable text formatting to 'bold' within a Text Area on an HTML webpage:

In the process of creating an online text editor, I am looking to incorporate a button above the text area that can be used to make selected text and/or upcoming text bold. To provide more clarity, I envision adding a bold button similar to the one found a ...

Mastering Bootstrap: The Ultimate Guide to Aligning and Centering Buttons at the Bottom of Columns of Equal Height

My Bootstrap 4 layout consists of three columns using col-sm classes. You can view the codepen example here: https://codepen.io/anon/pen/EryRJL?editors=1100 Within each column, I have a paragraph of text followed by a button. I'm trying to figure out ...

How do I ensure that my absolutely positioned element is centered in this specific scenario?

I've been working on centering an element within its parent container, and I'm having trouble ensuring it remains centered responsively. Here's what I have so far: HTML <div class="example"> <span class="element1">Element ...