Photos that are circle-cropped to be responsive

I have implemented quote boxes on my website that feature a 2-4 line quote, a byline with a description or title/subtitle, and a circularly cropped photo. The photo is positioned at the bottom left of the box using absolute positioning. You can view a simple demonstration in this js fiddle.

In my actual code, I use a SASS mixin to set the circle diameter:

haml

.circle-photo-div{ style: "background: url(#{photo_url})" }

sass

.circle-photo-div
  @include circle-photo(110)
  position: absolute
  bottom: -19%
  left: -7%

@mixin circle-photo($diameter)
  width: #{$diameter}px
  height: #{$diameter}px
  border-radius: #{$diameter / 2.0}px
  -webkit-border-radius: #{$diameter / 2.0}px
  -moz-border-radius: #{$diameter / 2.0}px
  margin: 1em auto
  background-size: cover
  background-repeat: no-repeat
  background-position: center center
  -webkit-border-radius: 99em
  -moz-border-radius: 99em
  border-radius: 99em
  border: 5px solid white
  box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.8)

However, I am facing an issue with making these circle photos responsive when the page size changes. Currently, they do not resize proportionally along with the page content. Any suggestions on how to achieve this functionality so that the circle-cropped photos adjust their size and maintain their relative positioning at the bottom left of the box?

Answer №1

The solution turned out to be vw/vh.

http://css-tricks.com/viewport-sized-typography/

Adjusting the circle dimensions based on percentages would result in ellipses, unless the container's height was equal to its width, which is a rare occurrence (an 80% x 80% circle in a 100px x 200px container would actually be 80px by 160px).

The key was to make the circle diameter dependent solely on the container/window width, utilizing the vw unit. This ensured that the image resized proportionally with the window, preventing distortion into ovals.

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

Using the ternary operator for the background-color style attribute in knockoutjs

How can I apply a background color to a td element in a table only when there is data present? If there is no data, I do not want any color to be displayed. Below is the code I currently have: <td data-bind="text:EarlyOut,style:{background-color:EarlyO ...

Shifting the "active" designation within a dropdown menu to correspond with the user's current page

Recently, I decided to explore the Foundation framework. However, my first stumbling block was figuring out how to use the "active" class in a dropdown menu. I am hoping to have the class applied to the page link that is currently being viewed by the user ...

clearing the input field without affecting the selection tag

I have a container that contains multiple input tags and one select tag, all with the className "contact". In jQuery, I am accessing them using the class name. There is also a checkbox that disables the inputs when checked, and when unchecked, it clears th ...

The "in" class for Bootstrap collapse is not functioning as expected

I am currently experimenting with Bootstrap's collapse class to create a toggle effect for an element when a checkbox is clicked. The initial state of the page should have the checkbox unchecked and the element displayed. Upon clicking the checkbox, t ...

Instructions for activating the click function for each individual looping image

When creating a blog page, I am using PHP to loop the like button images according to the total count of posts (example: Facebook like button). The issue I am facing is that while the PHP loop is working, when I click on the first post image, only the firs ...

Can someone guide me on replicating this design with Bootstrap?

How do I achieve this layout using Bootstrap? https://i.sstatic.net/Ffvog.jpg I have checked my code but can't seem to find the mistake. Can someone please help me out? <div class="row"> <div class="img-5"> <div class="c ...

The selection box for cities is not filling in with options

I am working on a dynamic city loading feature for a select tag in HTML. After selecting a state, I want to load the cities using an ajax call. While I am successfully logging the returned data to the console, I am struggling with populating the select op ...

Why isn't this code for hiding the animation and displaying it not functioning properly?

Why isn't this animation from display none to block working properly? The initial code appears as follows, and it functions correctly: $(".box_outer").stop().animate({top: '25px' , opacity: 1}, 100); When I add display: none; to the class ...

Using jQuery's .html() method to update the inner HTML of an element can cause the .click() event on a form button to stop functioning

There is a puzzling issue with my HTML form button and jQuery functionality. The button is supposed to trigger a .click() event from a JavaScript file, and it was working perfectly until I used jQuery .html() to replace the main page content with the form ...

What is the best way to refresh a webpage in Vue.js following a specific event or a button click?

Is there a way to reload a webpage only once after clicking a button, without the need for auto-refreshing at set intervals? I've written my code in Vue.js. Can anyone offer guidance on how to accomplish this? Any assistance would be greatly apprecia ...

The hover functionality fails to activate when a z-index is applied

My issue revolves around 2 divs: one containing a link and the other a box-shaped container. The link is set with position:fixed; causing it to fly over the container div. To resolve this, I attempted to assign a negative z-index value to the link, but unf ...

Choosing siblings of a particular element that meet certain criteria

I am faced with the following situation: <table> <tr class="header"> <tr class="data1"> <tr class="data2"> <tr class="data3"> <tr class="header"> <tr class="data1"> <tr class="data2"> </tabl ...

Innovative Double Navigation Menu Dropdown Utilizing Bootstrap 4.5

Need Help with Bootstrap 4.5 Double Navigation Menu Dropdown I'm facing an issue with the 'Reports' submenu not working properly. Any advice would be appreciated. Check out the template here <div class="nav-scroller bg-white shadow- ...

Adjusting the size of a neighboring div to match the width of the audio control component

Looking for a solution with CSS styling: I have a parent div element and two nested div elements, one containing an audio control of unknown length. My query is how to make the first nested div adjust its width based on the audio control. The goal is for ...

Adding the Bootstrap script

I am facing an issue with incorporating a Bootstrap navbar into my page using a PHP function. I have already included the Bootstrap CSS file, but now I also need to add the script for a dropdown menu functionality. When I tried placing the script at the en ...

Align columns to the right and left using Bootstrap

It should be simple enough, but I can't seem to find my mistake. Goal: The entire markup should be centered with a width of col-10. Within the same 10-column width, there should be two divs each taking up 50% of the space. Using Bootstrap 5, for so ...

Incorrect rendering of apostrophes detected

I am currently working on a basic blog using PHP, MYSQL, and HTML. I encountered an issue with displaying apostrophes and quotes on the webpage. Instead of showing "example," it displays \"example\" even though I have used escape strings. Here is ...

Having trouble retrieving the full png image using PhantomJs render command

Currently, I am utilizing PhantomJS to convert an html file into a png image. However, the html file is quite long horizontally and when using PhantomJs to render it as an image, it does not capture the entire length up to the last horizontal scroll. I a ...

Adjust the color of the bootstrap navbar upon resizing the screen

Attempting to modify the background color for the navbar menu items on smaller screen sizes. An issue arises in the following scenario: Browser window is resized until hamburger menu appears Hamburger menu is clicked to display menu i ...

Execute a snippet of code only when the opacity of a div is set to 1

I'm facing a challenge with displaying multiple images on the same page in different groups. Some of these groups have hidden elements with opacity = 0, which are then set to opacity = 1 when they need to be shown. The issue is that all images load a ...