Is there a way to replicate the following texture/fill using only CSS? I want to use the same kind of diagonal lines over top other containers with different background fills, so I'm hoping there might be a way to do it in CSS without having to create patterns and using them as images.
Any ideas how I might be able to do this? I'm guessing that it'll probably have to be something like this:
<div id="gradientFill">
<div class="linePattern">
<!-- Content goes here -->
</div>
</div>
Is there a better solution? I don't want to run into problems with using alpha/transparency on the diagonal lines and then having the content be transparent as well.
SOLUTION POSTED BELOW.
You can use multiple background images on the button, so you have your standard gradient with the stripy gradient on top tiled using background-size:
.stripy {
background-image:
linear-gradient(45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent),
linear-gradient(bottom, rgb(83,84,84) 0%, rgb(181,181,181) 100%);
background-size:50px 50px, auto;
}
The stripes are a bit thick, but with a bit of experimentation it should be possible to get what you want.
A CORRECT SOLUTION:
jsFiddle: If you're not seeing the diagonal lines, it's because jsFiddle doesn't really like external links to hosted images from imgur. Just copy and paste the imgur url in another tap to get it in your cache, then reload the Fiddle.
The key to the solution is the relative positioning of the color background, and the absolute positioning of the texture/line overlay. For future visitors to this post, if you want to overlay a texture on an image, apply:
position:relative
...to your image div, and:
position:absolute
...to your overlay div.
<div id="alert">
Text goes here!
<div class="lines"></div>
</div>
#alert {
position:relative;
padding:10px;
box-shadow:0px 1px 1px #000, 0px 1px 1px #F5BFB1 inset;
background: #ea765a; /* Old browsers */
background: -moz-linear-gradient(top, #ea765a 0%, #d2583b 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ea765a), color-stop(100%,#d2583b)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ea765a 0%,#d2583b 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ea765a 0%,#d2583b 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ea765a 0%,#d2583b 100%); /* IE10+ */
background: linear-gradient(to bottom, #ea765a 0%,#d2583b 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ea765a', endColorstr='#d2583b',GradientType=0 ); /* IE6-9 */
}
.lines {
position:absolute;
width:100%;
height:100%;
top:0;
left:0;
background:url(../img/lines.png);
opacity:0.05;
}
Related
I am trying to create a class to apply to elements which will give them a gradient using CSS. The problem is that I want a class that contains NO COLOR- only opacity from 1.0 to 0. This way, I can "lay" it down on top of any element with any color and it will give it a gradient, basically starting with the original color and fading to white.
background: #ffffff; /* Old browsers */
background: -moz-linear-gradient(top, #ffffff 0%, #e9e9e9 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e9e9e9)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 0%,#e9e9e9 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 0%,#e9e9e9 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 0%,#e9e9e9 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffffff 0%,#e9e9e9 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#e9e9e9',GradientType=0 ); /* IE6-9 */
How do I do this without specifying any color?
This is not possible without specifying the colour to transition into. What you could do is use rgba() to define a color and then also its opacity, but only affecting the opacity itself is not possible. An example of a gradient you'd get when using rgba() would be:
background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 0%, rgba(233, 233, 233, 0) 100%); /* W3C */
that would transition between the two specified colours, going from completely transparent at the #e9e9e9 (which is the same as rgba(233, 233, 233, 1)) to completely opaque at the white. Again, this is an alternative to what you actually want, but transitioning opacity only is not possible.
PS: you can also transition translucent colours in older IE versions using #AARRGGBB format.
I have a div and background color is red. Now I'd like to make left 80% remain red, rest 20% on the right part to no color or transparent. Is it possible to alter css only without adding more divs or changing the padding of the div? I'd like div to remain it's original size.
.myClass
{
background: -moz-linear-gradient(top, rgba(30,87,153,0) 0%, rgba(41,137,216,0) 20%, rgba(255,48,48,1) 21%, rgba(255,0,0,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(30,87,153,0)), color-stop(20%,rgba(41,137,216,0)), color-stop(21%,rgba(255,48,48,1)), color-stop(100%,rgba(255,0,0,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(30,87,153,0) 0%,rgba(41,137,216,0) 20%,rgba(255,48,48,1) 21%,rgba(255,0,0,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(30,87,153,0) 0%,rgba(41,137,216,0) 20%,rgba(255,48,48,1) 21%,rgba(255,0,0,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(30,87,153,0) 0%,rgba(41,137,216,0) 20%,rgba(255,48,48,1) 21%,rgba(255,0,0,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(30,87,153,0) 0%,rgba(41,137,216,0) 20%,rgba(255,48,48,1) 21%,rgba(255,0,0,1) 100%); /* W3C */
}
result:
i don't think you can set multiple background colors for one div, but you could try:
div.twocolorish {
background-color: blue;
border-left: 20px solid green;
}
This would only work if you didn't need text (or other) to go over the part with the green border
You cannot use padding to achieve the partial coloring. A div can be colored in the background which makes the whole div to be colored with the given color. But you can use an outer div to achieve your desired result or use css3pie to achieve your desired result (especially in IE 8 and below). It has gradient options also.
<div style="width:500px; height:400px; ">
<div style="width:80%; height:100%; background-color:blue;">
</div>
</div>
The resource was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate as value and it is preloaded intentionally.
(index):6770 crbug/1173575, non-JS module files deprecated.
(anonymous) # (index):6770
(index):6770 crbug/1173575, non-JS module files deprecated
I'm getting my feet wet with CSS3 and I'm doing my best to convert a Photoshop comp to HTML.
I have multiple instances of a background (using background url) with differing heights and I'd like to apply a gradient on top of that background using rgba gradients (using the alpha channel). I'd obviously like to stay away from a static background image with the gradient built into the pixels.
Is there a way to do this in CSS by 'stacking' the gradient on top of the background url?
I'm guessing if I can't do it in one element, I would put a container inside my background element, float it and make the width and height fill the background element, but that seems pretty messy.
Any advice is appreciated! Thanks for your time!
Here are two examples of the same background and gradient but at different heights: a nav and a footer
The code would look something like this:
<nav>
<ul>
<li>Menu item 1</li>
<li>Menu item 2</li>
<li>Menu item 3</li>
<li>Menu item 4</li>
</ul>
</nav>
style:
nav {
background : url('repeating-background-image.png') repeat;
background: -moz-linear-gradient(top, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.65)), color-stop(100%,rgba(0,0,0,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%); /* Chrome10+,Safari5.1+ */
}
Is there a way to do this in CSS by 'stacking' the gradient on top of the background url?
Yes: CSS3 allows multiple background images, separated by commas.
As gradients behave like images, you can use them in conjunction with background images:
div {
width: 400px;
height: 400px;
background: -moz-linear-gradient(top, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0) 100%), url(http://www.pauldwaite.me.uk/images/professional.jpg); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.65)), color-stop(100%,rgba(0,0,0,0))), url(http://www.pauldwaite.me.uk/images/professional.jpg); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%), url(http://www.pauldwaite.me.uk/images/professional.jpg); /* Chrome10+,Safari5.1+ */
}
http://jsfiddle.net/kReNL/
This doesn't work in IE 8 or earlier, but then neither do CSS gradients. (Although Microsoft's filter property works in IE 8 and earlier, and that does support gradients with alpha transparency - see Can you use rgba colours in gradients produced with Internet Explorer’s filter property?).
http://jsfiddle.net/8gvZM/
background: #ffffff; /* old browsers */
background: -moz-linear-gradient(top, #ffffff 0%, #f6f6f6 47%, #ededed 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(47%,#f6f6f6), color-stop(100%,#ededed)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); /* IE10+ */
background: linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ededed',GradientType=0 ); /* IE6-9 */
and make a div above it with the background url on a lower opacity.
Is that what you mean?
Use CSS :before to create an additional (pseudo) element sitting on top of the original element.
The original element would have the image background, and the :after element would have the gradient, with an opacity setting so that the original element shows through it.
div {
width: (whatever size you want to set it to)
height: (ditto)
position:relative;
background:url('mainImage.jpg');
z-index:5;
}
div::before {
content:'';
width: .... (same as main div)
height: .... (same as main div)
position:absolute;
z-index:-3;
display:block;
opacity:0.5;
background: linear-gradient(to bottom, #8fc400 0%,#ff0000 100%); /* plus add the other browser-specific gradient styles too */
}
I've done a jsFiddle for you to demonstrate: see here
Hope that helps.
[EDIT] Changed the details of the answer above slightly in response to OP's comment. Now using :before rather than :after, and using z-index to layer things so that the actual text content is visible on top of both backgrounds.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need a help regarding the background of the website, below are the details I want to know:
Different gradient background on left and right of the website (It should work also on all the IE Browser).
How will I do that using the HTML/CSS?
Please help. Thanks!
If you want it to work on older browsers, you could write something like this:
http://jsfiddle.net/ftcjZ/2/
This is more complicated html - it all depands on what exact browser do you need to run this on.
CSS:
.bg-left { background: url('http://cdn.imghack.se/images/3be5ae39376f069c0f49dd0cf09e74c7.png') top left no-repeat; }
.bg-right { padding: 0 118px 0 125px; background: url('http://cdn.imghack.se/images/ae53c28777043687b9a110e867798cb5.png') top right no-repeat; }
.main-content { height: 800px; background-color: white; }
HTML:
<div class="bg-left">
<div class="bg-right">
<div class="main-content">
</div>
</div>
</div>
EDIT: I updated the code changing margin for main container to padding in .bg-right as this is more reliable solution.
Generate your body background here
Create centered container div with and transparent curtain image background
Create centered website-container div in container div 100% height and set the background to the grey color
Good luck.
Clarification for Quentin's comments: use diagonal gradient:
background: #b5bdc8; /* Old browsers */
background: -moz-linear-gradient(-45deg, #b5bdc8 0%, #828c95 36%, #28343b 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right bottom, color-stop(0%,#b5bdc8), color-stop(36%,#828c95), color-stop(100%,#28343b)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(-45deg, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(-45deg, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(-45deg, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* IE10+ */
background: linear-gradient(135deg, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
this is method by which you can make background texture through CSS
background: linear-gradient(left, white 50%, #8b0 50%);
background-size: 100px 100px;
note:you can change the value of polarity and linearity and then define different background throughout the page through background-position
Also check this out.-->http://lea.verou.me/css3patterns/
Its also possible to use image as a gradient base. open this noisetexturegenerator.com and try below thing
body { background-image:url('gradient image'); background-repeat:repeat-x; }
One best idea to work in all the browsers and most of the resolutions is, using a huge image, with a separation in the middle, having a width of 2048 and make the vertical scrolling fixed.
This would work in all the browsers.
body {background: url("huge-image.png") center top no-repeat;}
To all who say bg will be big.
An image of resolution: 19488 x 3552 and the size is just 51 KB. Check it out:
(source: znate.ru)
You can use css-gradient. This should work with all browsers.
background-image: linear-gradient(left top, rgb(232,232,232) 16%, rgb(122,122,122) 58%, rgb(115,115,115) 79%);
background-image: -o-linear-gradient(left top, rgb(232,232,232) 16%, rgb(122,122,122) 58%, rgb(115,115,115) 79%);
background-image: -moz-linear-gradient(left top, rgb(232,232,232) 16%, rgb(122,122,122) 58%, rgb(115,115,115) 79%);
background-image: -webkit-linear-gradient(left top, rgb(232,232,232) 16%, rgb(122,122,122) 58%, rgb(115,115,115) 79%);
background-image: -ms-linear-gradient(left top, rgb(232,232,232) 16%, rgb(122,122,122) 58%, rgb(115,115,115) 79%);
background-image: -webkit-gradient(
linear,
left top,
right bottom,
color-stop(0.16, rgb(232,232,232)),
color-stop(0.58, rgb(122,122,122)),
color-stop(0.79, rgb(115,115,115))
);
Older versions of IE don't support gradient, so you have to make second div container, which will be transparent on other browsers.
And define new css for older versions of IE, e.g.:
<!--[if lte IE 8]>
<style>
.diaggradientback
{
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
overflow:hidden;
filter: progid:DXImageTransform.Microsoft.gradient(GradientType='1', startColorstr='#ffa885', endColorstr='#330000');
}
.diaggradientfront
{
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
overflow:hidden;
filter: progid:DXImageTransform.Microsoft.gradient(GradientType='0', startColorstr='#bbffa885', endColorstr='#bb330000');
}
</style>
<![endif]-->
I have a solid image, a .JPG, with no transparency (seeing as .JPG's cannot have an alpha layer). However, since the client would not have the ability to create an image that fades one image edge to transparency, they want to input a solid .JPG and have it fade via code. It should be noted that I've got this image set to be the background right now, it's not the src of a <img> tag. Is this possible in CSS3 and if so, how would it be accomplished?
Example image:
Desired result:
I believe you can do something with the CSS3 mask-image attribute along with CSS3 linear-gradient background:
-webkit-mask-image: -webkit-linear-gradient(left, rgba(0,0,0,1), rgba(0,0,0,0))
Here is a sample that I created to you. Since it's a new CSS3 thing compatible browsers are Chrome and Safari at this moment (Webkit browsers).
You can get true transparency via CSS masking:
http://www.webkit.org/blog/181/css-masks/
Support for it is still quite limited, though. However, in Webkit browsers, you can use something like:
.masked {
-webkit-mask-image: -webkit-gradient(linear, left top, right top, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
}
<div class="masked">Your content here</div>
This will work with all the content in any div (including the background), but this won't work in most browsers.
You could use a slice-and-animate approach similar to Nivo Slider, but that is an awful lot of work for what may not end up being a useful effect.
img,.over{
width:100px;
height:100px;
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(left, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(100%,rgba(255,255,255,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 ); /* IE6-8 */
position:absolute;
}
<div >
<img src="http://ts1.mm.bing.net/th?id=I.4763892546143716&pid=1.1" alt="test"/>
<div class="over"></div>
</div>
DEMO