Create a responsive receipt cutoff in css - html

I am trying to make some HTML and CSS look like a receipt. I want the bottom of this receipt to look like it was torn off. I have gotten an ::after style that looks close to what I want, however on mobile devices it is showing up with some weird lines. I need a responsive design that looks good on mobile screen sizes.
Here is the design I am looking for:
Here is my attempt that is showing up with weird lines:
Here is my code I am using:
body {
background: black;
}
.StyledReceipt {
background-color: #fff;
width: 22rem;
position: relative;
padding: 1rem;
box-shadow: 0 -0.4rem 1rem -0.4rem rgba(0, 0, 0, 0.2);
}
.StyledReceipt::after {
background-image: linear-gradient(135deg, #fff 0.5rem, transparent 0),
linear-gradient(-135deg, #fff 0.5rem, transparent 0);
background-position: left-bottom;
background-repeat: repeat-x;
background-size: 1rem;
content: '';
display: block;
position: absolute;
bottom: -1rem;
left: 0;
width: 100%;
height: 1rem;
}
<div class="StyledReceipt">Test</div>

I have a generator for this kind of shapes (https://css-generators.com/custom-borders/) and it works with any background as well. One gradient and no pseudo element needed.
body {
background: black;
}
.StyledReceipt {
background: linear-gradient(45deg,#aaa,#fff);
width: 22rem;
padding: 1rem 1rem 2rem;
--mask: conic-gradient(from -45deg at bottom,#0000,#000 1deg 89deg,#0000 90deg) 50%/30px 100%;
-webkit-mask: var(--mask);
mask: var(--mask);
}
<div class="StyledReceipt">Test</div>
If you want shadow you can do like below:
body {
background: black;
}
.StyledReceipt {
width: 22rem;
padding: 1rem 1rem 2rem;
filter: drop-shadow(0 0 .2rem red); /* update the shadow here */
position: relative;
z-index: 0;
}
.StyledReceipt:before {
content:"";
position:absolute;
z-index:-1;
inset:0;
background: linear-gradient(45deg,#aaa,#fff);
--mask: conic-gradient(from -45deg at bottom,#0000,#000 1deg 89deg,#0000 90deg) 50%/30px 100%;
-webkit-mask: var(--mask);
mask: var(--mask);
}
<div class="StyledReceipt">Test</div>

Related

Can I Fade Out Image With Border-Radius 50%?

So, I'm trying to fade out an image that has border-radius: 50% but I can't seem to get it down.
<section id="main">
<h1>Non-Important-Text</h1>
<h4>
it's all fun and games until you can't find a damn solution....
</h4>
<div id="img-container">
<img src="./assets/1.jpg" />
</div>
</section>
/* ... */
#main #img-container {
border-radius: 50%;
display: inline-block;
position: relative;
}
#main #img-container img {
width: 30em;
border-radius: 50%;
display: block;
border: 1px solid white;
}
#main #img-container img::after {
content: "";
display: block;
background: radial-gradient(
ellipse at center,
rgba(255, 255, 255, 0) 0%,
rgba(255, 255, 255, 1) 100%
); /* This doesn't work! */
border-radius: 50%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
My Image, is circle, and does have a border. But it doensn't get faded out( in a circular way). How can I achieve that
Goal:
What I Get:
I tried everything from, radial-gradient, -webkit-gradient, to even, -webkit-radial-gradient. But they all produce the same result!
you need to use mask-image
div{
background: skyblue;
padding: 20px;
}
img{
-webkit-mask-image: radial-gradient(circle at center, rgba(0,0,0,1) 0, rgba(0,0,0,0) 70%);
mask-image: radial-gradient(circle at center, rgba(0,0,0,1) 0, rgba(0,0,0,0) 70%);
display: block;
margin: 0 auto
}
<div><img src='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBUVFRgREhUSGBgYGBgYGBIYGBgYGBgYGBgZGRgYGBgcIS4lHB4rIRgYJjgmKy8xNTU1GiQ7QDs0Py40NTEBDAwMEA8QGhISHjQrISs0MTQ0NDQxNDQxNDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQxNDQ0NDE0NDQ0NDQ0NDQ0NP/AABEIARMAtwMBIgACEQEDEQH/xAAcAAABBQEBAQAAAAAAAAAAAAACAAMEBQYBBwj/xABBEAACAQIEAwYDBQQIBwEAAAABAgADEQQFEiExQVEGImFxgZETobEyUnLB0SNCkvAHMzRigsLh8RUWQ2OistIU/8QAGAEBAQEBAQAAAAAAAAAAAAAAAAECAwT/xAAhEQEBAAICAwEBAQEBAAAAAAAAAQIRITESQVEDMnFhIv/aAAwDAQACEQMRAD8AvFWOKsSrHFE0jirHAs6BCAgILFaGBOgQAAnbQ7TtoDemIrHLTloDR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S7m4ZbBUybsuo9WJb6wlw6DgiDyUQi0beqFBYmwAuTA4+HQ8UQ+aiRauU4dvtUqfnpEzuJ7Yg1lp01GgtpLnifw3IHhc7b85X5h2lxNnexooD3NaWZ9/s2PE2ubjbaZ2umppZKlNtdB6iH7uosh8CpktcfpYJVspb7DfuMfu35Nw2PHl0nnKdscUP30Pmg/K0fxPbE1UNOtSTfg6cVYcDpa9/EX3F5LvuD0otAZ5nuz2d06iLT13cC1jfV8+I8d+VzLpnmsbuA3eNO8B3jDvKhV6gsRI9GpvaM4ira8hYbFXcjwv7wCxmaCgKtVuAKAeJJtFMv2lrF6opcvtnxNiB+cUgsuzrk0KgJ4OfnaS+zTn49QX20Lt6mcilGkw/GTliigOpO1YooBUuEqu0h7i/iH0MUUuPcY/T+aeyP+q/xH8pPMUUufdXD+YGZ/thVK0GsSLxRTnem481eFjkAYgcjYbk294opPSGAvGNv+kUUkE/IXIxFOx/fT5sB+Z956D2YxDPh1Z2LHUwudzYMwA+UUU1O19LF5FqRRTSK3Gc5UYBz8Rt+Q+sUUCHif7Ufw/rFFFCP//Z' /></div>

CSS - gradient border not working in safari

I am trying to create a custom button with a gradient border. At this point I got the button to work in both Chrome and Firefox.
I have followed an online guide on how to create custom borders with a gradient which are also rounded. The link to the guide can be found here: documentation.
But for some reason the same styling does not work in Safari. I do not know why this is the case.
Here is the CSS code I use in order to create the button. I have also included a snippet with the same style at the bottom. Note that the snippet has a few extra classes and CSS properties just to get it to show properly.
.rainbow-gradient-border {
position: relative;
border-radius: 0.25rem;
box-shadow: 0 2px 10px 0 rgba(142, 57, 255, 0.29);
}
.rainbow-gradient-border::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 0.25rem;
padding: 0.1rem;
background: linear-gradient(
90deg,
#4d3d8f 0%,
#df67ed 23%,
#e24c26 65%,
#f18823 84%,
#3aa6c2 100%
);
-webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
-webkit-mask-composite: destination-out;
mask-composite: exclude;
}
body, .container{
width: 100%;
height: 100%;
background-color: black;
}
.container{
background-color: black;
}
.rainbow-gradient-border {
position: relative;
color: white;
width: 10rem;
display: flex;
justify-content: center;
align-items: center;
border-radius: 0.25rem;
box-shadow: 0 2px 10px 0 rgba(142, 57, 255, 0.29);
}
.rainbow-gradient-border::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 0.25rem;
padding: 0.1rem;
background: linear-gradient(
90deg,
#4d3d8f 0%,
#df67ed 23%,
#e24c26 65%,
#f18823 84%,
#3aa6c2 100%
);
-webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
-webkit-mask-composite: destination-out;
mask-composite: exclude;
}
<div class="container">
<div class="rainbow-gradient-border">
<p>Log In</p>
</div>
</div>
try using -webkit-mask-composite: source-out;
instead of destination-out.
This worked for me and they have the same description on https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-mask-composite
You can achieve this in a more simple way, without using masks. I used this tool to add the prefixes.
body, .container{
width: 100%;
height: 100%;
background-color: black;
color: white;
}
.rainbow-gradient-border {
position: relative;
}
.outie{
display: inline-block;
background: -webkit-gradient(
linear,
left top, right top,
from(#4d3d8f),
color-stop(23%, #df67ed),
color-stop(65%, #e24c26),
color-stop(84%, #f18823),
to(#3aa6c2)
);
background: -o-linear-gradient(
left,
#4d3d8f 0%,
#df67ed 23%,
#e24c26 65%,
#f18823 84%,
#3aa6c2 100%
);
background: linear-gradient(
90deg,
#4d3d8f 0%,
#df67ed 23%,
#e24c26 65%,
#f18823 84%,
#3aa6c2 100%
);
border-radius: 4px;
padding: 2px;
width: 10rem;
border-radius: 0.25rem;
-webkit-box-shadow: 0 2px 10px 0 rgba(142, 57, 255, 0.29);
box-shadow: 0 2px 10px 0 rgba(142, 57, 255, 0.29);
}
.innie{
display:inline-block;
width: 100%;
background: black;
padding: 15px 0px;
text-align: center;
}
<div class="container">
<div class="rainbow-gradient-border">
<span class="outie">
<span class="innie">
Log In
</span>
</span>
</div>
</div>

Divide a rectangle into 2 triangles along diagonal using css

I want to make a div into 2 triangles (as shown in below, no problem if 1 is background of parent) upper one with one color and lower one with another. I dont mind how it is implemented but i want to do it in css (not javascript). I tried with css rotation, (code below), but its not responsive. In smaller or wider screen it is distorted . Any way to implement this in css?
body {
background: #eee;
}
.darker {
position: fixed;
top: -94%;
left: -10%;
width: 150%;
height: 150%;
background: #dd4f39;
-webkit-transform: rotate(30deg);
transform: rotate(30deg);
}
<div class="darker"> </div>
I found an interesting way to do this from here, which uses clip-path
.Answering my own question so that everyone can use it.
html,
body {
margin: 0;
}
body {
background: #eee;
}
.box {
width: 100vw;
height: 100vh;
background-color: #dd4f39;
clip-path: polygon(0 0, 100% 0, 100% 100%);
}
<div class="box"></div>
This is one way of doing it. But this use case is strictly with respect to vw. Just make sure to give the same value to these elements
div and it's pseudo element should have same width and border-left respectively.
div and it's pseudo element should have same height and border-top respectively.
html, body {
margin: 0;
}
.box {
width: 100vw;
height: 100vh;
background-color: white;
}
.box::after {
content: ' ';
border-top: 100vh solid #dd4f39;
border-left: 100vw solid transparent;
width: 0;
position: absolute;
}
<div class="box"></div>
JS fiddle
https://jsfiddle.net/kqsrmrss/2/
You can do that with a skewed pseudo element. The main trick is to keep the aspect ratio the same or else the sloped angle will fail
Fiddle demo
Stack snippet Note 1
body {
background: #eee;
}
.darker {
position: absolute;
top: 0;
left: 0;
width: 100%;
padding-top: 50%;
background: #dd4f39;
overflow: hidden;
}
.darker::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: gray;
transform: skewY(26.5deg);
transform-origin: left top;
}
<div class="darker"></div>
Optionally, you can add media query to control the angle at different screen sizes
Fiddle demo 2
With a tiny script running when window resize's, you can control the angle and make it fully responsive both horizontally and vertically.
Note 1 Based on a comment, the Stack snippet might not work properly, and if, try the fiddle demos.
Please Use this code snippet.
div {
width: 100%;
height: 100px;
}
.diagonalRising {
border: 1pt solid black;
background: linear-gradient(to right bottom, #eeeeee 0%, #eeeeee 49.9%, #eeeeee 50%, #000000 51%, #dd4f39 51.1%, #dd4f39 100%);
}
.diagonalFalling {
background: linear-gradient(to right top, #eeeeee 0%, #eeeeee 49.9%, #000000 50%, #000000 51%, #dd4f39 51.1%, #dd4f39 100%);
}
.diagonalCross {
position: relative;
background: linear-gradient(to right bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 49.9%, rgba(0, 0, 0, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(0, 0, 0, 0) 51.1%, rgba(0, 0, 0, 0) 100%);
}
.diagonalCross:after {
content: "";
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
background: linear-gradient(to right top, #ffffff 0%, #ffffff 49.9%, #000000 50%, #000000 51%, #ffffff 51.1%, #ffffff 100%);
}
<div class="diagonalRising"></div>
<div class="diagonalFalling"></div>
<div class="diagonalCross"></div>
Try this,
.box::after {
background: #E52A35
content: '';
position: absolute;
width: 100%;
height: 100vh;
background-color: #dd4f39;
clip-path: polygon(52% 13%, 104% -1%, -1% 0%);
}

Creating responsive eye focus icon

I've been trying to make responsive colored eye focus icon, but so far all I've tried has been unsuccessful.
I was trying to somewhat replicate the colors of a real eye.
I used border, box shadow, to get the colors, but that part is not scaling. Tried with outline too, but failed as well, that one wasn't even round.
The height of the div is currently static, but I would like it to be responsive. So the whole eye scales properly across different sizes.
Here's my code:
<div class="paragraph eye-focus">
<div class="eye1" width="80%">
<div class="eye2"></div>
</div>
</div>
.eye1 {
height: 200px;
height: calc(attr(width) / 2.5);
width: 75%;
background-color: white;
border-radius: 50%;
position: relative;
margin: auto;
}
.eye2 {
background-color: black;
width: 8%;
height: 12%;
border-radius: 50%;
border: 0.5em solid #a50;
box-shadow: 0 0 0 1.5em #080;
position: absolute;
top: 40%;
left: 45%;
}
.eye-focus {
position: relative;
}
jsfiddle if you'd prefer https://jsfiddle.net/xcxdp92q/
I'd like to put my solution out there.
You can use background radial-gradient to create the eye in a single element.
When adding padding in %, it is based on the width of the element. Use that to your advantage to make it responsive. If padding equals width, the element will be a square.
.eye-focus {
box-sizing: content-box;
height: 0;
width: 75%;
padding: 30% 0 0 0;
margin: 0 auto;
border-radius: 50%;
background-color: #fff;
background-image: radial-gradient(circle, #000 8%, #a50 8%, #0b0 17%, #080 33%, transparent 33%);
}
<div class="paragraph">
<div class="eye-focus"></div>
</div>
jsfiddle
If you're only supporting browsers that support gradients (and current browsers most do) then you can just use one div and do all the colors in a radial gradient. I used vw to size it like Suthan Bala suggested in their comment.
body {
background: #EEE;
}
.eye {
border-radius: 50%;
background: -moz-radial-gradient(center, ellipse cover, #000000 17%, #aa5500 18%, #008800 40%, #ffffff 41%);
background: -webkit-radial-gradient(center, ellipse cover, #000000 17%, #aa5500 18%, #008800 40%, #ffffff 41%);
background: radial-gradient(ellipse at center, #000000 17%, #aa5500 18%, #008800 40%, #ffffff 41%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#ffffff', GradientType=1);
width: 35vw;
height: 35vw;
}
<div class="eye">
</div>
I used the Color Gradient Generator by Colorzilla.
Try using this CSS:
.eye1 {
height: 4vw;
width: 4vw;
background-color: white;
border-radius: 50%;
position: relative;
margin: auto;
}
.eye2 {
background-color: black;
width: 6vw;
height: 6vw;
border-radius: 50%;
border: 1em solid #a50;
box-shadow: 0 0 0 3vw #080;
position: relative;
top: 8vw;
left: 43%;
}
.eye-focus {
position: relative;
}
I've been using vw a lot lately (for a year now). Very handy!

Dotted top and bottom border shorter than text

I want to achieve border top and bottom like below image how can I achieve with CSS tricks?
Challenge is I don't want entire width with border and it should be responsive too.
Mobile version image is http://i.imgur.com/XZTW28N.jpg and it should work in desktop and mobile browser too.
I tried with %width border but it's not working.
I wrote below code but it's not 100% perfect answer for me.
HTML:
<h1>How it Works</h1
CSS:
h1:before, h1:after {
content: "";
height: 1px;
background: linear-gradient(to right, rgba(0,0,0,0) 0%,rgba(147,147,147,1) 50%,rgba(0,0,0,0) 100%);
display: block;
margin-bottom: 10px;
margin-top: 10px;
}
http://jsfiddle.net/wjhnX/488/
I made a few changes in your CSS:
h1{
text-align: center;
font-size: 70px;
}
h1:before, h1:after{
position: relative;
content: "";
width: 30%;
left: 35%;
display: block;
margin-bottom: 10px;
margin-top: 10px;
border-bottom: 5px dotted yellow;
}
DEMO
EDIT:
If you want a fixed width you can add:
h1:before, h1:after{
width: 150px; /* You can change this value */
left: 50%;
transform: translateX(-50%);
}
DEMO2
You can use box-shadows also to achieve this, first create an after psuedo-element on top and a before pseudo-element on bottom then give the two of the box-shadows
body{
background:#09858F;
}
div{
position:relative;
display:inline-block;
margin:100px;
}
h1{
text-align:center;
font-family: Calibri;
font-size:50px;
color:#fff;
margin:50px;
}
h1:after{
content:"";
position:absolute;
left:30%;
height:10px;
width:10px;
background:yellow;
top:20%;
border-radius:50%;
box-shadow:20px 0 0 0 yellow,40px 0 0 0 yellow,60px 0 0 0 yellow,80px 0 0 0 yellow,100px 0 0 0 yellow,120px 0 0 0 yellow,140px 0 0 0 yellow,160px 0 0 0 yellow;
}
h1:before{
content:"";
position:absolute;
left:30%;
height:10px;
width:10px;
background:yellow;
bottom:20%;
border-radius:50%;
box-shadow:20px 0 0 0 yellow,40px 0 0 0 yellow,60px 0 0 0 yellow,80px 0 0 0 yellow,100px 0 0 0 yellow,120px 0 0 0 yellow,140px 0 0 0 yellow,160px 0 0 0 yellow;
}
<div><h1>How it Works</h1></div>
Here is another approach using radial-gradient background image to produce the dots at the top and bottom. The output is responsive and the no. of dots at the top and bottom are determined by the width (for example, width: 108px produces 9 dots as background-size in x-axis is 12px).
The advantage of this approach over the others is that this allows greater control over the size of the dots and the space in between the dots. The downside is the browser support for radial-gradient which is lower (IE10+) compared to dotted border method.
h1 {
position: relative;
text-align: center;
font-size: 48px;
line-height: 1em;
padding: 0.625em;
font-family: Calibri;
font-weight: 100;
}
h1:after {
position: absolute;
content: '';
width: 108px; /* multiples of background-size in X-axis */
height: 100%;
top: 0px;
left: calc(50% - 50px);
background: radial-gradient(circle at 50% 50%, rgb(250, 189, 38) 30%, transparent 50%), radial-gradient(circle at 50% 50%, rgb(250, 189, 38) 30%, transparent 50%);
background-size: 12px 6px;
background-repeat: repeat-x;
background-position: 50% 0.125em, 50% 2em;
}
/* Just for demo */
body {
background: rgb(9, 133, 143);
color: white;
}
<!-- library included to support older browsers -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<h1>How it works</h1>
<h1>How it works with long text</h1>
Screenshot with large dots:
All that is needed to be done to make the dots smaller in size is to reduce the color-stop percentages of the radial gradient. The smaller the percentages, the smaller the dots.
h1 {
position: relative;
text-align: center;
font-size: 48px;
line-height: 1em;
padding: 0.625em;
font-family: Calibri;
font-weight: 100;
}
h1:after {
position: absolute;
content: '';
width: 108px; /* multiples of background-size in X-axis */
height: 100%;
top: 0px;
left: calc(50% - 50px);
background: radial-gradient(circle at 50% 50%, rgb(250, 189, 38) 25%, transparent 35%), radial-gradient(circle at 50% 50%, rgb(250, 189, 38) 25%, transparent 35%);
background-size: 12px 6px;
background-repeat: repeat-x;
background-position: 50% 0.125em, 50% 2em;
}
/* Just for demo */
body {
background: rgb(9, 133, 143);
color: white;
}
<!-- library included to support older browsers -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<h1>How it works</h1>
<h1>How it works with long text</h1>
Screenshot with smaller dots: