Ways to personalize your profile picture input similar to Facebook

Trying to customize my profile picture like the Facebook update design, but encountering issues. I have an external bootstrap CSS file and want it to look like this image: https://i.sstatic.net/QbmIh.png HTML

<div class="user-thumb user-thumb--edit">
    <div class="custom-file">
        <input class="custom-file__input" id="photo" accept="image/*" type="file">
            <label class="custom-file__label" for="photo">
                <img alt="" class="thumb--lg rounded-circle" src="">
            </label>
    </div>
</div>

CSS:

.user-thumb {
    position: relative;
    display: inline-block;
    background: #e9e9e9;
    border-radius: 50%;
}
.user-thumb--edit {
    position: relative;
    margin-bottom: 1rem;
}
.custom-file {
    margin: 0;
    height: auto;
}
.custom-file__input {
    position: absolute;
    opacity: 0;
    visibility: hidden;
    width: 1px;
    height: 1px;
}
.custom-file__label {
    cursor: pointer;
    border: 0;
    text-align: center;
    font-weight: 500;
    font-size: 1rem;
    display: block;
    margin: 0;
    border-radius: 0;
    padding: 0;
    background: transparent;
    position: relative;
}
.user-thumb--edit .custom-file__label::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    text-align: center;
    transition: all 0.15s ease-in-out;
    z-index: 20;
    background: #ffffff url();
    background: 1.4rem auto;
    width: 4.2rem;
    height: 4.2rem;
    border-radius: 100%;
    box-shadow: 0px 6px 6px -3px rgb(0 0 0 / 20%), 0px 10px 14px 1px rgb(0 0 0 / 14%), 0px 4px 18px 3px rgb(0 0 0 / 12%);
}

Answer №1

To achieve the desired effect, adjust the border-radius of the label to be 50% rather than 0. Additionally, include overflow: hidden to hide a portion of the ::before element. It is important to note that the ::before should be defined for the containing div, not the label itself: .custom-file::before.

Example:

.user-thumb {
  position: relative;
  display: inline-block;
  background: #e9e9e9;
  border-radius: 50%;
}

.user-thumb--edit {
  position: relative;
  margin-bottom: 1rem;
}

.custom-file {
  margin: 0;
  height: auto;
}

.custom-file__input {
  position: absolute;
  opacity: 0;
  visibility: hidden;
  width: 1px;
  height: 1px;
}

.custom-file__label {
  cursor: pointer;
  border: 0;
  text-align: center;
  font-weight: 500;
  font-size: 1rem;
  display: block;
  margin: 0;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  position: relative;
  overflow: hidden;
}

.user-thumb--edit .custom-file::before {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  text-align: center;
  transition: all 0.15s ease-in-out;
  z-index: 20;
  background: #ffffff url();
  background: 1.4rem auto;
  width: 4.2rem;
  height: 4.2rem;
  border-radius: 100%;
  box-shadow: 0px 6px 6px -3px rgb(0 0 0 / 20%), 0px 10px 14px 1px rgb(0 0 0 / 14%), 0px 4px 18px 3px rgb(0 0 0 / 12%);
}
<div class="user-thumb user-thumb--edit">
  <div class="custom-file">
    <input class="custom-file__input" id="photo" accept="image/*" type="file">
    <label class="custom-file__label" for="photo">
      <img alt="" class="thumb--lg rounded-circle" src="https://via.placeholder.com/150">
    </label>
  </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

What is the best way to extract a specific data field from an XML tag?

The format of the XML I'm currently handling is as follows: <item> <title>$39.99 and Under Juniors' Swimwear</title> <link>http://www.amazon.com/s/ref=xs_gb_rss_A1RFRNENBWTVO4/?rh=n:1036592,n:!2334084011,n: ...

Enhancing your website with a touch of elegance: horizontal scrolling

I am looking to incorporate an inset shadow to visually indicate that there is additional content available for scrolling. For a clearer understanding, here is a sketch: https://i.sstatic.net/odMPd.jpg Currently, I am utilizing Bootstrap framework for th ...

When multiple checkboxes are selected, corresponding form fields should dynamically appear based on the checkboxes selected. I attempted to achieve this functionality using the select option method

Require checkboxes instead of a selection option and have multiple checkbox options. Depending on the checked checkboxes, different form fields should appear. A submit button is needed. I have included some CSS code, but a more detailed CSS code is requir ...

Leveraging the jQuery click function to toggle elements on a webpage by referencing the current element with the keyword "this

I've been trying to implement a click event that toggles an element unrelated to the selected item's parent or child. I want to utilize "this" because there are multiple elements with the same class where I'd like to apply the same jQuery cl ...

What is the best way to display a background image at the top of a webpage and ensure it fills the entire visible area of the screen?

I'm a beginner in the world of development, and I've been given a challenging task to tackle. The assignment is to create a one-page website with navigation links for 'About Us' and 'Contact Us'. Upon clicking these links, th ...

Finding the Xpath for a checkbox element by identifying the label element following it based on its value

I've been putting in a lot of effort into this issue, but I haven't been able to find a specific answer on StackOverflow or figure it out myself through experimenting with Xpath. I'm still learning, so I apologize if this is a basic problem, ...

The problem of undefined icons in Material UI's Stepper StepLabel

Having some trouble incorporating a custom Step Label Icon within the nodes of the Stepper Component provided by Material UI. I want to add an icon to each circle, similar to what is shown in this Material UI demo: https://i.sstatic.net/WLOcS.png However, ...

The width property is ineffective when used in conjunction with the d3 styling method

My goal is to create bar graphs where the width of each bar represents a person's age. However, I am having trouble applying the width attribute to the bars using the style method in d3 (I checked this by inspecting the elements in the browser). Other ...

When utilizing scoped slots in BootstrapVue, you may encounter an error stating "Property or method 'data' is not defined."

Greetings! I am currently in the process of learning how to utilize BootstrapVue, and I decided to reference an example from the official BootstrapVue documentation. <template> <div> <b-table :fields="fields" :items="items" foot-clone ...

Is it possible to include a class in a 'label' element?

Forgive me if this is a simple question, but I'm curious - is it possible to add a class directly to a 'label' tag without needing to enclose it in a 'span' tag for styling? As I delve into "CSS: The Missing Manual," the book instr ...

Is there a way to retrieve JSON data from a different domain and incorporate it into my own website?

I am attempting to utilize JSON data from "" and display the data on my website. My goal is to extract the JSON field name "Stats" and retrieve the sub-field name '\"v\"'. You can refer to the documentation provided by purpleair here: h ...

Top method for triggering an external JavaScript function through an HTML element's onclick event obtained from an Ajax request

index.php: <html> <head> <script type="text/javascript" src="script.js"></script> </head> <body> <div id="box"></div> <div onclick="getContent()">Open Window</div ...

Creating a Tree Checkbox using jQuery without relying on pre-made plugins

The data structure provided appears to be hierarchical, but I am unsure if it follows the Adjacency list or Nested List model. Regardless, it is relatively simple to gather this hierarchical data. For instance, to retrieve the entire tree, you can use: SE ...

Conceal the "Item Successfully Added to Cart" notification on Woocommerce

Is there a way to eliminate the notification that says "xx product has been added to your cart" at the top of my checkout page? If so, how can I achieve this? I came across a suggestion from someone (link provided below), but unfortunately it didn't ...

Try adding three periods to the ngbind directive

I have a string that looks like this: <a href="#" ng-bind="::MyString | limitTo:40"></a> However, I want to add three dots after the string only if it is longer than 40 characters. Is there a way to achieve this? ...

The feature to select a cell on a Bootstrap table is not functioning as expected

Is there a way to retrieve the Cell value from a Bootstrap table when clicked? I have a method set up, but for some reason, after clicking on the table heading, the tdOnClick() function stops working. It seems to only be functional before clicking on the t ...

What is the best way to implement a gradual decrease in padding as the viewport resizes using JavaScript

My goal is to create a responsive design where the padding-left of my box gradually decreases as the website width changes. I want the decrease in padding to stop once it reaches 0. For instance, if the screen size changes by 1px, then the padding-left sh ...

After utilizing the function, the forward and back arrows are no longer visible

After setting up my slideshow, I encountered an issue where clicking the next or previous buttons caused them to shrink down and turn into small grey boxes. Has anyone experienced this before? This relates to PHP/HTML if ($_SERVER['REQUEST_METHOD&ap ...

Using jQuery, is it possible to retrieve the product name and image dynamically?

I'm currently working on implementing an add to cart functionality using jQuery. When the add to cart button is clicked, the product name and image should be displayed. I can achieve this statically but I need help figuring out how to dynamically retr ...

"Printed documents fail to display underlined text using Bootstrap styling

Why do the codes show underlines on the webpage but not in the browser's print? This code is from the printOrder.blade.php file: <!DOCTYPE html> <html dir="ltr" lang="en"> <head> <meta charset="UTF-8&qu ...