-1

im trying to put my image on the middle top off my box. I'm sorry if this is a stupid question but I'm new to coding and I'm young. I searched on the code, everything's fine except this part. It makes my image is on like the middle mid, a bit on the left which is not what I want. Thanks

.profile img
{
    position: absolute!important;
    left:calc(50% - 60%px)!important;
    border: 10px solid #fff!important;
}

this is what it gives me

3 Answers3

0

Try using Flexbox containers. Using justify-content and align-items, you should be able to put your image at the top center of your div without using absolutes. The W3 links show examples of both properties--combine them and you should achieve your desired result.

0
  1. Using margin:auto (by making img tag as display:block)

div {background: yellow; height: 400px;}
img {border-radius:50%; margin:auto;display:block;}
<div class="wrapper">
  <img src="https://picsum.photos/100" />
</div>
  1. Using Flexbox

div {background: yellow; height: 400px; display: flex; justify-content:center;}
img {height: 100px; border-radius: 50%;}
<div class="wrapper">
  <img src="https://picsum.photos/100" />
</div>
Deadpool
  • 6,416
  • 5
  • 32
  • 64
0

This will also help;

.profile{
  position:relative; /* set whatever height and width to this div */
}

.profile img{
    position: absolute;
    left:50%;
    top:50%;
    transform:translate(-50%,-50%);
    border: 10px solid #fff;
}
Imran Rafiq Rather
  • 5,459
  • 1
  • 9
  • 30