Pretty sure this is possible with CSS3, but I can't figure out how. Given this design pattern
create the horizontal hash marks in CSS3 that expands or contracts to fill a responsive container (as background?).
Chris Coyier proffered this Vertical Stripe CodePen, but how can it be revised to re-create the pattern above?
HTML
<div class="module">
<h2 class="stripe-6">Vertical</h2>
<p>You could do some schenigans where you have a big rotated element within
this header area (with hidden overflow) that has these stripes. That way
you could get away with not using repeating-linear-gradient.</p>
</div>
CSS
.module {
background: white;
border: 1px solid #ccc;
margin: 3%;
> h2 {
padding: 1rem;
margin: 0 0 0.5rem 0;
}
> p {
padding: 0 1rem;
}
}
.stripe-6 {
color: black;
background: repeating-linear-gradient(
to right,
#f6ba52,
#f6ba52 10px,
#ffd180 10px,
#ffd180 20px
);
}
Here's a larger, higher-contrast image to see the pattern better (thanks #Martin!)
Yes, it is definitely possible to create this pattern using linear-gradient background images. Unlike the pattern generated by Chris Coyier, this would require two linear gradients as there are two stripes of different heights and gaps.
.bg-pattern{
height: 50px;
width: 100%;
background-color: rgb(115,199,192);
background-image: linear-gradient(to right, rgba(0,0,0,0.25) 6px, transparent 6px), linear-gradient(to right, transparent 12px, rgba(0,0,0,0.25) 12px, rgba(0,0,0,0.25) 14px, transparent 14px, transparent 20px, rgba(0,0,0,0.25) 20px, rgba(0,0,0,0.25) 22px, transparent 22px, transparent 28px, rgba(0,0,0,0.25) 28px, rgba(0,0,0,0.25) 30px, transparent 30px, transparent 36px, rgba(0,0,0,0.25) 36px, rgba(0,0,0,0.25) 38px, transparent 38px);
background-repeat: repeat-x;
background-size: 44px 30px, 44px 20px;
background-position: 8px 0px;
border-top: 2px solid rgba(0,0,0,0.25);
}
<div class='bg-pattern'></div>
Below snippet has the same pattern added into your code:
.module {
background: white;
border: 1px solid #ccc;
margin: 3%;
}
.module > h2 {
padding: 1rem;
margin: 0 0 0.5rem 0;
}
}
.module > p {
padding: 0 1rem;
}
.stripe-6 {
color: black;
height: 50px;
background-color: rgb(115, 199, 192);
background-image: linear-gradient(to right, rgba(0, 0, 0, 0.25) 6px, transparent 6px), linear-gradient(to right, transparent 12px, rgba(0, 0, 0, 0.25) 12px, rgba(0, 0, 0, 0.25) 14px, transparent 14px, transparent 20px, rgba(0, 0, 0, 0.25) 20px, rgba(0, 0, 0, 0.25) 22px, transparent 22px, transparent 28px, rgba(0, 0, 0, 0.25) 28px, rgba(0, 0, 0, 0.25) 30px, transparent 30px, transparent 36px, rgba(0, 0, 0, 0.25) 36px, rgba(0, 0, 0, 0.25) 38px, transparent 38px);
background-repeat: repeat-x;
background-size: 44px 30px, 44px 20px;
background-position: 8px 0px;
border-top: 2px solid rgba(0, 0, 0, 0.25);
}
<div class="module">
<h2 class="stripe-6">Vertical</h2>
<p>You could do some schenigans where you have a big rotated element within this header area (with hidden overflow) that has these stripes. That way you could get away with not using repeating-linear-gradient.</p>
</div>
Related
I am trying to use CSS linear-gradient and box-shadow to make an image have a box-shadow on 3 sides (top, right, and left) while also having a "fade-to-white" on the bottom edge of the image.
I don't want the image url in the CSS, I want to use the img tag in the html.
This is what I have so far: https://codepen.io/adelelanders/pen/rNVMxZw however the bottom edge is still showing the box-shadow (dark line). I want the bottom edge to fade to white.
img {
max-width: 100%;
}
.image-container {
max-width: 100%;
width: 600px;
}
.white-fade::after {
display: block;
position: relative;
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0, #fff 100%);
margin-top: -150px;
height: 150px;
width: 100%;
content: '';
}
.box-shadow {
border-radius: 5px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
}
<div class="image-container white-fade">
<img class="box-shadow" src="https://cdn.pixabay.com/photo/2019/03/18/06/46/cyber-4062449__340.jpg" />
</div>
consider mask instead of gradient
img {
max-width: 100%;
}
.image-container {
max-width: 100%;
width: 600px;
padding:20px; /* Some padding for the shadow */
-webkit-mask:
linear-gradient(#fff,#fff) top/100% calc(100% - 149px) no-repeat,
linear-gradient(#fff,transparent) bottom/100% 150px no-repeat;
mask:
linear-gradient(#fff,#fff) top/100% calc(100% - 149px) no-repeat,
linear-gradient(#fff,transparent) bottom/100% 150px no-repeat;
}
.box-shadow {
border-radius: 5px;
display:block;
box-shadow: 0 10px 20px rgba(0, 0, 0, 1), 0 6px 6px rgba(0, 0, 0, 1);
}
<div class="image-container white-fade">
<img class="box-shadow" src="https://cdn.pixabay.com/photo/2019/03/18/06/46/cyber-4062449__340.jpg" />
</div>
I have a progress bar that show from left to right. I need to make another which is same style progress but will show from right to left.
Here is my style definition:
progress, progress[role] {
-webkit-appearance: none;
appearance: none;
border: none;
background-size: auto;
height: 50px;
width: 100%;
padding-top: 10px;
}
progress[value]::-webkit-progress-bar {
background-color: grey;
border-radius: 2px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}
progress[value]::-webkit-progress-value {
background-image:
-webkit-linear-gradient(-45deg,
transparent 33%, rgba(0, 0, 0, .1) 33%,
rgba(0,0, 0, .1) 66%, transparent 66%),
-webkit-linear-gradient(top,
rgba(255, 255, 255, .25),
rgba(0, 0, 0, .25)),
-webkit-linear-gradient(left, #09c, #f44);
border-radius: 2px;
background-size: 35px 20px, 100% 100%, 100% 100%;
}
.valuebar {
position: relative;
}
.valuebar h3 {
color: #fff;
left: 1em;
line-height: 1;
position: absolute;
}
I used sample from the web which uses ::-webkit-progress-value.
How can I make it render from right to left?
Generally, many elements flip their horizontal rendering when their direction attribute is changed from ltr (which is the default) to rtl, which stands for right-to-left (to be compatible with right-to-left languages, such as Arabic or Hebrew).
The <progress> element is not different. Just give CSS something to cling to (such as a special class) and set its direction: rtl;.
Here is a small snippet based on the code you posted.
/* this is the important bit */
progress.rtl {
direction: rtl;
}
progress,
progress[role] {
-webkit-appearance: none;
appearance: none;
border: none;
background-size: auto;
height: 50px;
width: 100%;
padding-top: 10px;
}
progress[value]::-webkit-progress-bar {
background-color: grey;
border-radius: 2px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}
progress[value]::-webkit-progress-value {
background-image: -webkit-linear-gradient(-45deg, transparent 33%, rgba(0, 0, 0, .1) 33%, rgba(0, 0, 0, .1) 66%, transparent 66%), -webkit-linear-gradient(top, rgba(255, 255, 255, .25), rgba(0, 0, 0, .25)), -webkit-linear-gradient(left, #09c, #f44);
border-radius: 2px;
background-size: 35px 20px, 100% 100%, 100% 100%;
}
.valuebar {
position: relative;
}
.valuebar h3 {
color: #fff;
left: 1em;
line-height: 1;
position: absolute;
}
<progress value="59" max="100">59%</progress>
<br />
<progress class="rtl" value="59" max="100">59%</progress>
I don't know what is your markup, as you did not post it, but you may need to adjust the .valuebar positioning.
Here is a code pen you can toy with.
I have a program in html that has a progress element. It turns blue in firefox, but refuses to work in chrome, and it turns green, which I don't want. my code
progress {
color: #0063a6;
font-size: .6em;
line-height: 1.5em;
text-indent: .5em;
width: 30em;
height: 3em;
border: 1px solid #0063a6;
background: #fff;
}
<progress value ="50" max ="100"></progress>
You need to do two things. First reset the style of the progressbar to it's default values and then target the appearance with a browser specific pseudo class like so:
progress {
-webkit-appearance: none;
appearance: none;
}
progress::-webkit-progress-bar {
background-color: #eee;
border-radius: 2px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}
styling the bar itself is done using background-image:
progress[value]::-webkit-progress-value {
background-image:
-webkit-linear-gradient(-45deg,
transparent 33%, rgba(0, 0, 0, .1) 33%,
rgba(0,0, 0, .1) 66%, transparent 66%),
-webkit-linear-gradient(top,
rgba(255, 255, 255, .25),
rgba(0, 0, 0, .25)),
-webkit-linear-gradient(left, #09c, #f44);
border-radius: 2px;
background-size: 35px 20px, 100% 100%, 100% 100%;
}
Read the full article here:
https://css-tricks.com/html5-progress-element/
So, I'm trying to create an border of 1px, with a color 30% green, 20% red, 27% blue, with 70% of opacity, it is possible? I'm using sass but I have not found a way to make this
.box
width: 100px
height: 100px
background: gray
margin: 50px auto 0 auto
border-color: #ff0000 #0000ff
My pen: http://codepen.io/mejingjard/pen/xwxLKO?editors=110
Yes it's possible, and it's actually really simple with rgba()
border-color: rgba(20%,30%,27%,0.7);
Read about this and more sass color functions at
http://sass-lang.com/documentation/Sass/Script/Functions.html#rgba-instance_method
You can give this a try, however this alternative is with four borders, not the three. With RGBA you can change the opacity. You can visit http://www.cssportal.com/css3-rgba-generator/ to generate the CSS3 RGBA colours; there you can also change the opacity.
div {
width: 100px;
height: 100px;
margin: auto;
}
.one {
border-top: 1px solid rgba(0, 255, 0, 0.7);
border-right: 1px solid rgba(255, 0, 0, 0.7);
border-bottom: 1px solid rgba(0, 0, 255, 0.7);
border-left: 1px solid rgba(255, 0, 0, .5);
<div class="one"></div>
Alternatively if you wanted to go for more of a gradient look you can try applying a CSS3 gradient within a pseudo-element, however only two border colors are adopted, and it's without the opacity.
.one{
margin: auto;
width: 100px;
height: 100px;
border: 1px solid transparent;
-moz-border-image: -moz-linear-gradient(top, #E93478 0%, #FF0 100%);
-webkit-border-image: -webkit-linear-gradient(top, #E93478 0%, #FF0 100%);
border-image: linear-gradient(to bottom, #E93478 0%, #FF0 100%);
border-image-slice: 1;}
<div class="one"></div>
I would like to have a mask that's fading out 16px from both sides.
So like: 16px fading in - white - 16px fading out.
What I got is this: DEMO
-webkit-mask-image: linear-gradient(to right, transparent, white), linear-gradient(to left, transparent, white);
-webkit-mask-repeat: no-repeat, no-repeat;
-webkit-mask-size: 16px 40px, 16px 40px;
-webkit-mask-position: 0 0, 100% 0;
-webkit-mask-origin: padding-box, padding-box;
The only problem is that it's not visible in the middle. How can i fix this?
One option is to add a third gradient (which will actually be uniformly white) covering the whole surface, and use -webkit-mask-composite: copy to make sure the other two gradients replace the parts on the sides:
-webkit-mask-image: linear-gradient(to right, transparent, white), linear-gradient(to left, transparent, white), linear-gradient(to right, white, white);
-webkit-mask-composite: copy;
-webkit-mask-repeat: no-repeat, no-repeat, no-repeat;
-webkit-mask-size: 16px 40px, 16px 40px, 100% 100%;
-webkit-mask-position: 0 0, 100% 0, 0 0;
-webkit-mask-origin: padding-box, padding-box, padding-box;
Demo: http://codepen.io/anon/pen/crEyL
Note that of course, all of this only works on WebKit browsers.
Try this.
Here is the codepen for demo CODEPEN
Also I have attached the code, If you have any doubt let me know.
html
<div class="div">
<span>Example Program</span>
</div>
CSS
.div {
box-shadow: 0 16px 0px 0px white, 0 -16px 0px 0px white, 12px 0 15px -4px rgba(31, 73, 125, 0.8), -12px 0 15px -4px rgba(31, 73, 125, 0.8);
-webkit-mask-position: 0 0, 100% 0;
-webkit-mask-size: 16px 40px, 16px 40px;
width: 30%;
height: 40px;
margin: 50px;
background: red;
}
span {
display: block;
background: rgb(255, 255, 255);
height: 40px;
}
This did the trick. Pretty hacky solution.
-webkit-mask-image: linear-gradient(white, white),linear-gradient(to right, white, transparent), linear-gradient(to left, white, transparent);
-webkit-mask-repeat: repeat,no-repeat, no-repeat;
-webkit-mask-size: 100% 100%,16px 100%, 16px 100%;
-webkit-mask-position: 0 0,0 0, 100% 0;
-webkit-mask-origin: padding-box, padding-box, padding-box;
-webkit-mask-composite: source-out;
Solution demo