A circle border-radius transforms into an ellipse when used with absolute positioning

I am facing an issue while trying to create a circular shape around a font awesome icon. Whenever I apply position: absolute, the circle distorts and turns into an ellipse.

A similar problem occurs when I try using display: block.

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

For reference, here is an image of what my desired outcome looks like -

https://i.sstatic.net/YsFZp.jpg

<slide class="assessment-score">
  <div class="score-heading pass">
    <span id="score-salutation" class="light">CONGRATULATIONS</span>
    <span id="score-message">YOU HAVE PASSED</span>
    <i class="fa fa-check-circle"></i>
  </div>
  <div class="score-results">
    <span id="score">You have scored 92%</span>
    <button>DOWNLOAD YOUR CERTIFICATE</button>
    <a id="assessment-close"><i class="fa fa-times-circle-o"></i> CLOSE ASSESSMENT</a>
  </div>
</slide>

The CSS code snippet:

slide.assessment-score .score-heading{
  height: 33%;
  background-color: #a8db66;
  border-radius: 5px 5px 0 0;
  color: #ffffff;
  position: relative;
}
slide.assessment-score .score-heading i{
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  font-size: 6em;
  margin-bottom: -30px;
  border-radius: 50%;
  padding: 1rem
  background-color: black;
}

Answer №1

To center a absolutely positioned div horizontally, refrain from using left: 0 and right: 0. Using those properties will actually stretch the div by anchoring one end to the left edge of the container and the other end to the right edge.

To perfectly center an absolutely positioned div, consider the following code snippet:

slide.assessment-score .score-heading i {
    position: absolute;
    left: 50%;
    transform: translate(-50%, 0);
}

For more information on how this technique works, visit: Element will not stay centered, especially when re-sizing screen

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

HTML <section> Order Placement

I am currently facing an issue with the placement of two divs on my html page. I have a navigation bar and another content div, but they are not appearing in the right order. This is how my html structure looks: <html> <body> <div id="navig ...

Using a string array item to add a line break in HTML will be ineffective

Issue Resolved with Updated Code After entering text in the edit text field to be searched on the textview, the text is highlighted in color. However, all line breaks are removed, causing all the text to appear in one sentence. This problem occurs only wh ...

Utilize CSS to break apart text (text = white space = text) and align text in a floating manner, allowing

Is there a way to use CSS to create a white space in the middle of text? Currently, I am manually breaking the text, which is not ideal. I am aware that there is a function that allows the text to end and start in another div, but unfortunately, it is not ...

The vertical scrolling feature will come to a halt once it reaches a specific limit

Check out this website: How can I prevent the vertical scroll from continuing past the orange footer boundary? ...

Initiate automatic speech-to-text conversion using HTML5

Is there a way to begin the speech input session without manually clicking on the microphone icon? Perhaps triggering it on window load or document load event instead of the default click event? <input type="text" id="autoStart" x-webkit-speech /> ...

Are there any CSS attribute configurations that I am overlooking?

Reviewing a colleague's CSS file, I stumbled upon an interesting section. They are a skilled CSS designer, so before jumping to conclusions, I wanted to make sure I am not missing something. In the code snippet below, it seems like they are unintenti ...

What is the process for incorporating a button to the left of the search field?

Is it possible to enhance the search field by adding a button to make it more user-friendly? Below is the code I have been using: <div id="search"> <div class="container"> <h1>Search U.K. house price data</h1> <form c ...

Place 2 images side by side within a row using Bootstrap's grid system

https://i.sstatic.net/RVBpK.png Is there a way to center the images for the 2 app download links within the class="row" section? <div class="container"> <div class="row"> <div class="col-xs-4" style="text-align:right"&g ...

Customizing the layout of div elements with Twitter Bootstrap for a responsive design

Utilizing Bootstrap's responsive style sheet, I have organized 4 squares in divs that span 12 columns - |3|3|3|3|. However, when I access this layout on a mobile browser, it displays as: |12| |12| |12| |12| My desired display format is: |6 ...

Combining selected boxes through merging

Looking to create a simple webpage with the following requirements: There should be 10 rows and 3 boxes in each row. If I select 2 or more boxes or drag a box, they should merge together. For example, if my initial screen looks like this: and then I se ...

Incorporating directional indicators to a Bootstrap 4 table

I'm having trouble aligning Font Awesome sort icons to the right side of a table cell. I've tried using ml-auto but it's not working as expected. What I need help with is getting those arrows aligned properly on the right side of the cell. ...

Unusual Behavior of CSS and JQuery Selectors

As I was working with jquery selectors, I encountered something quite unexpected. This is an example of my HTML: <ul id="unordered-list"> <li> <img src="https://www.google.com/images/srpr/logo4w.png" width="40" height="40"/> ...

How can I ensure that Bootstrap Navbar elements are all aligned in a single line?

https://i.sstatic.net/pkxyI.pngI'm experiencing an issue with my code, and I suspect it might be related to Bootstrap. I've tried using align-items-center but it doesn't seem to work as expected. Changing the display property to inline or in ...

Activate only the content of the parent div in a duplicated list using Javascript

Exploring the world of JavaScript, I am focusing on mastering event listeners and node lists. However, I have hit a roadblock when it comes to the JavaScript syntax for a specific query. My goal is to extract the innerHTML of each button and display it in ...

When you refresh the page, the number of items in the cart displayed on the navbar always shows 0

When using my angular application, I encountered a problem with adding movies to a cart. Although I can successfully add them to the cart and see the correct number of movies reflected in the navbar, upon refreshing the page, the count resets to 0. Here i ...

Fade-in effect applied to images upon exposure

Is there a way to fade in an image based on the percentage scrolled, rather than a set number of pixels? I want my website to be responsive and adjust to all screen resolutions. Or perhaps is there a method to have the image fade in when it enters the fiel ...

ReferenceError: jQuery Tabs cannot find the definition of the $ symbol?

I have been trying to implement tabs in a browser using the code provided in this link. Despite copying the code directly from the example and placing it in an index.html file, I am facing issues. Upon opening the index.html file in Chrome, the tab view is ...

The presence of a Bootstrap addon is resulting in horizontal scrolling on mobile devices within the webpage

I am encountering a peculiar issue with an input-group in my cshtml file which features a Bootstrap addon. The problem arises on mobile devices, where upon focusing on the input field, the page scrolls horizontally to the right, revealing the right margin ...

Difficulty in finding class using Selenium's xpath method

I'm currently engaged in a data scraping project where I'm running a for loop to go through 50 URLs, all of which lead to the same page but with different information. My objective is to extract various data elements and compile them into a CSV f ...

Interactive element for initiating a HTTP request to NodeJS/Express server to trigger a specific function

I currently have a frontend button implemented using nodejs and express for my server-side backend. The button is supposed to trigger a function that controls the Philips Hue API on the backend via an HTTP request. I have experimented with various approac ...