I am trying to make a user-information box where there is an avatar and some additional information. I want that avatar to stay on the border of that container, vertically translated as in the example below.
However, as you can see, when I translate the element some part of it becomes invisible, since the content is not "pushed" down. How can I achieve the same result, but properly displaying the image? I tried playing with position: absolute
and top
and bottom
, but I wasn't able to achieve the desired result.
Note: in my app, a div with class="profile-info-container"
is inside a Bootstrap col, that's why width is set to 100%.
Thank you!
.profile-info-container {
background-color: white;
border: 2px solid #7EA2BC;
border-radius: 10px;
margin: 20px 10px;
position: relative;
text-align: center;
min-height: 300px;
height: auto;
width: 100%
}
.profile-info-image {
transform: translateY(-50%) rotate(45deg);
border-radius: 100%;
height: auto;
margin: auto;
width: 50%;
border: 10px solid transparent;
background-size: 100% 100%, 50% 50%, 50% 50%, 50% 50%;
background-repeat: no-repeat;
background-image: linear-gradient(white, white), linear-gradient(60deg, red 36%, red 30%), linear-gradient(120deg, yellow 36%, yellow 30%), linear-gradient(240deg, blue 36%, blue 30%);
background-position: center center, left top, right top, left bottom, right bottom;
background-origin: content-box, border-box, border-box, border-box, border-box;
background-clip: content-box, border-box, border-box, border-box, border-box;
}
.profile-info-image img {
transform: rotate(-45deg);
border: 1px solid #7ea2bc;
border-radius: 100%;
height: 100%;
width: 100%;
}
.half {
width: 50%;
}
<div class="half">
<div class="profile-info-container">
<div class="profile-info-image">
<img src="https://www.ibts.org/wp-content/uploads/2017/08/iStock-476085198.jpg" />
</div>
</div>
</div>