Circle with transparent borders over background - html

How can I achieve such a thing in CSS?
I've tried so many ways but the dark background is still in the way and can't be clipped so the background image under it's invisible...
.item {
position: relative;
}
.item:before {
content: '';
size(100%);
top: 0;
left: 0;
z-index: 1;
background: rgba(0, 0, 0,0 0.1);
}
<div class="item">
<img>
<span class="rate">
<span class="amount">10</span> امتیاز
</span>
</div>
I'm looking for a way to be able to make parts of the dark background transparent, so the image can be seen.

This can be achieved using a radial gradient, (Example split onto separate lines to make it easier to read)
background-image: radial-gradient(
/* Position the circle at the center, 40px from the top */
circle at center 40px,
/* The center of the radius should be dark */
rgba(0,0,0,0.4) 0%,
/* This is the inner edge of the circle, we transition from dark-transparent between pixels 30 and 31 */
rgba(0,0,0,0.4) 30px, rgba(0,0,0,0) 31px,
/* This is the outer edge of the circle, we transition back from transprent-dark between pixels 34 and 35*/
rgba(0,0,0,0) 34px, rgba(0,0,0,0.4) 35px,
/* Everything outside of the circle should be dark */
rgba(0,0,0,0.4) 100%
);
Where circle at center 40px defines the position of the circle relative to the parent element (Horizontally centred, an 40px down from the top) bare in mind this is the position for the centre of the circle so you do need to account for it's radius.
And we use very small steps between the gradient to make it look like a solid line rather than a blurred gradient (I find that a 1px difference helps prevent aliasing on the line and makes everything look much smoother)
You can adjust the size of the circle or the thickness of the line by changing the 30px, 31px, 34px and 35px values in the gradient.
Working example:
.item {
position: relative;
width: 200px;
height: 200px;
background: url(https://picsum.photos/seed/picsum/200/200);
}
.item:before {
position: absolute;
content: '';
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1;
/* This is the ring itself, you can adjust it's size using the pixel values, leaving 1px differnce usually leaves the best result for smooth edges */
background-image: radial-gradient(circle at center 40px, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0.4) 30px, rgba(0, 0, 0, 0) 31px, rgba(0, 0, 0, 0) 34px, rgba(0, 0, 0, 0.4) 35px, rgba(0, 0, 0, 0.4) 100%);
}
<div class="item"></div>
(This method is browser compatible with pretty much every browser released since 2010)

Infinite box-shadow with overflow: hidden; I don't know if it would work for you, I just tried-
<style>
.item img {
max-width: 100%;
vertical-align: top;
}
.item {
font-family: 'Amiri', serif;
width: 300px;
margin: 20px auto;
overflow: hidden; /* STEP-1 */
position: relative;
}
.rate {
position: absolute;
width: 100px;
height: 100px;
border-radius: 100%;
background: rgba(0,0,0,.7);
top: 80px;
left: 50%;
transform: translatex(-50%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 22px;
color: #fff;
}
.rate::before {
position: absolute;
content: '';
width: calc(100% + 10px);
height: calc(100% + 10px);
top: -5px;
left: 50%;
transform: translatex(-50%);
border-radius: 100%;
box-shadow: 0 0 0 100vh rgba(0,0,0,.7); /* STEP-2 */
}
.amount {
font-size: 20px;
font-weight: 700;
display: block;
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Amiri:wght#400;700&display=swap" rel="stylesheet">
<div class="item">
<img src="https://images.pexels.com/photos/4888690/pexels-photo-4888690.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" alt="Card title">
<span class="rate">
<span class="amount">١٠</span> امتیاز
</span>
</div>

You could use a few divs with position: absolute:
body {
margin: 0;
}
.container {
display: flex;
justify-content: center;
align-items: center;
}
.bg {
height: 100vh;
width: 100%;
background-image: url('https://i.ytimg.com/vi/fqumdSlyLxg/maxresdefault.jpg');
filter: brightness(0.4);
}
.circle {
position: absolute;
height: 150px;
width: 150px;
border-radius: 50%;
backdrop-filter: brightness(5);
-webkit-backdrop-filter: brightness(5);
z-index: 0;
}
.inner-circle {
position: absolute;
height: 142px;
width: 142px;
border-radius: 50%;
backdrop-filter: brightness(0.2);
-webkit-backdrop-filter: brightness(0.2);
z-index: 1;
}
.rate {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-evenly;
position: absolute;
height: 142px;
color: white;
z-index: 2;
}
.amount {
font-size: 30px;
border-radius: 50%;
text-shadow: 0px 0px 5px #fff;
}
<div class="container">
<div class="bg"></div>
<div class="circle"></div>
<div class="inner-circle"></div>
<div class="rate">
<span class="amount">10</span>
<span class="amount">امتیاز</span>
</div>
</div>
Use the backdrop-filter property to set the brightness and display: flex on the container to center everything, then for the text use text-shadow to make it luminous.

As an alternative, I made .item and its child elements Flexbox containers for easy positioning.
The circle is simply a circular element with a border.
All you have to do now is fiddle with sizes, colors and tranparency.
For the fun of it I added some :hover effects...
snippet with comments
/* All are FBL containers, for easy positioning */
.item, .item>*, .rate {
display: flex;
justify-content: center; align-items: center;
}
.rate { flex-direction: column }
/* item content */
.item {
position: relative; /* position child elements to this parent */
width: 400px;
height: 600px;
/* set image to background of item */
background-image: url("https://i.ytimg.com/vi/fqumdSlyLxg/maxresdefault.jpg");
background-repeat: no-repeat;
background-size: cover; /* clip/stretch when too large/small */
background-color: rgba(0,0,0,0.3); /* some tranparent black */
background-blend-mode: overlay; /* mix bg-color with image */
/* eye-candy */
margin: 5rem auto; /* center */
font-size: 1.5em;
font-weight: bold;
color: rgba(255,255,255,.6);
border-radius: 12px;
}
.item>* {
position: absolute; /* position child inside parent */
width : 100px; height: 100px;
opacity: 0.7;
}
.rate { text-shadow: 0px 0px 7px rgba(255,255,255,.8) }
.circle {
border: 5px solid rgba(255,255,255,.3);
border-radius: 50%;
filter: blur(1px);
}
/******************************/
/* HOVER eye-candy, demo only */
/******************************/
.item:hover {
background-blend-mode: normal;
color: rgba(255,255,255,1);
}
.item:hover>* {
opacity: 1;
}
.item:hover .circle {
border-color: rgba(255,255,255,.8);
}
/* demo eye-candy */
.item {
/* GMC elevation 1dp */
box-shadow: 0px 2px 1px -1px rgba(0,0,0,.20),
0px 1px 1px 0px rgba(0,0,0,.14),
0px 1px 3px 0px rgba(0,0,0,.12);
}
.item:hover {
transform: scale(1.01);
/* GMC elevation 3dp */
box-shadow: 0px 3px 3px -2px rgba(0,0,0,.20),
0px 3px 4px 0px rgba(0,0,0,.14),
0px 1px 8px 0px rgba(0,0,0,.12);
}
/*.item:active:not(:focus) { transform: scale(1) }/* enable for some animation */
<div class="item">
<div class="circle"></div>
<div class="rate">
<span class="amount">10</span>
<span>text</span>
</div>
</div>

Related

Can you put 2 circles inside of one Button [duplicate]

This question already has answers here:
Circle with two borders
(4 answers)
Closed 7 months ago.
I want to make a 1€ coin with CSS but I have the problem that I can't give it it's characteristic shape consisting of two circles. I don't want to use multiple divs for making the two circles because I want to have it as a Button. Is there any way to put 2 different shapes in one button tag or are you forced to use divs?
Here is my failed attempt at trying to do so:
.btnCircle1 {
height: 50px;
width: 50px;
border-radius: 50%;
background: red;
z-index: 100;
}
.btnCircle2 {
height: 100px;
width: 100px;
border-radius: 50%;
background: blue;
z-index: 1;
}
<button type="button" class="btnCircle1 btnCircle2"></button>
.btnCircle {
/* here just change one value, to change the other automatically */
/* for example you can use a responsive unit (that change often) like `vw` and the other element will automatically changed automatically */
--bigCirle-Height: 100px;
height: var(--bigCirle-Height);
width: var(--bigCirle-Height);
/* is always a perfect circle */
border-radius: var(--bigCirle-Height);
border: none; /* Remove default borders */
/* add this to make the ::before works */
position: relative;
}
.btnCircle::before {
/* change this value 1 means bigger, the smaller is the number (for example 0.7) the yellow circle is smaller */
/* using css variables and calculations the money it will be always responsive to the parent height */
--smallCirle-Height: calc(var(--bigCirle-Height) * 0.7);
content: '1€';
height: var(--smallCirle-Height);
width: var(--smallCirle-Height);
border-radius: var(--smallCirle-Height);
background: yellow;
/* this two lines will center the circle */
/* inset is like writing top: 50%, left: 50% */
inset: 50%;
transform: translate(-50%, -50%);
/* center the text inside circle */
display: grid;
place-content: center;
/* positioning absolutely */
position: absolute;
}
<button type="button" class="btnCircle"></button>
as A Haworth mentioned you, one way is using the before/after pseudo elements
here's an example:
.btnCircle {
position: relative;
border: none;
padding: 45px;
border-radius: 50%;
background: red;
}
.btnCircle::after {
position: absolute;
inset: 10px;
content: '';
background: blue;
border-radius: 50%;
}
<button class="btnCircle"></button>
One you can use background and border.
/*With background and border css start*/
.btnCircle1 {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
width: 85px;
color: white;
background-color: blue;
border: 15px solid red;
border-radius: 100%;
}
/*With background and border css end*/
/*With pesudo element css start*/
.btnCircle1-psd {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
width: 50px;
color: white;
}
.btnCircle1-psd::before,
.btnCircle1-psd::after {
content: "";
position: absolute;
top: 0;
left: 0;
display: inline-block;
height: 50px;
width: 50px;
border-radius: 50%;
background: red;
z-index: -1;
}
.btnCircle1-psd::after {
transform: scale(0.8);
background-color: blue;
}
/*With pesudo element css end*/
/*With radial gradient background color start*/
.btnCircle1-bg {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
height: 85px;
width: 85px;
color: white;
border-radius: 100%;
background: rgb(255, 0, 0);
background: radial-gradient(circle, rgba(255, 0, 0, 1) 50%, rgba(0, 160, 255, 1) 50%);
}
/*With radial gradient background color end*/
/*With box inset shadow color start*/
.btnCircle1-shadow {
position: relative;
background: red;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
height: 85px;
width: 85px;
color: white;
border-radius: 100%;
-webkit-box-shadow: inset 0px 0px 0px 10px blue;
box-shadow: inset 0px 0px 0px 10px blue;
}
/*With box inset shadow color end*/
<h1> With background and border</h1>
<button type="button" class="btnCircle1">1$</button>
<h1> With radial gradient background color</h1>
<button type="button" class="btnCircle1-bg">1$</button>
<h1> With box inset shadow color</h1>
<button type="button" class="btnCircle1-shadow">1$</button>
<h1>With pesudo element <strong>before</strong> and <strong>after</strong>.</h1>
<button type="button" class="btnCircle1-psd">1$</button>

Div is smaller than the content of the Div

I've a DIV, with a button inside. Under this DIV, I've a hr, but the hr isn't under the button. I could make the DIV height bigger, but I don't know how high the button is (it depends on the browser). Can I style the DIV, that all things, which are in the code under the DIV, on the website also under the DIV are? I show below my HTML and the CSS code, and a screenshot from the result.
body {
min-height: 100vh;
}
/* centering the div that is supposed to take all content */
#center {
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}
#wrapper {
background: rgba(255, 255, 255, 0.1);
border-radius: 50px;
box-shadow: -1px 0px 20px 0px rgba(0, 0, 0, 1);
height: 75vh;
padding: 50px;
width: 75vh;
}
hr {
border-style: none;
border-top: 1px solid black;
}
#output {
display: inline-block;
}
/* make button sit on the right side */
#copy {
float: right;
}
<div id="center">
<div id="wrapper">
<div id="top">
<div id="output"></div>
<div id="copy"><button>kopieren</button></div>
</div>
<hr>
</div>
</div>
Is your problem that you want the hr to be placed under the button? Then, applying a width: 100% to it could be a solution. But it depends on the final result you're looking for.
* {
font-family: sans-serif;
color: white;
}
/* Schriftart (Sansserif), Weiss */
body {
background-image: url(img.jpg);
background-position: center;
background-size: cover;
min-height: 100vh;
}
/* positioning background image */
#center {
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}
/* centering the div that is supposed to take all content */
#wrapper {
backdrop-filter: blur(10px);
background: rgba(255, 255, 255, 0.1);
border-radius: 50px;
box-shadow: -1px 0px 20px 0px rgba(0, 0, 0, 1);
height: 75vh;
padding: 50px;
width: 75vh;
}
hr {
border-style: none;
border-top: 1px solid black;
width: 100%;
}
#output {
display: inline-block;
}
#copy {
float: right;
}
/* make button sit on the right side */
button {
background-color: rgb(132, 60, 116);
border: none;
padding: 8px;
border-radius: 10px;
}
<div id="center">
<div id="wrapper">
<div id="top">
<div id="output"></div>
<div id="copy"><button>kopieren</button></div>
</div>
<hr>
</div>
</div>
Just add
#top {
display: flex;
flex-direction: column;
}
Here is the result
* {
font-family: sans-serif;
color: white;
}
/* Schriftart (Sansserif), Weiss */
body {
background-image: url(img.jpg);
background-position: center;
background-size: cover;
min-height: 100vh;
}
/* positioning background image */
#center {
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}
/* centering the div that is supposed to take all content */
#wrapper {
backdrop-filter: blur(10px);
background: rgba(255, 255, 255, 0.1);
border-radius: 50px;
box-shadow: -1px 0px 20px 0px rgba(0, 0, 0, 1);
height: 75vh;
padding: 50px;
width: 75vh;
}
hr {
border-style: none;
border-top: 1px solid black;
}
#output {
display: inline-block;
}
#copy {
float: right;
}
/* make button sit on the right side */
button {
background-color: rgb(132, 60, 116);
border: none;
padding: 8px;
border-radius: 10px;
}
#top {
display: flex;
flex-direction: column;
}
<div id="center">
<div id="wrapper">
<div id="top">
<div id="output"></div>
<div id="copy"><button>kopieren</button></div>
</div>
<hr>
</div>
</div>

How to overlay transparent text on an image with a dark overlay background on hover?

Title is a bit of a mouthful. I've just started with CSS and am trying to achieve the effect a text overlay while the image is still transparent behind the text.
Below is what I've managed to achieve by snipping together various bits of code I've found. I am struggling to get the dark overlay the same size as the image. I haven't used any margin or padding on the overlay or image so have no clue why it's happening. I've also tried several ways to align the text so it sits vertically in the middle but have had no such luck.
.image-container {
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
}
.border {
border-radius: 50%;
}
.image-container .after {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
display: none;
color: #FFF;
border-radius: 50%;
}
.image-container:hover .after {
display: block;
background: rgba(0, 0, 0, .6);
border-radius: 50%;
}
#title {
background: url('https://bopepor.es/wp-content/uploads/2018/08/Logo-200x200PX.png');
background-size: cover;
color: #fff;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
padding: 0;
display: flex;
}
h1 {
font-size: 80px;
font-family: sans-serif;
text-align: center;
text-shadow: 0 0 1px rgba(0, 0, 0, .1);
margin: 0;
padding: 0;
letter-spacing: -1px;
line-height: 0.8;
}
<div class="image-container">
<img src="https://bopepor.es/wp-content/uploads/2018/08/Logo-200x200PX.png" class='border' />
<div class="after">
<div id="title">
<h1><b>ONE<br>TWO</b></h1>
</div>
</div>
</div>
For the first issue You will not able to center the overlay on to the image because the image isn't actually 200px x 200px because there are transparent pixels around the image. so first crop the transparent pixels around the image and get it's real size. Then replace the 200px size in the css below to the appropriate size.
I have corrected your code snippet to be able to center the text by adding display: flex and align-content: center (for vertical alignment) and justify-content: center(for horizontal alignment),
I have also added overflow: hidden to the .image-container .after to prevent overflowed text and changed the text size to 60px for better visibility.
.image-container {
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
}
.image-container .after {
position: absolute;
display: none;
left: 0;
bottom: 0;
overflow: hidden;
color: #FFF;
}
.image-container:hover .after {
display: flex;
background: rgba(0, 0, 0, 0.6);
border-radius: 50%;
border-width: 0px;
width: 200px;
height: 200px;
}
#title {
background: url('https://bopepor.es/wp-content/uploads/2018/08/Logo-200x200PX.png');
background-size: cover;
color: #fff;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
padding: 0;
display: flex;
align-content: center;
justify-content: center;
width: 100%;
}
h1 {
font-size: 60px;
font-family: sans-serif;
text-align: center;
text-shadow: 0 0 1px rgba(0, 0, 0, .1);
margin: 0;
padding: 0;
display: flex;
align-items: center;
letter-spacing: -1px;
line-height: 0.8;
}
<div class="image-container">
<img src="https://bopepor.es/wp-content/uploads/2018/08/Logo-200x200PX.png" class='border' />
<div class="after">
<div id="title">
<h1><b>ONE<br>TWO</b></h1>
</div>
</div>
</div>

Anchor fails to activate in flexbox item

I have a flex container holding multiple items. I am setting the flex item class inside the anchor tag and trying to enable a link to work when a user clicks the anchored element.
The element is a 3 stage div... the first div is a circle with an icon, the "second" div (if you want to call it a second div...) loads the ::before psuedo element that loads some dimensionality to the circle. and the third div is a text item that appears when the item is hovered.
The issue is that when you hover over the element i am not able to click the follow on link. My guess is the anchor is being covered by the divs.
I have attempted setting z-index's across elements but cant seem to get the anchor to expose itself
HTML:
<div class="flex_row">
<a class="flex_col" src="http://www.cnn.com">
<div class="circle_shape">
<i class="fas fa-sitemap"></i>
<div class="circle_text">
<p>CNN IS A TERRIBLE NEW SOURCE!</p>
</div>
</div>
<div>
<h2>CNN SUCKS</h2>
</div>
</a>
</div>
CSS:
.flex_col{
flex: 1;
margin: 10px;
}
.circle_shape {
position: relative;
display: flex;
padding: 50% 0;
border-radius: 50%;
overflow: hidden;
border: 1px solid gray;
font-size: 16px;
font-family: 'Source Sans Pro', sans-serif;
justify-content: center;
align-items: center;
background: radial-gradient(circle at 50% 120%, #81e8f6, #76deef 10%, #055194 80%, #062745 100%);
}
.circle_shape:before {
content: "";
position: absolute;
top: 1%;
left: 5%;
width: 90%;
height: 90%;
border-radius: 50%;
background: radial-gradient(circle at 50% 0px, #ffffff, rgba(255, 255, 255, 0) 58%);
filter: blur(5px);
z-index: 2;
}
.circle_shape:hover{
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1), 0 1px 2px rgba(0,0,0,0.1);
}
.circle_shape img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.circle_shape i{
position: absolute;
text-align: center;
font-size: 4vw;
text-shadow:
0 0 1px #fff,
0 1px 2px rgba(0,0,0,0.3);
}
.circle_shape h2 {
position: absolute;
bottom: 10%;
font-size: 1vw;
font-weight: 800;
text-align: center;
}
.circle_text{
position: absolute;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0,51,102, 0.9);
border-radius: 50%;
width: 100%;
height: 100%;
overflow: hidden;
opacity: 0;
transition: all 0.4s ease-in-out;
transform: scale(0);
}
.circle_text p {
color: #fff;
padding: 4px;
text-align: center;
font-size: calc(7px + .5vw);
text-shadow:
0 0 1px #fff,
0 1px 2px rgba(0,0,0,0.3);
}
.circle_shape:hover .circle_text{
transform: scale(1);
opacity: 1;
}
fiddle: https://jsfiddle.net/honeynutz/czq9y5fp/4/
I would expect the link in question to load cnn, but instead it does nothing.
The solution is actually very simple and I'm sure you'll kick yourself that you didn't spot it! I'm surprised it took me so long.
The issue is that you're using src on your anchor where you should be using href
More information on HTML Links

box-shadow on angled border :after pseudoelement

So, I've searched for a solution to this, and have had no luck. I need the box-shadow on the parent div to carry through the :after pseudo element.
Currently, the box shadow is still applying like a rectangle instead of following the edge of the border, which renders the angle at the end of the div. You can see what I'm talking about here:
https://codepen.io/thomasjost/pen/XBOjqm
Here's my HTML:
<div class="total-tag">
<h3 class="h-big-dollar-sign">$</h3>
<h1 class="total">13,550</h1>
</div>
SCSS:
.total-tag {
border-radius : 6px 0 0 6px;
background : #EBEDEE;
height : 68px;
width : 15em;
position : relative;
box-shadow: 0 1px 2px 0 rgb(0,0,0);
display: flex;
justify-content: flex-start;
align-content: center;
align-items: center;
&:after {
content : '';
display : block;
position : absolute;
top : 0;
left : 15em;
border-style : solid;
border-color : #EBEDEE transparent transparent transparent;
border-width : 68px 34px 0 0;
box-shadow: 1px 1px 2px 0 rgb(0,0,0);
}
}
.total {
font-size: 38px;
font-weight: 300;
color: #64A31B;
line-height: 1em;
margin-top: 5px;
}
.h-big-dollar-sign {
position: relative;
left: inherit;
top: inherit;
margin-top: 5px;
margin-left: 17px;
font-size: 24px;
}
Any assistance would be greatly appreciated.
you could play with a gradient background to draw bg and simulate the shadow:
&:after {
content : '';
display : block;
position : absolute;
top : 0;
left : calc(15em - 2px);/* minus shadow's width */
bottom : 0;
width :36px;
background: linear-gradient(to bottom right, #EBEDEE 49%, #000 50%, transparent calc(50% + 2px) );/* draw bg and part of slanted shadow */
box-shadow:0px -2px 2px -3px;/* top shadow is to be shawn too, give it a try */
}
DEMO:
.total-tag {
border-radius: 6px 0 0 6px;
background: #EBEDEE;
height: 68px;
width: 15em;
position: relative;
box-shadow: 0 1px 2px 0 black;
display: flex;
justify-content: flex-start;
align-content: center;
align-items: center;
}
.total-tag:after {
content: '';
display: block;
position: absolute;
top: 0;
left: calc(15em - 2px);
bottom: 0;
width: 36px;
background: linear-gradient(to bottom right, #EBEDEE 49%, #000 50%, transparent calc(50% + 2px));
box-shadow: 0px -2px 2px -3px;
}
.total {
font-size: 38px;
font-weight: 300;
color: #64A31B;
line-height: 1em;
margin-top: 5px;
}
.h-big-dollar-sign {
position: relative;
left: inherit;
top: inherit;
margin-top: 5px;
margin-left: 17px;
font-size: 24px;
}
<div class="total-tag">
<h3 class="h-big-dollar-sign">$</h3>
<h1 class="total">13,550</h1>
</div>