I'm trying to design a profile image shape just like this
but my code given me the following design
I'm worried about the white space inside the border and the shape here is code
.doctor-profile-photo {
width: 210px;
height: 210px;
border-radius: 60px/140px;
border: 5px solid #000;
box-shadow: 0px 2px 5px #ccc;
}
.doctor-profile-photo img {
width: 100%;
height: 100%;
border-radius: 60px/140px;
}
<div class="doctor-profile-photo">
<img src="http://weknowyourdreams.com/images/bird/bird-09.jpg" alt="">
</div>
This gives pretty similar output to what you want. Try tweaking the values of border-radius and height-width to achieve exactly what you want.
<style>
#pic {
position: relative;
width: 130px;
height: 150px;
margin: 20px 0;
background: red;
border-radius: 50% / 10%;
color: white;
text-align: center;
text-indent: .1em;
}
#pic:before {
content: '';
position: absolute;
top: 10%;
bottom: 10%;
right: -5%;
left: -5%;
background: inherit;
border-radius: 5% / 50%;
}
</style>
<div id="pic"></div>
Here's a useful link : https://css-tricks.com/examples/ShapesOfCSS/
SVg path and pattern
You can create your shape with a single path. I used a quadratic Bezier curve.
Path MDN
I added an image to the svg using a image tag and pattern tag.
This is then using inside the path with this fill="url(#img1)".
The defs tag is used to hide elements we are not using directly.
<svg viewBox="0 0 100 100" width="400px" xmlns="http://www.w3.org/2000/svg">
<defs>
<pattern id="img1" patternUnits="userSpaceOnUse" width="400" height="400">
<image xlink:href="http://lorempixel.com/400/400/" x="0" y="0" width="100px" height="100px" />
</pattern>
</defs>
<path d="M15,15 Q 50,0 85,18 100,50 85,85 50,100 18,85 0,50 15,15Z" fill="url(#img1)" />
</svg>
Related
I want to draw these shapes using CSS and I'm having a bit of trouble
I'm trying the way above:
CSS:
.menu-animation{
border-radius: 50%;
display: inline-block;
height: 40px;
width: 40px;
background-color: #000000;
position: relative;
left: 0px;
}
.menu-animation2{
border-radius: 50%;
display: inline-block;
height: 29px;
width: 23px;
background-color: #000000;
position: absolute;
left: 9px;
top: 26px;
}
If you really want a CSS only solution, you can create black circles with your border-radius: 50%; approach, combine them with a black rectangle and simulate the round cut-out on both sides with white circles. This is how it works:
The single circle elements can be created using the pseudo elements ::before and ::after. With some positioning, the circles position can be adjusted properly.
This is a working example:
.drop {
background: black;
margin: 40px;
height: 20px;
width: 14px;
position: relative;
z-index: 10;
}
.drop::before,
.drop::after {
content: '';
position: absolute;
background: black;
border-radius: 50%;
}
.drop::before {
width: 30px;
height: 30px;
top: -25px;
left: -7px;
}
.drop::after {
width: 20px;
height: 20px;
top: 10px;
left: -3px;
}
.gaps::before,
.gaps::after {
content: '';
position: absolute;
background: white;
border-radius: 50%;
z-index: 10;
}
.gaps::before {
width: 22px;
height: 22px;
top: -3px;
left: -21px;
}
.gaps::after {
width: 22px;
height: 22px;
top: -2px;
left: 13px;
}
<div class="drop">
<div class="gaps"></div>
</div>
Although this is nearly perfect, I would recommend using SVG for this problem, as you can create a smooth outline and you don't have to bother with positioning, sizes and responsive design.
This would be extremely difficult using CSS but there are other solutions. You can attempt to draw them using JavaScript and the HTML5 Canvas element. Or the easier solution would be to create the illustration in a program like Adobe Illustrator, export the image as an SVG file. Get the SVG code from the file (Adobe Illustrator does that for you), it is basically contains the path of the vector. You can then add all the information in an SVG HTML tag and view the element. CSS then allows you to interact with the SVG element.
If you can live with SVG you can do it like this, even animated:
var circle2 = document.getElementById('circle2');
setInterval(function() {
circle2.style.transition="unset";
circle2.style.transform = "translate(0, 0)";
setTimeout(function() {
circle2.style.transition="transform 1400ms ease-in";
circle2.style.transform = "translate(0, 230px)";
}, 0);
}, 1400);
<div style="overflow: hidden">
<svg viewBox="0 0 200 200" width="200" height="200">
<defs>
<filter id="goo-filter">
<feGaussianBlur stdDeviation="8" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" />
</filter>
</defs>
<g fill="black" filter="url(#goo-filter)">
<circle id="circle1" cx="100" cy="40" r="20" />
<circle id="circle2" cx="100" cy="40" r="12" />
</g>
</svg>
<div>
This question already has an answer here:
How to cut a circular part from an image?
(1 answer)
Closed 3 years ago.
I have a simple user profile image, and a green state indicator.
I want to add a transparent border to the indicator, which surpasses the image in the background, like the image below.
It's easy when the background is a single color, I just have to add a border with the same color, but what to do when the background is a gradient or an image for example? If I add a white border, it looks like the image in the middle, and I would like to have a render like the right image.
How to achieve that ?
.user {
display: inline-block;
position: relative;
}
img {
width: 75px;
height: 75px;
border-radius: 75px;
}
.user-state {
position: absolute;
top: 4px;
right: 4px;
width: 15px;
height: 15px;
border-radius: 10px;
background: #57d642;
}
<body>
<div class="user">
<img src="http://lorempicsum.com/up/255/200/5" alt="">
<div class="user-state"></div>
</div>
</body>
I would consider SVG and mask like below:
.user {
display: inline-block;
position: relative;
}
svg {
width: 200px;
height: 200px;
}
.user:after {
content: "";
position: absolute;
top: 18px;
right: 18px;
width: 40px;
height: 40px;
border-radius: 50%;
background: #57d642;
}
body {
background: linear-gradient(to right, pink, purple);
}
<div class="user">
<svg viewbox="0 0 200 200">
<defs>
<mask id="hole">
<rect width="100%" height="100%" fill="white"/>
<!-- This circle is your hole on the top -->
<circle r="28" cx="162" cy="38" fill="black"/>
</mask>
<!-- the clipath will replace border-radius -->
<clipPath id="circle">
<circle cx="100" cy="100" r="100" fill="white" />
</clipPath>
</defs>
<image width="200" height="200" xlink:href="https://picsum.photos/id/1003/200/200" mask="url(#hole)" clip-path="url(#circle)"/>
</svg>
</div>
Border: ?px
Border-color: rgba(255,255,255,0)
Hi i have a HTML polygon, this is my code :
<div class="full-background">
<div class="diag">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 10" preserveAspectRatio="none">
<polygon points="100 0 100 10 0 10" />
</svg>
<img src="assets/img/downarrow.png" alt="" />
</div>
</div>
This produces :
I actually want this the other way around, so that the black section is blue and the blue section is transparent. I cant find a way at all to edit the color of the black section i have even tried changing the bodys bg-color.
Here is my css:
.diag {
position: absolute;
bottom:0;
width:100%;
}
svg {
display: block;
width: 100%;
height: 20vh;
background: #38aae1;
}
img {
height: 50px;
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
margin: auto;
background: #ef7d00;
border-radius: 50%;
padding: 10px;
}
Can anyone help? Thanks.
Add fill property to polygon and change the background of svg to transparent.
Have a look at the snippet below (use full screen for better view, ignore placeholder image of arrow):
.diag {
position: absolute;
bottom:0;
width:100%;
}
svg {
display: block;
width: 100%;
height: 20vh;
background: transparent;
}
svg polygon {
fill: #38aae1;
}
img {
height: 50px;
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
margin: auto;
background: #ef7d00;
border-radius: 50%;
padding: 10px;
}
<div class="full-background">
<div class="diag">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 10" preserveAspectRatio="none">
<polygon points="100 0 100 10 0 10" />
</svg>
<img src="http://placehold.it/10x10" alt="" />
</div>
</div>
Hope this helps!
Set the polygon fill to the blue color and set the svg background to black in css:
svg{
background: black;
}
and your svg:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 10" preserveAspectRatio="none">
<polygon points="100 0 100 10 0 10" fill="#38aae1"/>
</svg>
How to transform block in CSS? Pseudo-elements is need or not? I try to create block look like block on the picture below. I can't create such block as on the picture below.
This is my code:
.transform_items {
width: 40%;
height: 80px;
position: relative;
margin: 0 auto;
perspective: 600px;
margin-top: 150px;
left: 50px;
}
.block,
.block::before{
display: block;
position: absolute;
margin: 0 auto;
}
.block {
border: 5px solid transparent;
width: 350px;
height: 60px;
}
.block::before {
content: '';
border: 5px solid #52B352;
transform: rotateY(30deg);
top: -5px;
right: -5px;
bottom: -5px;
left: -35px;
}
.block a {
font-size: 24px;
}
<div class="transform_items">
<div class="block"><a>Block</a></div>
</div>
The expected result:
If you can use SVG (1), it could be like this
codePen
svg #block {
stroke: orange;
fill: none;
stroke-width: 5
}
svg text {
font-size: 25px
}
<svg version="1.1" x="0px" y="0px" width="274px" height="84px" viewBox="0 0 274 84">
<polygon id="block" points="33,13 245,24 245,60 29,64 " />
<text x="100" y="50">BLOCK</text>
</svg>
You can also save the svg code as a .svg file,without the text element, and use it as background-image for the div that contains your text
Read this to learn how to use svg in different ways: https://css-tricks.com/using-svg/
(1) Browser support for SVG is a little better than browser support for transform, caniuse: SVG
I've been trying to create a an 'inside curved box' with no success, I don't seem to find any example online. Can anyone help me to replicate that using just CSS or maybe SVG?
Given that the shape background is a solid color and the page background is not, you can create the shape using a pseudo-element and a box-shadow with high spread radius. Its a hackish solution but would work on most browsers as box shadow has good support.
div{
position: relative;
height: 300px;
width: 150px;
border-radius: 12px;
overflow: hidden;
}
div:after{
position: absolute;
content: '';
height: 30px;
bottom: -15px;
width: 100%;
left: 0px;
box-shadow: 0px 0px 0px 500px blue;
border-radius: 12px;
}
body{
background: linear-gradient(chocolate, brown);
height: 100vh;
}
<div class='shape'></div>
You can also achieve the same effect using SVG path elements like in the below snippet.
div {
height: 300px;
width: 150px;
}
svg path {
fill: blue;
}
body {
background: linear-gradient(chocolate, brown);
height: 100vh;
}
<svg viewBox='0 0 150 300' height='0' width='0'>
<defs>
<g id='shape'>
<path d='M0,12 A12,12 0 0,1 12,0 L138,0 A12,12 0 0,1 150,12 L150,300 A12,12 0 0,0 138,288 L12,288 A12,12 0 0,0 0,300z' id='fill' />
</g>
</defs>
</svg>
<div class='shape'>
<svg viewBox='0 0 150 300' preserveAspectRatio='none' vector-effect='non-scaling-stroke'>
<use xlink:href='#shape' />
</svg>
</div>