How do I make a div like this be able to expand to any size while having the corner triangles stay the same size? - html

As I said in the title, I want this div to be able to be any size, but without the corner triangles or the line on top getting bigger:
How could I achieve something like this with CSS?

You may use gradients and padding.
possible example
body {
background:linear-gradient(to bottom left , #f8f3e0, silver, #f8f3e0, silver, #f8f3e0, silver, #f8f3e0, silver, #f8f3e0, silver ) ;
}
div {
margin: 1em;
padding: 1.6em 0.5em 1em;
background:
linear-gradient(140deg, transparent 1em, black 1.07em) 0 0 / 1.7em 1.45em no-repeat,
linear-gradient(220deg, transparent 1em, black 1.07em) 100% 0 / 1.7em 1.45em no-repeat,
linear-gradient( to bottom, transparent 1.3em, black 1.3em 1.45em, #e0e5c1 1.45em);
}
div+div {
width: 50vmin;
float: left;
filter:drop-shadow(0 0 1px crimson);
}
div+div+div {
width: 30vmax;
filter: drop-shadow(1px 0px) drop-shadow(-1px 0px) drop-shadow(0 1px); /* a border ? */
}
<div>
<h1>title</h1>
<p>Whatever comes inside</p>
</div>
<div>
<h1>title</h1>
<p>Whatever comes inside</p>
</div>
<div>
<h1>title</h1>
<p>Whatever comes inside</p>
</div>

an idea using clip-path:
.box {
/* adjust the variable to control the clip-path*/
--b:10px;
--c:8px;
/**/
border-top:10px solid #000;
height:100px;
background:#e0e5c1;
clip-path:polygon(var(--b) 0,var(--b) var(--c),calc(100% - var(--b)) var(--c),calc(100% - var(--b)) 0,100% var(--c),100% 100%,0 100%,0 var(--c));
}
<div class="box"></div>

Related

CSS - fading gradient border from-to

I want to make my whole div section with fading border. Here is my code:
.usermanagement {
-webkit-border-image: -webkit-gradient(
linear,
left top,
left bottom,
from(#fff),
to(#afd4ec),
color-stop(0.2, #afd4ec)
)
0 0 0 0 repeat repeat;
}
The effect is exactly what I want but only for top:
Then all goes to light blue and finishes like this:
Without this fading effect. I want to make the same effect as in the top for the bottom end of the section. How it is possible?
You can try like below. make sure to correctly set the different values.
.box {
height:50px; /* this need to be a multiple of 10 for the effect to work */
border-top: 10px solid;
border-bottom:10px solid;
background:#f2f2f2;
border-image:repeating-linear-gradient(#fff 0,red 10px) 10;
}
<div class="box"></div>
You can also do it with multiple background:
.box {
height:50px;
border-top:10px solid transparent;
border-bottom:10px solid transparent;
background:
linear-gradient(#fff ,red ) top,
linear-gradient(#fff ,red ) bottom, /* use (red, #fff) here for the opposite effect */
#f2f2f2;
background-size:100% 10px;
background-origin:border-box;
background-repeat:no-repeat;
}
<div class="box"></div>

How do you apply a gradient from outer to inner, only to borders, in CSS?

Based on the MDN documentation this doesn't seem to be explicitly supported. So I tried it as follows in the linked code pen below. I know the nested <div>'s are ugly as can be and don't make for a good reusable style component, but I don't know how else to approach this effect! Any guidance on what approaches to try to accomplish this would be greatly appreciated!
Here is a link to a pen demonstrating my current approach:
:root {
--outer-battle-window-color-0: #7c7874;
--outer-battle-window-color-1: #c8c4c0;
--outer-battle-window-color-2: #ccc9cc;
--outer-battle-window-color-3: #c9c9cb;
--outer-battle-window-color-4: #c2c1c5;
--outer-battle-window-color-5: #71767e;
--outer-battle-window-color-6: #6b6e87;
--battle-window-top-gradient-color: #6c70a6;
--battle-window-middle-gradient-color: #21217c;
--battle-window-bottom-gradient-color: #040136;
--battle-window-border-radius: 5px;
}
html{
font-family: "Final Fantasy 3/6 Font Regular", monospace;
color: #ecedee;
margin: 0px;
padding: 0px;
background-color: var(--battle-window-middle-gradient-color);
text-shadow: 3px 2px #2d2a4b;
}
div{
background-color: var(--battle-window-middle-gradient-color);
}
#outer-window-border-color_0{
border-color: var(--outer-battle-window-color-0);
border-width: 1px;
border-style: solid;
border-radius: var(--battle-window-border-radius);
}
#outer-window-border-color_1{
border-color: var(--outer-battle-window-color-1);
border-width: 1px;
border-style: solid;
border-radius: var(--battle-window-border-radius);
}
#outer-window-border-color_2{
border-color: var(--outer-battle-window-color-2);
border-width: 1px;
border-style: solid;
border-radius: var(--battle-window-border-radius);
}
#outer-window-border-color_3{
border-color: var(--outer-battle-window-color-3);
border-width: 1px;
border-style: solid;
border-radius: var(--battle-window-border-radius);
}
#outer-window-border-color_4{
border-color: var(--outer-battle-window-color-4);
border-width: 1px;
border-style: solid;
border-radius: var(--battle-window-border-radius);
}
#outer-window-border-color_5{
border-color: var(--outer-battle-window-color-5);
border-width: 1px;
border-style: solid;
border-radius: var(--battle-window-border-radius);
}
#outer-window-border-color_6{
border-color: var(--outer-battle-window-color-6);
border-width: 1px;
border-style: solid;
border-radius: var(--battle-window-border-radius);
}
<div id="outer-window-border-color_0">
<div id="outer-window-border-color_1">
<div id="outer-window-border-color_2">
<div id="outer-window-border-color_3">
<div id="outer-window-border-color_4">
<div id="outer-window-border-color_5">
<div id="outer-window-border-color_6">
This is a test of the borders!
</div>
</div>
</div>
</div>
</div>
</div>
</div>
https://codepen.io/webDevelopmentSolutions/pen/zYvGWLO
You can build it using multiple background:
.box {
--r:15px; /* radius */
--g:red,blue; /* gradient */
border-radius:var(--r);
padding:calc(var(--r) + 5px);
background:
/*corners*/
radial-gradient(farthest-side at bottom right,var(--g)) top left /var(--r) var(--r),
radial-gradient(farthest-side at top right,var(--g)) bottom left /var(--r) var(--r),
radial-gradient(farthest-side at bottom left ,var(--g)) top right/var(--r) var(--r),
radial-gradient(farthest-side at top left ,var(--g)) bottom right/var(--r) var(--r),
/* borders*/
linear-gradient(to top ,var(--g)) top /calc(100% - 2*var(--r)) var(--r),
linear-gradient(to bottom,var(--g)) bottom/calc(100% - 2*var(--r)) var(--r),
linear-gradient(to right ,var(--g)) right /var(--r) calc(100% - 2*var(--r)),
linear-gradient(to left ,var(--g)) left /var(--r) calc(100% - 2*var(--r));
background-repeat:no-repeat;
width:150px;
display:inline-block;
display:inline-block;
vertical-align:top;
font-size:25px;
}
<div class="box"> Some text inside</div>
<div class="box" style="--r:10px;--g:black,orange,grey"> more text inside</div>
<div class="box" style="--r:30px;--g:green,blue,yellow">Some text inside</div>
If you want inner radius you can adjust like below:
.box {
--r:10px; /* radius */
--g:red 0%,blue; /* gradient */
--rg:transparent 50%,var(--g);
border-radius:calc(2*var(--r));
padding:calc(2*var(--r) + 5px);
background:
/*corners*/
radial-gradient(farthest-side at bottom right,var(--rg)) top left /calc(2*var(--r)) calc(2*var(--r)),
radial-gradient(farthest-side at top right,var(--rg)) bottom left /calc(2*var(--r)) calc(2*var(--r)),
radial-gradient(farthest-side at bottom left ,var(--rg)) top right/calc(2*var(--r)) calc(2*var(--r)),
radial-gradient(farthest-side at top left ,var(--rg)) bottom right/calc(2*var(--r)) calc(2*var(--r)),
/* borders*/
linear-gradient(to top ,var(--g)) top /calc(100% - 4*var(--r)) var(--r),
linear-gradient(to bottom,var(--g)) bottom/calc(100% - 4*var(--r)) var(--r),
linear-gradient(to right ,var(--g)) right /var(--r) calc(100% - 4*var(--r)),
linear-gradient(to left ,var(--g)) left /var(--r) calc(100% - 4*var(--r));
background-repeat:no-repeat;
width:200px;
box-sizing:border-box;
display:inline-block;
vertical-align:top;
font-size:25px;
}
<div class="box"> Some text inside</div>
<div class="box" style="--r:8px;--g:black 0%,orange,grey"> more text inside</div>
<div class="box" style="--r:20px;--g:green 0%,blue,yellow">Some text inside</div>
Related question to get diffent gradient with radius: Border Gradient with Border Radius
I think you should use the border-image property and set it to a linear gradient and tweak it until you have achieved what you want. After all, CSS does treat linear-gradient() as an image.
If you have an image of what you want to produce maybe I can help bring it to life. I hope this helps
example:
.div {
color: pink;
border: 10px solid pink;
border-image: repeating-linear-gradient( 45deg, pink, pink 1%, purple 1%, purple 8%) 10;
}
source: https://css-tricks.com/almanac/properties/b/border-image/

CSS / HTML gradient fill pattern is glitchy in Firefox

The following is a minimal (ish) example in which a chequered gradient fill pattern is glitchy in Firefox (version 74) i.e. it is not pixel perfect. There are line artefacts. Why is this? Is that normal? Is there a fix, other than using an image for the background?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<style>
.r{width:20px;height:20px;background:white;float:left;}
.w{overflow:hidden;}
#p75{
width:80px;
height:20px;
background-position:0px 0px,10px 10px;
background-size:20px 20px;
background-image:linear-gradient(45deg,#ccc 25%,transparent 25%,transparent 75%,#ccc 75%,#ccc 100%),
linear-gradient(45deg,#ccc 25%,white 25%,white 75%,#ccc 75%,#ccc 100%);
float:left;
}
</style>
</head>
<body>
<div class="w">
<div class="r">0</div>
<div id="p75"></div>
</div>
</body>
Rotating gradients have always had that problem for more on that check this question
One way to fix the issue is to not use angles at all, and make use of repeating gradients.
html {
height: 100%;
background:
repeating-linear-gradient(90deg, #fff 0px 10px, transparent 10px 20px),
repeating-linear-gradient(0deg, #000 0px 10px, #fff 10px 20px);
background-blend-mode: difference;
}
Edit: thanks to #Temani Afif without repeating gradient.
html {
height: 100%;
background:
linear-gradient(90deg, #fff 50%, transparent 0) 0 0/20px 100%,
linear-gradient(0deg, #000 50%, #fff 0) 0 0/100% 20px;
background-blend-mode: difference;
}
you can overlap them a tiny bit , here i added 0.1% to the color start/stop setup , chrome use to be the one.
.r {
width: 20px;
height: 20px;
background: white;
float: left;
}
.w {
overflow: hidden;
}
#p75,
.p75 {
width: 80px;
height: 20px;
background-position: 0px 0px, 10px 10px;
background-size: 20px 20px;
background-image: linear-gradient(45deg, #ccc 25%, transparent 25.1%, transparent 75%, #ccc 75.1%, #ccc 100%), linear-gradient(45deg, #ccc 25%, white 25.1%, white 75%, #ccc 75.1%, #ccc 100%);
float: left;
}
.p75 {
margin:0 1em 1em;
height: 200px;
width:100%;
background-size: 19px 19px;
<div class="w">
<div class="r">0</div>
<div id="p75"></div>
</div>
<p>or decrease background-size of 1px</p>
<div class="p75"></div>
Another solution is to set the whole pattern from triangles and pretune values via css custom properties :
div {
--bgsize: 40;
--sq1: 0 0;
--sq2: calc(var(--bgsize) / 2 * 1px) calc(var(--bgsize) / 2 * 1px);
--sq3: var(--sq2);
--sq4: calc(var(--bgsize) * 1px ) 0px;
}
#a20:checked ~ div { --bgsize: 20; }
#a50:checked ~ div { --bgsize: 50; }
#a150:checked~ div { --bgsize: 150;}
#a100:checked~ div { --bgsize: 100;}
div {
height:200px;
background:
linear-gradient(45deg, gray 25% , transparent 26%),
linear-gradient(225deg, gray 25% , transparent 26%),
linear-gradient(45deg, gray 25% , transparent 26%),
linear-gradient(225deg, gray 25% , transparent 26%)
;
background-position:
var(--sq1) ,
var(--sq2) ,
var(--sq3) ,
var(--sq4);
background-size: calc(var(--bgsize) * 1px) calc(var(--bgsize) * 1px );
}
reset bg-size:<br>
<label for=a20>20px</label><input type=radio name=test id=a20>
<label for=a100>100px</label><input type=radio name=test id=a100>
<label for=a150>150px</label><input type=radio name=test id=a150>
<div></div>
demo with option to reset --bgsize and color
https://codepen.io/gc-nomade/pen/GRJGXwv

CSS gradients start to fade when generating more lines every x%

I'm trying to create a gradient that simply shows a red line every x%.
When I start generating more lines the red stripes seems to start fading into white.
the .four-stripes selector gives a nice result, but when I add one more red line, like in more-stripes everything starts to get blurry...
See codepen for an example:
div {
width: 1200px;
height: 20px;
}
.four-stripes {
background: linear-gradient(90deg,red 0.00% 0.27%,transparent 0.27% 1.92%,red 1.92% 2.19%,transparent 2.19% 3.84%,red 3.84% 4.11%,transparent 4.11% 5.75%,red 5.75% 6.03%,transparent 6.03% 100%);
}
.more-stripes {
background: linear-gradient(90deg,red 0.00% 0.27%,transparent 0.27% 1.92%,red 1.92% 2.19%,transparent 2.19% 3.84%,red 3.84% 4.11%,transparent 4.11% 5.75%,red 5.75% 6.03%,transparent 6.03% 7.67%,red 7.67% 7.95%,transparent 7.95% 100%)
}
<div>
<div class="four-stripes"></div>
<div class="more-stripes"></div>
</div>
Using "repeating-linear-gradient" may help.
div {
width: 1200px;
height: 20px;
}
.more-stripes {
background: repeating-linear-gradient(
90deg,
red,
red 5px,
transparent 5px,
transparent 20px
);
}
<div>
<div class="more-stripes"></div>
</div>
make the gradient easy and adjust the background-size.
div {
height: 20px;
margin:5px;
}
.four-stripes {
background:
linear-gradient(to right,red 5px,transparent 0 100%)
left/25% 100%;
}
.more-stripes {
background:
linear-gradient(to right,red 5px,transparent 0 100%)
left/15% 100%;
}
<div>
<div class="four-stripes"></div>
<div class="more-stripes"></div>
</div>
Or like this if you want to keep a fixed distance between stripes:
div {
height: 20px;
margin:5px;
}
.four-stripes {
background:
repeating-linear-gradient(to right,red 0 5px,transparent 0 40px)
left/calc(4*40px) 100% no-repeat;
}
.more-stripes {
background:
repeating-linear-gradient(to right,red 0 5px,transparent 0 40px)
left/calc(6*40px) 100% no-repeat;
}
<div>
<div class="four-stripes"></div>
<div class="more-stripes"></div>
</div>

CSS: how to make a circle with 60% one color and 40% other color around an image?

Is it possible to make a circle with 60% one color and 40% other color around an image.
I have tried using the below code,
//CSS
.waitlist .img-thumbnail {
border: 2px solid #dee2e6;
background: linear-gradient(90deg, #2A89F6 50%, transparent 50%),
linear-gradient(-90deg, #CCC 50%, transparent 50%);
}
//HTML
<img src="images/1.jpg" alt="" class="img-fluid rounded-circle img-thumbnail mb-2" width="100">
The output for above code is,
But I want the output as,
Is it possible to achieve the required output?
you can do it like this:
.box {
border-radius:50%;
display:inline-block;
padding:5px;
background:
linear-gradient(-40deg, grey 50%,transparent 0), /*adjust the deg value here to control the %*/
linear-gradient(to right, red 50%,transparent 0),
grey;
}
.box img {
border-radius:50%;
display:block;
}
<div class="box">
<img src="https://picsum.photos/100/100?image=1069" >
</div>