Position a letter inside a circular shape at the center of a specific grid cell using Ionic4

I'm trying to make sure that the circular element with a letter inside is perfectly centered within the grid row.

This is how I have set up the SCSS:

.numberCircle {
  width: 25px;
  line-height: 25px;
  border-radius: 50%;
  text-align: center;
  font-size: 18px;
  border: 2px solid #666;
}

When it comes to the HTML file, this is what I have done:

<ion-item>
  <ion-grid no-padding>
    <ion-row no-padding justify-content-start align-items-start>
      <ion-col ion-item no-lines no-padding text-center>
        <div class="numberCircle">X</div>
      </ion-col>
    </ion-row >
    <ion-row>
      <ion-col ion-item no-lines no-padding text-center>
        <div class="numberCircle">Y</div>
      </ion-col>
      <ion-col ion-item no-lines no-padding text-center>
        <div class="numberCircle">A</div>
      </ion-col>
    </ion-row>
    <ion-row>
      <ion-col ion-item no-lines no-padding text-center>
        <div class="numberCircle">B</div>
      </ion-col>
    </ion-row>

  </ion-grid>

</ion-item>

The issue I'm facing is that the numberCircle elements are not perfectly centered in the grid cell and thus not aligned within the rows. How can I address this problem?

Answer №1

Make sure to center the element:

.numberCircle {
  width: 25px;
  line-height: 25px;
  border-radius: 50%;
  text-align: center;
  font-size: 18px;
  border: 2px solid #666;
  margin-left: auto;
  margin-right: auto;
}

By default, a div is displayed as a block element and setting a specific width may not center it properly. Setting both side margins to auto will help achieve the desired result.

You can also explore using flexbox properties for more efficient centering options. Check out the following link for further information on flex container properties:

Flex Container Properties - CSS Utilities - Ionic Documentation

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

How to display unique content within a div based on individual element hover using AngularJS

As a newcomer to AngularJS, I am facing some challenges while working with directives. Currently, I am working on a navigation menu where my goal is to dynamically display different information within the .services-content section upon hovering over each ...

Floating Columns in Bootstrap 4

Seeking a solution in Bootstrap 4 for achieving the placement of 3 columns in one row, where the content in the first column dictates that the other two columns should be displayed alongside it. Bootstrap 4 utilizes Flex to manage rows and columns. Please ...

Utilizing CSS to Properly Position HTML Elements

Check out my code on jsFiddle I'm facing some challenges in positioning HTML elements using CSS. While I grasp the fundamental concepts of block and inline elements, implementing them in real coding scenarios can be confusing. I've shared my HTM ...

Issue with mouseover functionality not functioning properly while hovering over a dropdown menu

My friend and I are relatively new to the world of coding with HTML, CSS, and a bit of JavaScript. We're currently facing an issue with our dropdown menu implementation. We have created buttons and added a dropdown menu using li and ul elements. Initi ...

Achieving full-width ordering in CSS

Is it feasible to have a child div with 100% width? This is an example of HTML: <div class="main"> <div class="order2">order2</div> <div class="order1">order1</div> </div> Here is the CSS code: .main{ dis ...

Currently in the process of optimizing controllers but continuously encountering 404 errors when making api requests

I previously utilized the SampleData controller that is automatically generated. I added my custom methods, everything was functioning perfectly. Recently, I decided to create a new class for better organization purposes. After pasting in the desired metho ...

CSS inline-block problem - Either everything stays or everything collapses

I am facing a specific scenario where I have three inline-elements. Two of them are essentially the same, but the one in the middle has an unknown width. I want to achieve one of two things: Have all three elements display inline on the same row If the ...

Enlargen div or unordered list according to content exceeding limits

What is the best way to ensure a div expands when it contains a lot of content? Code Example (HTML): <div class="content"> Content goes here <br /> Content goes here <br /> Content goes here <br /> Content goes her ...

Experiencing difficulties typing into a text/input field using electron

I am currently working on a calendar app using electron. In the app, I have created a menu to add new events and other features. One feature I want to implement is allowing users to enter the title of their event in a textbox/input field. However, when I t ...

Creating a single form field with two inputs and applying custom styling in Angular Material can be achieved by following these steps

In my Angular Material project, I am creating a sample application with a form that includes a field with an input and dropdown. Currently, I have utilized flex styles and attributes as shown below: <div class="row"> <mat-label>De ...

Tips for making a horizontal scrolling container that doesn't hide elements with overflow-y?

I'm struggling to find an example of horizontal scrolling that doesn't hide content with overflow-y. Is there a way to create a horizontally scrolling div where absolutely positioned elements (dropdowns) remain visible? If you have a working ex ...

The alignment of the div on the project page is not correct

I am seeking help to align the entire .main class, which starts with "dashboard," properly at the top of the page next to the sidebar. Currently, its alignment appears below the sidebar. Here is a visual representation of my current page layout: https://i ...

Angular: Using ngrx for Nested HTTP Calls

Looking at my Angular code, I am trying to figure out how to convert nested HTTP calls into the ngrx pattern. My idea is to create separate actions for getUser and getPost, but I am struggling with passing the getUser response as a parameter to the getPo ...

Issue encountered while utilizing property dependent on ViewChildren

Recently, I designed a custom component which houses a form under <address></address>. Meanwhile, there is a parent component that contains an array of these components: @ViewChildren(AddressComponent) addressComponents: QueryList<AddressCo ...

In certain instances, content spills beyond the boundaries of a div element in Chrome 43

In my design, I have a purple block that contains text of varying lengths. The block is responsive and its width is set in percentage. Some users using Chrome (v43.0.2357.65) on Windows XP are experiencing issues where the text overflows beyond the edge o ...

After installing Ionic globally in the node modules directory, I encountered the following error: "-bash: ionic: command not found"

Today, I encountered an issue while trying to set up Ionic on my system. Despite running the command sudo npm install -g ionic, an error message stating -bash: ionic: command not found keeps popping up whenever I attempt to use any Ionic CLI commands. To ...

What is the method for incorporating opacity into the background color CSS attribute using a Fluent UI color?

Currently, my challenge involves applying opacity to a background color sourced from the fluent UI library, which utilizes Design Tokens. Typically, I would add opacity to a background color like this: background-color: "rgba(255, 255, 255, 0.5)" However ...

Error in Angular 7: Image is not being rendered

Currently, I am working on a project that involves Angular JS. I have been following this example: https://jsbin.com/gumaraz/edit?html,output However, I need to transition this code to Angular 7. I have tried upgrading the code from Angular.js to Angular ...

'Dynamic' styling in Next.js using conditional CSS

I am exploring ways to style elements based on their parameters. I have been searching for terms like "conditional css react" and "implementing conditional styles in react with css". Here is a snippet of my code: e.g. <div class="ChatComponent_ ...

I can't figure out why the option value is being displayed as "2: Object" when printing it. Can someone please clarify

Hey there! Currently, I have a UI built using Angular 5 and TypeScript. In one of my components, I have a reactive form with a select box form control in the view. What I'm trying to achieve is that whenever a different option is selected from the sel ...