I am trying to put a small gradient on the bottom of a scrolling div. I've based my solution on the accepted answer to this SO thread. The gradient shows up fine, but when I scroll the content in the div, the bottom of the gradient moves. I need it to remain in place so that the content scrolls independently of the gradient. I've tried several combinations of position: fixed, position: relative, and position: relatve to no avail. What have I missed?
Relevant markup:
<div class="resultListContainer">
<ul class="result">
<li><span class="resultPermitNumber resultElement">B123456789</span></li>
<li><span class="resultPermitType resultElement">FINAL</span></li>
<li><span class="resultDisplayAddress resultElement">41975 LOUDOUN CENTER PL SE, LEESBURG, VA 20175</span></li>
</ul>
<!-- Lots more of the ul. -->
</div>
Relevant CSS:
.resultListContainer {
border: 1px solid #000;
height: 400px;
width: 40em;
overflow-y: scroll;
font-size: 1em;
position: relative;
}
.resultListContainer::before {
background-image: linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background-image: -moz-linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background-image: -ms-linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background-image: -o-linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background-image: -webkit-linear-gradient( top, rgba( 255, 255, 255, 0 ) 95%, rgba( 255, 255, 255, 1 ) 100% );
content: "\00a0";
height: 100%;
position: absolute;
width: 100%;
}
.result {
margin-bottom: 0;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
list-style-type: none;
}
The result:
Because your element is positioned absolute, it's position is absolute to the parent element so when you scroll it scrolls with your content. What you want is your ul to scroll. I have quickly rewritten yours, but below I've got a simplified and cleaned up version:
.resultListContainer {
border: 1px solid #000;
height: 400px;
width: 40em;
font-size: 1em;
position: relative;
}
.resultListContainer::before {
background-image: linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background-image: -moz-linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background-image: -ms-linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background-image: -o-linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background-image: -webkit-linear-gradient( top, rgba( 255, 255, 255, 0 ) 95%, rgba( 255, 255, 255, 1 ) 100% );
content: "\00a0";
height: 100%;
position: absolute;
width: 100%;
z-index: 2;
pointer-events: none;
}
.result {
position: absolute;
left: 0;
top: 0;
margin: 0;
box-sizing: border-box;
z-index: 1;
width: 100%;
height: 100%;
margin-bottom: 0;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
list-style-type: none;
overflow-y: scroll;
}
.result li {
height: 100px;
background: red;
}
<div class="resultListContainer">
<ul class="result">
<li><span class="resultPermitNumber resultElement">B123456789</span></li>
<li><span class="resultPermitType resultElement">FINAL</span></li>
<li><span class="resultDisplayAddress resultElement">41975 LOUDOUN CENTER PL SE, LEESBURG, VA 20175</span></li>
<li><span class="resultPermitNumber resultElement">B123456789</span></li>
<li><span class="resultPermitType resultElement">FINAL</span></li>
<li><span class="resultDisplayAddress resultElement">41975 LOUDOUN CENTER PL SE, LEESBURG, VA 20175</span></li>
<li><span class="resultPermitNumber resultElement">B123456789</span></li>
<li><span class="resultPermitType resultElement">FINAL</span></li>
<li><span class="resultDisplayAddress resultElement">41975 LOUDOUN CENTER PL SE, LEESBURG, VA 20175</span></li>
</ul>
<!-- Lots more of the ul. -->
</div>
Basically there are two things that are important: your outer box cannot be scrollable, you inner box can. All the fixed elements need to be outside your inner box (which is your ul in this case). Secondly, your :before cannot be 100% high, as it will absorb your mouse events, preventing scrolling. For all browsers except IE you can solve this by using pointer-events: none, but otherwise the safest way is to make your gradient a fixed height and your :before element the height of the gradient you want, resulting in a (in this case) 20px area that would not take your mouse events at the bottom.
html, body { height: 100%; } body { padding: 0; margin: 0; }
div {
width: 400px;
height: 400px;
max-height: 100%;
position: relative;
}
div:before, div ul {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
}
div:before {
background: linear-gradient(0deg, rgba(255,255,255,1), rgba(255,255,255,0));
background-size: 100% 100%;
height: 20px;
z-index: 2;
/* IE does not support pointer events, so making this small in height is important
as your scroll events will not be passed to the ul if it is covered by your :before */
pointer-events: none;
content: '';
display: block;
}
div ul {
margin: 0;
padding: 0;
height: 100%;
overflow-y: scroll;
z-index: 1;
}
div li {
width: 100%;
height: 100px;
background: #ececec;
}
div li:nth-child(2n){
background: #cecece;
}
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
</div>
You need to wrap your container in another div that is positioned as relative.
Also, overlay will block your scroll bar, so instead of width: 100% I used: left:0; right: 16px; - now scroll is clickable.
Try my fiddle:
https://fiddle.jshell.net/8c6k4k6d/1/
replace
.resultListContainer::before
with
.resultListContainer .result:last-of-type::before
Related
I am working on a transparent menu for my site.This is my current code
nav{
display: inline-block;
position:overlay;
top:0;
left:0;
width:100%;
height:80px;
padding: 10px 90px;
box-sizing: border-box;
background: rgba(0,0,0,.5);
}
I want the menu to be transparent like this site
https://www.holeman-finch.com.
Thanks in advance
nav{
display: inline-block;
position:overlay;
top:0;
left:0;
width:100%;
height:80px;
padding: 10px 90px;
box-sizing: border-box;
background: rgba(0,0,0,.5);
margin-bottom:-80px
}
nav{
display: inline-block;
position: overlay;
top:0;
left:0;
width:100%;
height:80px;
padding: 10px 90px;
box-sizing: border-box;
background-color: transparent;
}
On your header element, you can use any transparent background color, for example a very light white transparent shade which will work fine as an overlay on a darker photo:
background-color: #ffffff42;
In order for your header to actually float on top of the photo behind it, add position: fixed; or position: sticky; to it, for example. The same effect can also be achieved with position: absolute; and some extra top, right and left properties.
nav {
max-width: 960px;
/* The mask-image gives us some extra fading. It is not necessary but without this, you can't face out the box-shadows. This clips our menu */
mask-image: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, #ffffff 25%, #ffffff 75%, rgba(255, 255, 255, 0) 100%);
margin: 0 auto;
/* Using padding instead of margin for the top and bottom here will keep our box-shadow visible and not affected by the mask-image */
padding: 75px 0;
}
nav ul {
text-align: center;
background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.2) 25%, rgba(255, 255, 255, 0.2) 75%, rgba(255, 255, 255, 0) 100%);
width: 100%;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.1), inset 0 0 1px rgba(255, 255, 255, 0.6);
}
nav ul li {
display: inline-block;
}
nav ul li a {
padding: 20px;
font-family: "Roboto";
color: rgba(0, 0, 0, 0.5);
text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.4);
font-size: 25px;
text-decoration: none;
display: block;
}
I am trying to produce a faded gradient for the left and right margins on my website, but the only way I can think to go about it is found on this fiddle: https://jsfiddle.net/btzr1vox/
body {
background-color: #fafafa;
}
.box-1 {
background-image: linear-gradient(to left, rgb(250, 250, 250) 0%, rgb(0, 0, 0, 1) 15%);
display: inline-block;
width: 50%;
}
.box-2 {
background-image: linear-gradient(to left, rgb(0, 0, 0) 85%, rgb(250, 250, 250, 1) 100%);
float: left;
width: 50%;
}
.row {
max-width: 114rem;
margin: 0 auto;
}
.col-1-of-2 {
width: calc((100% - #{6rem}) / 2);
}
.color {
color: white;
}
.column-1 {
margin-right: 3rem;
}
.column-2 {
margin-left: 3rem;
}
It works, but it divides the the page into to columns, which I don't want, as I would have to repeat the process for each section of the website. This seems like a hassle, especially if I want to change the width of the columns, such as a block that only takes up 1/3 of the page, and the other 2/3, and so on.
I would suggest separating the white gradient from the elements that hold your text, so they're not dependent on each other. Even easier: if you create two elements and apply the position: absolute; property on them, you can re-use them wherever you want: on top of the whole background, or per section.
If you run into problems with text covering the gradient, you can of course give the element that holds your text a padding equal to the width of the gradients, so they never touch them.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body, html {
width: 100%;
height: 100%;
}
body {
position: relative;
background-color: #36393f;
}
.gradient-left {
position: absolute;
top: 0;
left: 0;
width: 60px;
height: 100%;
background-image: linear-gradient(
to right,
rgba(255, 255, 255, 1) 0%,
rgba(255, 255, 255, 0) 100%
);
}
.gradient-right {
position: absolute;
top: 0;
right: 0;
width: 60px;
height: 100%;
background-image: linear-gradient(
to left,
rgba(255, 255, 255, 1) 0%,
rgba(255, 255, 255, 0) 100%
);
}
<div class="gradient-left"></div>
<div class="gradient-right"></div>
I need help with a webpage I'm webmastering. Here's some code:
<body>
<div class="left">
</div>
And here's the css for it:
.left {
position: fixed;
width:50%;
height: 100vh;
top:0;
background-image: url('../img/plakatm.jpg');
background-size: 1164px,1000px;
background-position: center;
background-repeat: no-repeat;
}
The problem is, that i need to make a gradient at the right edge of it. I can't add the gradient to the image, beacause the .left element changes size on smaller monitors and the gradient would not show up.
Here you can see the full site (It's in polish but you don't need to understand it) Click here to see it.
Thanks.
Adam
Use CSS linear-gradient, something like below will work for you, better separate it to a separate into a different class, not call it .left, I call it .gradient in this example:
.left {
position: fixed;
width: 50%;
height: 100vh;
top: 0;
background-image: url('http://weknownyourdreamz.com/images/jungle/jungle-04.jpg');
background-size: 1164px, 1000px;
background-position: center;
background-repeat: no-repeat;
}
.left:after {
position: absolute;
content: '';
top: 0;
height: 100%;
width: 100%;
display: block;
background: white;
background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
background: -o-linear-gradient(right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
background: -moz-linear-gradient(right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
}
<body>
<div class="left">
</div>
</body>
There is a css-property for gradients. That should help.
Here is how you can have background gradient.
.left {
background-image: linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%);
height: 100px;
width: 100px;
}
<div class="left">
</div>
And this is the link where you can find good gradients: https://webgradients.com/
The Nav looks fine in Chrome and Firefox, but Safari breaks into a new line.
Safari:
Chrome:
CODE PEN: http://codepen.io/patrickhofer/pen/vKEbao
The nav has this CSS:
nav {
float: left;
margin-top: 50px;
margin-left: 0px;
}
nav ul li {
display: inline-block;
list-style: none;
height: 100%;
}
nav ul li h1 {
font-size: 40.5px;
font-weight: 600;
height: 100%;
}
/* PADDING FOR NAV */
.navp {
padding-right: 44.3px;
height: 100%;
}
#reflect h1:hover {
text-decoration: underline;
}
#reflect {
position: relative;
-webkit-box-reflect: below -3px -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0.1) 0%, transparent 50%, transparent 100%);
}
#reflect:before {
background: -moz-linear-gradient(center top, #FFFFFF, #FFFFFF 30%, rgba(255, 255, 255, 0.9) 65%, rgba(255, 255, 255, 0.7)) repeat scroll 0 0 padding-box, -moz-element(#reflect) no-repeat scroll 0 -127px content-box rgba(0, 0, 0, 0);
content: "";
height: 140px;
left: 0;
position: absolute;
top: 277px;
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
width: 360px;
}
HTML:
<nav>
<ul>
<li id="reflect" class="navp txtRot"><h1>HOME</h1></li>
<li id="reflect" class="navp txtOrange"><h1>ANGEBOT</h1></li>
<li id="reflect" class="navp txtGelb"><h1>TEAM</h1></li>
<li id="reflect" class="navp txtGruen"><h1>UMWELT</h1></li>
<li id="reflect" class="txtBlau"><h1>KONTAKT</h1></li>
</ul>
</nav>
I'm using this as simple CSS reset:
* {
margin: 0px;
padding: 0px;
}
Any help much appreciated!
It seems like Safari rounds up the font-size to a whole number. If the sizing is important, you could change the font-size down to 40px and do a scale transform on the parent element.
I want to apply this code:
/* Glossy overlay */
html {
min-height: 100%;
background: linear-gradient(#000, #445);
}
figure {
width: 162px;
height: 162px;
margin: 24px auto;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
border-radius: 5px;
}
figure img {
display: block;
border-radius: 5px;
}
figure:after {
position: absolute;
pointer-events: none;
content: '';
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 5px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
background-image: linear-gradient(-45deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, 0) 50%);
-webkit-mask-image: linear-gradient(#000, transparent);
mask: url(http://daneden.me/labs/albums/images/mask.svg#mask);
}
<figure>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</figure>
But I don't want to apply it on a div element, I want to apply it on every single photo (through a img How can I do that?
I want to apply it on every single photo (through a img)
If every image is inside an <a>, all you need to do is change the CSS to target a, a img and a:after. Ensure that the <a> is display: block or display: inline-block;
Example
/* Glossy overlay */
html {
min-height: 100%;
background: linear-gradient(#000, #445);
}
a {
display: inline-block;
width: 162px;
height: 162px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
border-radius: 5px;
}
a img {
display: block;
border-radius: 5px;
}
a:after {
position: absolute;
pointer-events: none;
content: '';
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 5px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
background-image: linear-gradient(-45deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, 0) 50%);
-webkit-mask-image: linear-gradient(#000, transparent);
mask: url(http://daneden.me/labs/albums/images/mask.svg#mask);
}
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>