So I have an image slider behind a div with scrolling text content. I want the edges of the scrolling text div to feather into whatever is displaying behind it, so the text appears/disappears nicely when it scrolls in/out.
I tried adding an inset box shadow and linear gradients, but when the scrolling text has a transparent background you can see the shading around the text, fading into black, rather than transparent.
This is what I have:
This is what I want:
How do I do it with CSS?
You shouldn't need my code as it's not a bug, but here's some anyway.
<style>
#slider, #text, #text_overlay {
position:absolute;
width: 100%;
}
#slider {
height: 350px;
}
#text, #text_overlay {
top: 200px;
height: 100px;
}
#text {
z-index: 10;
}
#text_overlay {
z-index: 20;
background-image: linear-gradient(to right, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 3%, rgba(0,0,0,0) 97%, rgba(0,0,0,1) 100%);
}
</style>
<div id="slider">
<img src='https://www.w3schools.com/howto/img_fjords.jpg' />
</div>
<div id="text">Some text etc blah blah blah</div>
<div id="text_overlay"></div>
Solved this issue using -webkit-mask-image and a gradient as the mask on the text div. No need for the text_overlay div anymore, and works with changing backgrounds :)
#text {
-webkit-mask-image: linear-gradient(
to right, /* gradient direction */
rgba(0,0,0,0) 0%, /* transparent left 3% */
rgba(0,0,0,1) 3%, /* visible in the middle start */
rgba(0,0,0,1) 97%, /* visible in the middle end */
rgba(0,0,0,0) 100% /* transparent right 3% */
);
}
Full code:
<style>
#container {
position:relative;
height: 350px;
width: 100%;
}
#slider, #text {
position:absolute;
width: 100%;
}
#slider {
height: 100%;
}
#text {
top: 200px;
height: 100px;
z-index: 10;
-webkit-mask-image: linear-gradient(
to right, /* gradient direction */
rgba(0,0,0,0) 0%, /* transparent left 3% */
rgba(0,0,0,1) 3%, /* visible in the middle start */
rgba(0,0,0,1) 97%, /* visible in the middle end */
rgba(0,0,0,0) 100% /* transparent right 3% */
);
}
</style>
<div id="container">
<div id="slider">
<img src='https://www.w3schools.com/howto/img_fjords.jpg' />
</div>
<div id="text">Some text etc blah blah blah</div>
</div>
Related
currently I have a div container with text in it.
div {
height: 200px;
background: red;
}
p {
text-align: center;
}
<div>
<p>
Text goes here
</p>
</div>
and I want this div container being a parallelogram with a vertically centered text in it.
div {
height: 200px;
background: red;
clip-path: polygon(0 25%, 100% 0, 100% 25%, 0 50%);
}
p {
text-align: center;
}
<div>
<p>
Text goes here
</p>
</div>
as you can see here, the text completely disappears because the css only works for the div container.
How can I make the text appear in the vertical center of this parallelogram?
Edit:
I don't know if using
clip-path: polygon(0 25%, 100% 0, 100% 25%, 0 50%);
is the best way to create a div container that is skew.
Use gradient to create the shape as background and you simply need to center the text using any common way. You will have better support than clip-path.
div.container {
height: 120px;
line-height:120px;
background-image:
/*Top triangle*/
linear-gradient(to bottom right,transparent 49%,red 51%),
/*Bottom triangle*/
linear-gradient(to top left,transparent 49%,red 51%);
background-position:top, bottom; /* One on the top and the other on the bottom*/
background-size:100% 50%; /*both will be 100% width and 50% height*/
background-repeat:no-repeat; /*don't repeat*/
}
p {
text-align: center;
}
<div class="container">
<p>
Text goes here
</p>
</div>
And if you want to rely on clip-path better use these values to cover the whole div and you simply need to adjust the height of div to control the height of shape:
div.container {
height: 120px;
line-height:120px;
background:red;
-webkit-clip-path: polygon(0 50%, 100% 0%, 100% 50%, 0% 100%);
clip-path: polygon(0 50%, 100% 0%, 100% 50%, 0% 100%);
}
p {
text-align: center;
}
<div class="container">
<p>
Text goes here
</p>
</div>
I have a page on my site that has a gray background color that I am trying to add gradient to it in a different way than just a left to right. My page has an outer div that takes up 100% of the page's width. I then have an inner div that takes up 80% of the page's with, but auto aligned. I was wondering how, if I can, do a full cycle of my gradient within each side (left & right) of the outer div, the 10% part that shows before the inner div starts.
So say an A equals 10%, and everytime I put two colors together, that is the gradient taking place within that 10%. I want to do this...
#181818, #282828 AAAAAAAA #282828, #181818
How can I do this?
HTML
<div class="graypage">
<div class="homeimg">
gfdsgsg
</div>
</div>
CSS
.graypage, .whitepage { margin: 0 auto; }
/*------Page Wraps--------*/
.graypage {
width: 100%;
left: 0;
right: 0;
min-height: 100%;
background: -webkit-linear-gradient(left, #282828, #181818); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, #282828, #181818); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, #282828, #181818); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, #282828, #181818); /* Standard syntax */
}
.homeimg {
background-image: url("/images/bright_lights_small.jpg");
width: 80%;
background-size: cover;
background-position: center;
height: 100%;
position: absolute;
margin-right: 10%;
margin-left: 10%;
}
As I understand it, you'd like two bars - one on the left of the outerDiv and the other on the right. Each of these bars you'd like to be 10% of the page width. You'd also like each bar to cycle through the colours #181818, #282828, #aaaaaa, #282828, #181818.
I'd just use a linear-gradient with 12 colour-stops. Something like this:
#outerDiv
{
background: linear-gradient(to right,
#181818 0%,#282828 2%,#aaaaaa 4%,#aaaaaa 6%,#282828 8%,#181818 10%,
#181818 90%,#282828 92%,#aaaaaa 94%,#aaaaaa 96%,#282828 98%,#181818 100%); /* W3C */
width: 100%;
}
Credit: http://www.colorzilla.com/gradient-editor/
Here it's applied to the outer div and a solid colour is applied to the (80% as wide) inner div.
EDIT: Here's the (now updated) html and css used.
<style>
body
{
margin: 0;
padding: 0;
}
#outerDiv
{
background: linear-gradient(to right,
#181818 0%,#282828 10%,
#282828 90%,#181818 100%); /* W3C */
width: 100%;
}
#innerDiv
{
width: 80%;
margin: auto;
background-color: #dddddd;
}
</style>
</head>
<body>
<div id='outerDiv'>
<div id='innerDiv'>
<button id='goBtn'>Change the text</button>
<div class="menu-wrapper">
<ul>
<li>WORD1</li>
<li>WORD2</li>
<li>WORD3</li>
<li>WORD4</li>
</ul>
</div>
</div>
</div>
</body>
This code produces the following result:
Bacically, you have 2 posibilities here. You can set a repeating gradient
div {
width: 500px;
height: 100px;
background: repeating-linear-gradient(to right, yellow 0%, green 10%);
}
<div></div>
And you can play with the background-size
div {
width: 500px;
height: 100px;
background: linear-gradient(to right, yellow, green);
background-size: 10% 100%;
}
<div></div>
I'm adding a gradient on top of a background-imagewith a single property:
background-image: -webkit-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,0.5)), url('/image-1.jpg');
All my elements with class .gradient have the gradient, but the image changes for each element so I wanted to know if I could set the gradient as a property of .gradient and then change the image url in each element.
<div class="gradient image-1"></div>
<div class="gradient image-2"></div>
<div class="gradient image-3"></div>
Something like this:
.gradient // Add the gradient just once
{
background-color: background-image: -webkit-linear-gradient(top, rgba(0,0,0,0), rgba(0,0,0,0.5);
}
.image-1 // Change the image for each element
{
background-image: url('/image-1.jpg');
}
.image-2
{
background-image: url('/image-2.jpg');
}
There is no way you can define and override only one of the multiple background layer, so you need to re declare for each..
Demo
div {
height: 100px;
width: 100px;
background: #eee;
margin: 20px;
background: url('http://www.google.com/images/icons/product/chrome-48.png'), linear-gradient(to bottom, #a90329 0%,#8f0222 44%,#6d0019 100%);
}
div:nth-of-type(2) {
background: url('http://www.digitalkonline.com/Portals/86261/images/agree-icon.png'), linear-gradient(to bottom, #a90329 0%,#8f0222 44%,#6d0019 100%)
}
The other way to achieve this is to have background on the parent element, and another background on the child element, so a nesting trick
Demo 2
div.wrap {
height: 100px;
width: 100px;
background: #eee;
margin: 20px;
background: linear-gradient(to bottom, #a90329 0%,#8f0222 44%,#6d0019 100%);
}
div.wrap div {
height: 100%;
width: 100%;
}
div.hold > div.wrap:nth-of-type(1) > div {
background: url('http://www.digitalkonline.com/Portals/86261/images/agree-icon.png');
}
div.hold > div.wrap:nth-of-type(2) > div {
background: url('https://www.google.com/images/icons/product/chrome-48.png');
}
I am not sure if it will work with gradient.
However when we want to add 2 images I use background-size:contain;
background-image: URL("../images/imageName1.png"), URL("../images/Icone/imageName2.png");
background-size:contain;
background-repeat: repeat-x, no-repeat;
The first repeat will be for the first image and so on.
So I'm in the process of making a drag and drop browser 'dress up' type game. However, for some reason, I can't seem to position my images - either the draggable image or the doll base. I am able to drag and drop the draggable image, but I can't change their initial positions.
I've changed their position types, tried using top/bottom/left/right, margin, and even padding to move the images to where I want them, but they absolutely will not move!
Here's the HTML/CSS I'm using:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<style>
<!--Page Styling-->
html, body{
background-color:#5C5C5C;
height: 100%;
width: 100%;
overflow: hidden;
}
#banner{
background: rgb(143,250,138); /* Old browsers */
background: -moz-linear-gradient(top, rgba(143,250,138,1) 0%, rgba(127,239,127,1) 10%, rgba(109,223,115,1) 25%, rgba(107,229,115,1) 37%, rgba(106,236,114,1) 50%, rgba(74,226,82,1) 51%, rgba(136,242,122,1) 83%, rgba(175,252,142,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(143,250,138,1)), color-stop(10%,rgba(127,239,127,1)), color-stop(25%,rgba(109,223,115,1)), color-stop(37%,rgba(107,229,115,1)), color-stop(50%,rgba(106,236,114,1)), color-stop(51%,rgba(74,226,82,1)), color-stop(83%,rgba(136,242,122,1)), color-stop(100%,rgba(175,252,142,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(143,250,138,1) 0%,rgba(127,239,127,1) 10%,rgba(109,223,115,1) 25%,rgba(107,229,115,1) 37%,rgba(106,236,114,1) 50%,rgba(74,226,82,1) 51%,rgba(136,242,122,1) 83%,rgba(175,252,142,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(143,250,138,1) 0%,rgba(127,239,127,1) 10%,rgba(109,223,115,1) 25%,rgba(107,229,115,1) 37%,rgba(106,236,114,1) 50%,rgba(74,226,82,1) 51%,rgba(136,242,122,1) 83%,rgba(175,252,142,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(143,250,138,1) 0%,rgba(127,239,127,1) 10%,rgba(109,223,115,1) 25%,rgba(107,229,115,1) 37%,rgba(106,236,114,1) 50%,rgba(74,226,82,1) 51%,rgba(136,242,122,1) 83%,rgba(175,252,142,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(143,250,138,1) 0%,rgba(127,239,127,1) 10%,rgba(109,223,115,1) 25%,rgba(107,229,115,1) 37%,rgba(106,236,114,1) 50%,rgba(74,226,82,1) 51%,rgba(136,242,122,1) 83%,rgba(175,252,142,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#8ffa8a', endColorstr='#affc8e',GradientType=0 ); /* IE6-9 */
font-size: 20px;
font-family: 'Arial Black', sans-serif;
width: 100%;
margin-left: -10px;
text-align: center;
z-index: 99999;
position: fixed;
}
#holder{
position: absolute;
height: 800px;
width: 900px;
background-color: #838B8B;
margin-left: -10px;
margin-top: -300px;
z-index: -1;
}
<!--Bodies-->
#body1 {
position: absolute;
right: 0;
height: auto;
width: 200px;
z-index: 1;
}
<!--Parts-->
#breath{
position: relative;
left: 10px;
}
</style>
<!--Draggable Scripts-->
<script>
$(function() {
$( "#breath" ).draggable();
});
</script>
<!--End Draggable Scripts-->
</head>
<body>
<div id="banner">Homestuck Character Editor</div>
<div id="body1"><img src="http://i.imgur.com/aO3GWBO.png"draggable="false"/></div>
<div id="holder"></div>
<div id="breath">
<img src="http://i.imgur.com/iAmOFlH.png"/>
</div>
</body>
</html>
You positioned the div on the right, but the image is still on the left. Since div elements are blocks, they fill 100% of their parent. In this case, the parent is 100%. You can get the image on the right side of the screen by selecting it, and shifting the image itself. I used the following:
#body1 img {
position:absolute;
right:0;
}
The fiddle.
I have a background image for a hero element on a website that I'm working on. I want to make the background image in the .hero div be on a gradient from transparency to complete opacity on the edges so the backgrounds of both divs blend into each other.
To illustrate, here's the code that I'm using right now in the body of my index.html:
<div class="hero">
<div class="hero-inner">
<h1>My awesome hero element</h1>
</div>
</div>
... and this is what's in my style.css
.hero {
background-color: black;
width: 800px;
}
.hero-inner {
width: 700px;
height: 200px;
margin: auto;
background-image: url('http://i.imgur.com/PXzVXmR.png');
}
.hero-inner h1 {
position: absolute;
font-family: Arial, sans-serif;
color: white;
padding: 10px;
background-color: rgba(0, 0, 0, 0.7);
left: 50px;
top: 20px;
font-size: 48px;
}
Here's the jsFiddle. How would I make the background image in .hero-inner blend in with the background color of .hero on the edges? I've got a similar effect on Photoshop that does the job but I'd like to know if this could be done with CSS3 gradients
You can draw radial background gradient, but code is really ugly and looks heavy.
Here is a gradient editor that may be useful: http://www.colorzilla.com/gradient-editor/
background: -moz-radial-gradient(center, ellipse cover, rgba(255,48,48,1) 23%, rgba(205,57,71,1) 40%, rgba(80,79,130,0) 83%, rgba(30,87,153,0) 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(23%,rgba(255,48,48,1)), color-stop(40%,rgba(205,57,71,1)), color-stop(83%,rgba(80,79,130,0)), color-stop(100%,rgba(30,87,153,0)));
background: -webkit-radial-gradient(center, ellipse cover, rgba(255,48,48,1) 23%,rgba(205,57,71,1) 40%,rgba(80,79,130,0) 83%,rgba(30,87,153,0) 100%);
background: -o-radial-gradient(center, ellipse cover, rgba(255,48,48,1) 23%,rgba(205,57,71,1) 40%,rgba(80,79,130,0) 83%,rgba(30,87,153,0) 100%);
background: -ms-radial-gradient(center, ellipse cover, rgba(255,48,48,1) 23%,rgba(205,57,71,1) 40%,rgba(80,79,130,0) 83%,rgba(30,87,153,0) 100%);
background: radial-gradient(ellipse at center, rgba(255,48,48,1) 23%,rgba(205,57,71,1) 40%,rgba(80,79,130,0) 83%,rgba(30,87,153,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff3030', endColorstr='#001e5799',GradientType=1 );