I'm trying to do CSS to make a div that looks like this:
I'm pretty much started with this:
.player {
width: 480px;
height: 80px;
border-radius: 40px;
}
Whats the simplest way to do this, without too much code?
Here's yet another way of doing it, this time using a radial background image. This lets it be transparent and works in both Firefox and Chrome.
.player {
width: 480px;
height: 80px;
border-radius: 40px;
background-image: radial-gradient(circle at 38px 40px, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 40px, blue 40px);
color: #FFF;
}
<div class="player"></div>
You can use the before
pseudo element to provide the "cut out"
.player {
width: 480px;
height: 80px;
border-radius:0 40px 40px 0;
background-color:#0000FF;
position:relative;
color:#FFF;
}
.player:before
{
width: 80px;
height: 80px;
border-radius:0 40px 40px 0;
background-color:#FFF;
display:inline-block;
vertical-align: middle;
margin-right: 10px;
content: '';
}
<div class="player">Some Content</div>
clip-path
: caniuse.com/#feat=css-clip-path & css-tricks.com/almanac/properties/c/clip
.wrapper {
width: 500px;
height: 103px;
background-color: red;
padding-top: 15px;
}
.player {
width: 480px;
height: 83px;
margin-left: 10px;
border-top-right-radius: 40px;
border-bottom-right-radius: 40px;
border: 1px solid black;
border-left: none;
background-color: blue;
-webkit-mask-image: radial-gradient(circle at left, transparent 0, transparent 40px, black 41px);
}
<div class="wrapper"><div class="player"></div></div>
Jon P's answer is almost there - but the before element can be used to make a transparent circle to the left of the main div and a shadow produces the desired cut-out effect.
body {
/* You can change the background colour to verify that this is truly transparent */
background-color: pink;
}
.player {
/* Just a normal box */
width: 480px;
height: 80px;
border-radius:0 40px 40px 0;
background-color:#0000FF;
position:relative;
color:#FFF;
/* Move the box right so that we can see the cutout to the left */
margin-left: 40px;
}
.player:before
{
width: 80px;
height: 80px;
border-radius:0 40px 40px 0;
background-color:transparent;
display:inline-block;
vertical-align: middle;
margin-right: 10px;
content: '';
/* This is the cutout: */
box-shadow: 40px 0px #00f;
position: relative;
left: -80px;
}
<div class="player">Some Content</div>
I was thinking like that too, but I got a better way, I used a svg as a background. It also has the advantage of being more responsive. I will send my problem here to other people who will also have the same question.
* {
padding: 0;
margin: 0;
}
#sidebar {
width: 500px;
height: 100vh;
background: url(https://svgshare.com/i/XiH.svg) center right;
background-size: 150%;
}
<div id="sidebar"></div>