Can i get this shape with gradients on one element?

https://codepen.io/Miss-Fox/pen/MWRGMZe (this pen has changed, didnt mean to overwirte it) trying to use one background property with gradients sans the pseudo element. Breaking my brain because i need one gradient to go to the right to have that break on top and seemingly one to go to the bottom to get the solid bottom border. Right now i have the bottom border as a pseudo element but i'm curious if it can be achieved all on the .box background property?
48 Replies
capt_uhu
capt_uhu8mo ago
could the bottom border just literally be a border-bottom: solid red 10px; to cover up the hole. Other thought is maybe a conic-gradient with the hard stops?
clevermissfox
clevermissfoxOP8mo ago
Oh conic is a good idea . Hmm I didn’t try border-bottom Wow that worked. I thought it would overwrote the border-box bg property for the whole thing. That does solve this particular example. I was curious more about gradients in general and having one gradient go to the right with also one that goes to the bottom, and how to accomplish that. I’ve seen the guys in this channel do amazing things with gradients
capt_uhu
capt_uhu8mo ago
did one with conic and one with layered linear, have a look: https://codepen.io/jsnkuhn/pen/poBVMVr
clevermissfox
clevermissfoxOP8mo ago
Oh gosh it’s that easy (the layered)?! Thank you so much
MarkBoots
MarkBoots8mo ago
a hacky option with fieldset/legend (with this you could even have a border-radius really easy)
No description
clevermissfox
clevermissfoxOP8mo ago
interesting, does the legend get a bg of white anywhere or does aligning it center and giving it a width just auto matically make that tranparent space for it? oh gosh that bacground-size property has my head spinning a bit! So does each entry before a comma refer to each gradient , in order? so the first 100% var(--border-size) refers to the first gradient, the next to the next gradient, etc? I forget about the background-size and background-position properties so often unless its background-size: cover;
MarkBoots
MarkBoots8mo ago
it is just transparent, by default it aligns to the left, but as it is an inline-elelement, you can just center it. https://codepen.io/MarkBoots/pen/gOyKbGO
Mark Boots
CodePen
.
...
MarkBoots
MarkBoots8mo ago
yea each comma is a layer. from top layer to bottom
Choo♚𝕂𝕚𝕟𝕘
Yes. They are in order. Note that when you have multiple backgrounds, the first one is on top and the last one is on the bottom.
clevermissfox
clevermissfoxOP8mo ago
I did notice that, about how they layer. I’m so intrigued with gradients and how many ways you can use them but I’m terrible at putting it into practice . Really appreciate everyone’s time and effort 💜 Gotcha I would have never thought to use this element this way. Thank you so much MarkBoots!! 💜 Mark since youve been my hero these last couple days with all my questions, im wondering if youd be able to answer this question about gradients:
clevermissfox
clevermissfoxOP8mo ago
in this example https://codepen.io/Miss-Fox/pen/OJGEVVW?editors=0100 i have two boxes. One i define the bg all on the bg property, box-2 i define the gradients on the bg property and the bg-clip values on the background-clip property. why does the second one have a completely green border-top and completely blue border-bottom? when it should be giving me the same result as Box-1? what am i missing?
MarkBoots
MarkBoots8mo ago
Yea, that's a strange one. On first sight it looks like it should work the same. But i am on mobile right now, so it's a bit hard to dive into it. I'll come back to this later today
clevermissfox
clevermissfoxOP8mo ago
no rush, thank you so much
capt_uhu
capt_uhu8mo ago
have a look at background-origin for the explanation: https://developer.mozilla.org/en-US/docs/Web/CSS/background-origin
MDN Web Docs
background-origin - CSS: Cascading Style Sheets | MDN
The background-origin CSS property sets the background's origin: from the border start, inside the border, or inside the padding.
MarkBoots
MarkBoots8mo ago
background-origin: border-box; indeed does the trick, but am still wondering why it isn't necessary in the background shorthand
capt_uhu
capt_uhu8mo ago
not sure that i'm following the question. Maybe this is the explanation you're looking for:
No description
MarkBoots
MarkBoots8mo ago
Yep, that's it!
clevermissfox
clevermissfoxOP8mo ago
Aha that explains it!
clevermissfox
clevermissfoxOP8mo ago
Mark, gradient issue again...I've got this solution but i cant figure out why theres that light line around the "transparent" areas. Trying to fiddle with the background position and size but it keeps giving me a repeating gradient. Tried with a conic gradient but i couldnt get the straight lines where i needed the breaks . https://codepen.io/Miss-Fox/pen/ZEZXgWd?editors=1100 attached the reference of what it ShOULD look like.
No description
MarkBoots
MarkBoots8mo ago
yea, that happens some times. the green tips are laying on top of the yellow, sometimes there is some spillage. (think that may be a rounding issue or something. nothing much we can do about it really. (if you remove the rotate you'll see it does not happen) btw, you could add the size and position also to the background shorthand as well. and a gradient between the same colors could be written differently with only having to declare the color once:
background:
linear-gradient(#BFE33A 0 0) content-box, /*sets the inner box */
linear-gradient(#223E1F 0 0) padding-box, /* sets the dark green "border" around the inner box*/
linear-gradient(#223E1F 0 0) top left / 40px 40px border-box no-repeat, /* sets dark green on the top tip */
linear-gradient(#223E1F 0 0) bottom right / 40px 40px border-box no-repeat, /* sets dark green on the btm tip */
#BFE33A; /* sets lime green elsewhere on the border */
background:
linear-gradient(#BFE33A 0 0) content-box, /*sets the inner box */
linear-gradient(#223E1F 0 0) padding-box, /* sets the dark green "border" around the inner box*/
linear-gradient(#223E1F 0 0) top left / 40px 40px border-box no-repeat, /* sets dark green on the top tip */
linear-gradient(#223E1F 0 0) bottom right / 40px 40px border-box no-repeat, /* sets dark green on the btm tip */
#BFE33A; /* sets lime green elsewhere on the border */
MarkBoots
MarkBoots8mo ago
i did the challenge myself as well. but I did it with box-shadows, codegolved 136 chars
<style>*+*{color:BFE33A;margin:150 200;box-shadow:0 0 0 37q,0 0 0 58q#223E1F,21q -21q 0 58q,-21q 21q 0 58q,0 0 0 9in#223E1F;rotate:45deg
<style>*+*{color:BFE33A;margin:150 200;box-shadow:0 0 0 37q,0 0 0 58q#223E1F,21q -21q 0 58q,-21q 21q 0 58q,0 0 0 9in#223E1F;rotate:45deg
No description
clevermissfox
clevermissfoxOP8mo ago
box-shadow was what i first thought of but since im trying to get better with gradients, i figured i should challenge myself. interesting, i thought i had tried using just one colour before in a gradient and it hadnt worked; mustve been doing something wrong. and i get confused using everything on the background property right now, i can never get the order right or ill forget the '/' between position and size so still breaking it up into extra props. Not good enough to use cssbattle for min-vhars; just trying to get the thing to look right youre the best thank you
clevermissfox
clevermissfoxOP8mo ago
on this https://cssbattle.dev/play/TcULOISsIjEsam2LQsT1 challenge, i eventually figured it out but was trying to do the left to right gradient then a top to bottom gradient but my bg-size property wasnt working. something like this https://codepen.io/Miss-Fox/pen/ExJeJBw?editors=0110 ; i eventually just flipped the order of the gradients but im wondering why the bg-size didnt work for the first.
CSSBattle
The funnest CSS game for web designers & developers
Miss Fox
CodePen
ExJeJBw
...
MarkBoots
MarkBoots8mo ago
The background size is working, but by default backgrounds repeat. with a background-repeat: no-repeat. it should work as you intended; But in this scenario i do think swapping the order is easier. in that case the left to right gradient can just fill up the full space and the top layer can cover it top to bottom. So background-sizing is not nessesarry anymore This is my solution with a single conic background (taking advantage of default background repeat)
<style>
body {
background-image: conic-gradient(at 150px 50%, #EA6B62 75%, #512B2A 0);
background-size: 250px 100%;
}
</style>
<style>
body {
background-image: conic-gradient(at 150px 50%, #EA6B62 75%, #512B2A 0);
background-size: 250px 100%;
}
</style>
codegolfed 68chars
<style>&{background:50vh conic-gradient(at 25%,#512B2A 25%,#EA6B62 0
<style>&{background:50vh conic-gradient(at 25%,#512B2A 25%,#EA6B62 0
clevermissfox
clevermissfoxOP8mo ago
Swapping snd removing size is what I ended up doing I was just baffled why the size wasn't working... of course bg repeat. I am just awful with the bg property , cannot write it as a shorthand or remember/understand all the props. Like how bg clip and bg origin are different . Thanks I struggle with conic gradients when I need psttslrl lines because conic come from the center. I'm on mobile right now but gonna three your solution on a pen later to see how it would work. Thanks Mark, youre my gradient guru 🤣 ahh okay i see how you used the conic-gradient now, took advantage of the bg repeat and made the conic gradient have a straight line bc of the 75% value. did you do the latest cssbattle? i assume it can be done with a radial gradient somehow but not sure how.
MarkBoots
MarkBoots8mo ago
yea i did, but not only with gradients (only the center circle) It can be done only with gradients, but you;'ll need a lot maybe later today i will try it that way
No description
clevermissfox
clevermissfoxOP8mo ago
i find its so hard to get the border-radii right in these css battles, this is impressive that youre one of these cssbattle wizrds that can match it without elements. the translate and box shadow is blowing my mind. i dont even know how to read it, looks like you have
* {
* {background: lightpink etc}
radial-gradient: ...etc

}
* {
* {background: lightpink etc}
radial-gradient: ...etc

}
how does that selector work? is the first * selecting the html tag and the second selecting the body?
MarkBoots
MarkBoots8mo ago
Yep html and body
clevermissfox
clevermissfoxOP8mo ago
i played with it a bit, very interesting. so basically before you put any elements in the body, you have 6 elements you can style: html + body, html::before, html::after, body::before, body::after ? or does the html element not have pseudo-elements?
MarkBoots
MarkBoots8mo ago
Yea it has. i did it with gradients, as said, it requiers a lot of them
<style>
body {
--circle: no-repeat radial-gradient(100% 100%, #BE3184 50%, #0000 0);
--block: no-repeat linear-gradient(#BE3184 0 0);
background:

/* center */
var(--circle) center / 100px 100px,

/* top right */
var(--circle) 200px -60px / 160px 160px,
var(--block) right top / 120px 100px,
var(--block) right top / 200px 20px,

/* bottom left */
var(--circle) 40px 200px / 160px 160px,
var(--block) left bottom / 120px 100px,
var(--block) left bottom / 200px 20px,

/* background */
#611B3F;
}
</style>
<style>
body {
--circle: no-repeat radial-gradient(100% 100%, #BE3184 50%, #0000 0);
--block: no-repeat linear-gradient(#BE3184 0 0);
background:

/* center */
var(--circle) center / 100px 100px,

/* top right */
var(--circle) 200px -60px / 160px 160px,
var(--block) right top / 120px 100px,
var(--block) right top / 200px 20px,

/* bottom left */
var(--circle) 40px 200px / 160px 160px,
var(--block) left bottom / 120px 100px,
var(--block) left bottom / 200px 20px,

/* background */
#611B3F;
}
</style>
clevermissfox
clevermissfoxOP8mo ago
🤯 woah. Gradient guru 👑 gonna play with this now and see if I can reverse engineer tried to do todays all on the body with a lot of gradients but the kept messing up the size and position and padding-box, content-box, border etc. But closer than i was last week so thank you for your assistance Edit: I did it!! i didnt need the clip or origin properties on the body duh and i used the bg property instead of all the individual background-repeat, background-size etc. Thank you Mark!! If you see anything glaringly wrong or bad habits lmk
* { * {
background:
linear-gradient(#B53733 0 0) top left / 75px 75px no-repeat,
linear-gradient(#EA7457 0 0) top left/100px 100px no-repeat,
linear-gradient(#B53733 0 0) top left/150px 150px no-repeat,
linear-gradient(#B53733 0 0) bottom right / 75px 75px no-repeat,
linear-gradient(#EA7457 0 0) bottom right/100px 100px no-repeat,
linear-gradient(#B53733 0 0) bottom right/150px 150px no-repeat,
linear-gradient(to right, #EA7457 0 175px, #B53733 0 225px, #EA7457 0 100%) center/ 100% 100%;
}
}
* { * {
background:
linear-gradient(#B53733 0 0) top left / 75px 75px no-repeat,
linear-gradient(#EA7457 0 0) top left/100px 100px no-repeat,
linear-gradient(#B53733 0 0) top left/150px 150px no-repeat,
linear-gradient(#B53733 0 0) bottom right / 75px 75px no-repeat,
linear-gradient(#EA7457 0 0) bottom right/100px 100px no-repeat,
linear-gradient(#B53733 0 0) bottom right/150px 150px no-repeat,
linear-gradient(to right, #EA7457 0 175px, #B53733 0 225px, #EA7457 0 100%) center/ 100% 100%;
}
}
MarkBoots
MarkBoots8mo ago
well done! the only obvious thing i see it that the nesting is not nessessary. you can just do
*>* { background: ... }
/* or */
& { background: ... }
*>* { background: ... }
/* or */
& { background: ... }
clevermissfox
clevermissfoxOP8mo ago
ah gotcha makes sense. I also am not good enough to worry about char count on cssbattles, i just try to make the thing work but i did remove all the no-repeats and just put it into a background-repeat: no-repeat bc theres prob less characters overall. Im so happy, i cant thank you enough ive been struggling with gradients and the bg property for ages, and im finally making some progress now that ive been paying more attention to it.
MarkBoots
MarkBoots8mo ago
no problem at all. owh btw, when you have a 100% 100% size, you don't need to set it at all, and you can leave the position off as well. (center by default) it will just will up the available space
linear-gradient(to right, #EA7457 0 175px, #B53733 0 225px, #EA7457 0);
linear-gradient(to right, #EA7457 0 175px, #B53733 0 225px, #EA7457 0);
clevermissfox
clevermissfoxOP8mo ago
Oh awesome good to know , I knew center and 100% was the default but wasn’t sure if setting multiple bgs and using position and size on those would then require an explicit declaration for all. Good to know for sure. I’ll get there one day. Gonna try for one of those inverted curved pieces that everyone’s always asking about. I always recommend clip-path but cubiq has demonstrated using gradients before. To clarify , the kind of curved inverted menu in this https://youtu.be/SkML640BcoA?si=0ICwKaVgqyC_I428
Kevin Powell
YouTube
Create a clean, modern navigation with HTML & CSS
Looking to step up your CSS game? I have free and premium courses: 👉 https://kevinpowell.co/courses?utm_campaign=general&utm_source=youtube&utm_medium=funkynavigation 🔗 Links ✅ Chrome Canary: https://www.google.com/intl/en_ca/chrome/canary/ ✅ Finished code: https://github.com/kevin-powell/funky-nav ✅ Finished version live site (animation will ...
clevermissfox
clevermissfoxOP8mo ago
Is it valid syntax to use a calc() within a background-position or background-size?
MarkBoots
MarkBoots8mo ago
yea, you can use it everywhere
clevermissfox
clevermissfoxOP8mo ago
cool. im getting comfortable using background w gradients but if im not using fixed pixel sizes like in css battle im wondering how to keep it responsive as the screen size moves. assuming using percentages anc calcs will be the answer i dont suppose you can use gradients within gradients? something like:
linear-gradient(to right, radial-gradiant(100% 100%, red 50%, transparent 0), blue 0)
linear-gradient(to right, radial-gradiant(100% 100%, red 50%, transparent 0), blue 0)
?
MarkBoots
MarkBoots8mo ago
No, that is not a thing
clevermissfox
clevermissfoxOP8mo ago
didnt think so , but would be cool 🤣 struggline with the values on how to make the semi circles take up 100% of the width of the background-size. I have background-size: 50px 100px; radial-gradient(0% 50%, #F180B6 0 50%, transparent 0) no-repeat); but with the aspect-ratio i cant figure it out
MarkBoots
MarkBoots8mo ago
<style>
body{
--block: linear-gradient(#A6A0BE 0 0) no-repeat;
--circle: radial-gradient(100% 100%,#A6A0BE 50%, #0000 0) no-repeat;
background:
var(--block) 100px 0px / 40px 100px,
var(--block) 40px 100px / 100px 50px,
var(--circle) 40px / 100px 100px,

var(--block) 260px 0px / 40px 100px,
var(--block) 260px 100px / 100px 50px,
var(--circle) 260px / 100px 100px,

radial-gradient(100% 100%, #766D94 50%, #0000 0) 50% 100px / 40px 40px no-repeat,
linear-gradient(#766D94 0 0) 50% 120px / 40px 180px no-repeat,

#301E53
}
</style>
<style>
body{
--block: linear-gradient(#A6A0BE 0 0) no-repeat;
--circle: radial-gradient(100% 100%,#A6A0BE 50%, #0000 0) no-repeat;
background:
var(--block) 100px 0px / 40px 100px,
var(--block) 40px 100px / 100px 50px,
var(--circle) 40px / 100px 100px,

var(--block) 260px 0px / 40px 100px,
var(--block) 260px 100px / 100px 50px,
var(--circle) 260px / 100px 100px,

radial-gradient(100% 100%, #766D94 50%, #0000 0) 50% 100px / 40px 40px no-repeat,
linear-gradient(#766D94 0 0) 50% 120px / 40px 180px no-repeat,

#301E53
}
</style>
clevermissfox
clevermissfoxOP8mo ago
sorry i thought i pasted this, i ws actually wondering about the sem-circles in this kind of challenge https://cssbattle.dev/play/fg9g3K0GVSIdaUaIeqL6 I'm close but I cant get the visible half circle part to take up 100% of the width (when the background size is 50px 100px)
CSSBattle
The funnest CSS game for web designers & developers
MarkBoots
MarkBoots8mo ago
ah okay i would just make all background sizes the same (100px 100px) but set the center of the circle at the left / right edge
<style>
body {
background:
radial-gradient(100% 100%, #F180B6 50%, #0000 0) 50% 40px,
radial-gradient(100% 100% at left, #F180B6 50%, #0000 0) 250px 40px,
radial-gradient(100% 100% at left, #F180B6 50%, #0000 0) 300px 40px,

radial-gradient(100% 100%, #F180B6 50%, #0000 0) 50% 160px,
radial-gradient(100% 100% at right, #F180B6 50%, #0000 0) 50px 160px,
radial-gradient(100% 100% at right, #F180B6 50%, #0000 0) 0px 160px,
#5F0032;
background-size: 100px 100px;
background-repeat: no-repeat
}
</style>
<style>
body {
background:
radial-gradient(100% 100%, #F180B6 50%, #0000 0) 50% 40px,
radial-gradient(100% 100% at left, #F180B6 50%, #0000 0) 250px 40px,
radial-gradient(100% 100% at left, #F180B6 50%, #0000 0) 300px 40px,

radial-gradient(100% 100%, #F180B6 50%, #0000 0) 50% 160px,
radial-gradient(100% 100% at right, #F180B6 50%, #0000 0) 50px 160px,
radial-gradient(100% 100% at right, #F180B6 50%, #0000 0) 0px 160px,
#5F0032;
background-size: 100px 100px;
background-repeat: no-repeat
}
</style>
clevermissfox
clevermissfoxOP8mo ago
That’s what I started with, just was wondering if there was a way to make the circle for the width AND height when it’s a 1/2 aspect ratio. Its hard to do calculations when the exact size of the visible semi-circle is not the exact size of the bg-size but if I suppose it’s easier if you know it’s half the width. I did something where it was almost the right width but not quite and that discrepancy was a pain to calculate
clevermissfox
clevermissfoxOP7mo ago
is there a way to get rid of this aliasing on my radial-gradients?
No description
MarkBoots
MarkBoots7mo ago
yes, you can make the colorstop a bit les harsh. now we do it on exactly 50%.
radial-gradient(100% 100%, #FEFF58 calc(50% - 1px), #F48B26 50%)
radial-gradient(100% 100%, #FEFF58 calc(50% - 1px), #F48B26 50%)
now we have 1px to make the color switch happen btw you can do it with a repeat-x, then you only have to use the gradient once at the bottom position. and in the shorthand, you can also just use a color without a gradient if you want to fill the whole thing
&{
background:
radial-gradient(100% 100%, #FEFF58 50%, #F48B26 0) bottom left / 50% 200px repeat-x,
#FEFF58
}
&{
background:
radial-gradient(100% 100%, #FEFF58 50%, #F48B26 0) bottom left / 50% 200px repeat-x,
#FEFF58
}
clevermissfox
clevermissfoxOP7mo ago
Ahh minus 1px and yes good point on repeat x. Ohh I didn't even think of using the orange as part of the radial grade
Want results from more Discord servers?
Add your server