Issue with a responsive CSS circle element that holds an image

I'm struggling to figure out how to create 9 responsive CSS circles in a row, with each circle containing an img tag rather than a background image. The goal is to center the img and resize it based on the size of its parent circle div. These 9 circles should be aligned horizontally within a grid container, occupying individual cells. Notably, the fifth circle at the center should be twice the size of the others.

My approach for the smaller circle containers involves utilizing the following CSS properties:

border: blue 1px solid;
border-radius: 50%;
width: 100%;
height: 0%;
padding-top: 100%;
margin:auto;
overflow: hidden;

This CSS code was adopted from various online tutorials and suggestions presented in different Stack Overflow threads.

The CSS styling applied to the img tag is as follows:

width: 100%;
height: 100%;
object-fit: cover;

Inspired by this tutorial link: https://medium.com/@chrisnager/center-and-crop-images-with-a-single-line-of-css-ad140d5b4a87

However, I am encountering issues with the images not displaying, which I suspect may be due to the padding in the circle containers. I am uncertain about the necessary adjustments needed. Removing the padding and adding height directly to the containers resolves the image display issue, but the circles lose their responsiveness - leading to oval shapes when the page size changes.

Here is a fiddle showcasing the components under discussion: https://jsfiddle.net/jth3rb6m/

Answer №1

The reason why the images are not appearing round is because they are not square in shape.

.friend-cont {
  display: grid;
  justify-content: space-around;
  grid-template-columns: calc(10% - 5px) calc(10% - 5px) calc(10% - 5px) calc(10% - 5px) calc(20% - 5px) calc(10% - 5px) calc(10% - 5px) calc(10% - 5px) calc(10% - 5px);
  grid-column-gap: 5px;
  grid-template-rows: auto;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  margin: auto;
}

.friend-pic {
  border: blue 1px solid;
  border-radius: 50%;
  width: 100%;
  height: auto;
  /* height: 0%; */
  /* padding-top: 100%; */
  margin: auto;
  overflow: hidden;
}

.friend-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-pic {
  border: blue 1px solid;
  border-radius: 50%;
  /* height: 0%; */
  /* padding-top: 100%; */
  margin: auto;
  overflow: hidden;
}
<div class="friend-cont">

  <div class="profile-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </div>

  <div class="friend-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </div>

  <div class="friend-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </div>

  <div class="friend-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </div>

  <div class="friend-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </div>

  <div class="friend-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </div>

  <div class="friend-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </div>

  <div class="friend-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </div>

  <div class="friend-pic">
    <img class="friend-photo" src="https://i.stack.imgur.com/l60Hf.png">
  </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

Angular: Updating image tag to display asynchronous data

Utilizing Angular to retrieve user profile pictures from the backend, specifically Node.js/Express, has been mostly successful. However, there is one issue that I have encountered. The HTML displaying the profile picture does not re-render when the user up ...

Guide on making a prev/next | first/last button functional in list.js pagination

Is there a way to enhance my paginated index by adding prev/next, first/last buttons? I am curious if anyone has implemented these features using List.js. <script src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js&ap ...

The color of the text changes based on its alignment

Utilizing style sheets and attribute selectors, create styles that will change the color of text displayed on the page based on its alignment (e.g. left-aligned text in blue, right-aligned text in green). Additionally, text within h2 tags should have color ...

What is the best way to extract the src attribute from an image tag nested within innerHtml?

In the developer tools, navigate to console and enter: var x= document.getElementsByClassName('ad-area')[0].innerHTML; x returns: '<a href="/members/spotlight/311"><img class="block-banner" src="https://tes ...

How can you correctly include a link to a plain text sitemap file in an HTML document?

Could this code effectively inform Google to index my sitemap (or acknowledge its presence)? <link rel="sitemap" href="./sitemap.txt" type="text/plain" title="Sitemap" /> Google's guidelines allow plain t ...

Chosen link fails to update color

I've successfully implemented a navigation bar that changes the content in the body when each link is selected. Utilizing AJAX for dynamic content changing, I can change the color of menu items on hover but am facing issues with changing the color upo ...

Pass the chosen option to PHP using Ajax within the same webpage, utilizing HTML

My Goal: I am working on a HTML/PHP page that displays the home page of my website. One section on this page is dedicated to highscores, with data retrieved from a database. Users can use a Select box to choose how the highscores are sorted. View the high ...

Focusing solely on a particular category in EJS

I am struggling with this code snippet. HTML: <header<% if ( current.source === 'features' || current.path[0] === 'index' || current.source !== 'customers' ) { %> class="header-white"<% } %>> <div cl ...

How to access bespoke attributes in Scene Builder using JavaFX?

I am on the hunt for a way to designate customizable properties for my custom controls. Jens Deters has already created some fantastic custom controls utilizing fontawesomefx for JavaFX. Once you import the jar files into Scene Builder, you can easily inc ...

Changing the CSS class of the Bootstrap datetime picker when selecting the year

Is there a way to change the CSS style of the Bootstrap datetime picker control so that when selecting years, the color changes from blue to red? I attempted to do this with the following code: .selectYear { background-color:red!important; } However ...

The function of slidetoggle is malfunctioning when clicked

I currently have two dynamic containers with one displaying grouped boxes, quantities, and totals, while the other shows detailed information. Both container values are added dynamically at runtime. By default, the grouping container is displayed on the p ...

Creating HTML tables with PHP for dynamic web content

I am facing a minor issue while displaying my results in tables. Here is the code snippet: <?php //return data if any while ($client = mysqli_fetch_assoc($result)) { //output data form each client //var_dump($client); ?> < ...

Remove the blue outline in Fancybox when clicked

Does anyone know how to remove the default blue outline that appears after opening and closing an image or video in Fancybox 3? It disappears when clicked next to, but I would like to get rid of it completely. Any help is appreciated. https://i.stack.imgu ...

Is it possible to modify the background-image using Typescript within an Angular project?

I have been struggling to change the background image in my Angular project using Typescript. I attempted to make the change directly in my HTML file because I am unsure how to do it in the CSS. Here is the line of code in my HTML file: <div style="ba ...

When the page is loaded, ensure a condition is met before displaying a modal pop-up using AngularJS

Just starting out with AngularJS and looking to implement a modal pop up? I've tried using the modal on button click from the Angular dialog demo tutorial. Now, I want to show the pop up based on a condition when the page loads. The idea of automatic ...

Using jQuery to locate a JavaScript variable is a common practice in web development

I recently created a JSFiddle with buttons. As part of my journey to learn jQuery, I have been converting old JavaScript fiddles into jQuery implementations. However, I seem to be facing a challenge when it comes to converting the way JavaScript fetches an ...

Is it possible to use the same identifier for both the name and id attributes in HTML?

In the world of coding, the "name" attribute is often used in server-side programming to send name/value pairs in requests. On the other hand, the "id" attribute is commonly utilized in client-side programming such as Javascript and CSS. However, both att ...

Is there a way to move a placeholder to a small label in the top left corner when an input field is being used?

I've been searching for functional code, but everything I've tried so far hasn't worked. Does anyone have expertise in creating this animation using React? ...

I am looking to dynamically insert a text field into an HTML form using jQuery or JavaScript when a specific button is clicked

This is my code snippet: <div class="rButtons"> <input type="radio" name="numbers" value="10" />10 <input type="radio" name="numbers" value="20" />20 <input type="radio" name="numbers" value="other" />other </div> ...

Is it possible to retrieve JSON data and display only the entries with positive values in an HTML

I am working on a project that involves fetching JSON API data and displaying it in an HTML table, but only for values above 10. Below is the code snippet along with my JavaScript. I specifically want to exclude negative values and only display positive v ...