I have a simple page in which I want particle js animation at the background and have a button and few anchors for user to click. However, when I add particle js to a particular div, which is parent, I am not able to click the button or the anchors. I did try changing the z-index of them to higher number(z-index:2000), that didn't help either.
This is the code:
https://plnkr.co/edit/JMYVXu6I3G7kdKUWN7tc?p=preview
/* Styles go here */
body{
color:white;
}
#home {
color:white;
padding-bottom: 2em;
min-height: 100vh;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
background-image: url("http://www.melbourne.vic.gov.au/SiteCollectionImages/1200-buildings-898x381.jpg");
/* fallback */
background-image: linear-gradient(to bottom, rgba(0, 67, 105, 0.5) 0%, rgba(0, 67, 105, 0.5) 100%), url("http://www.melbourne.vic.gov.au/SiteCollectionImages/1200-buildings-898x381.jpg"g);
}
.home-icon {
width: 2em;
height: 2em;
text-align: center;
margin: 0.5em;
font-size: 2em;
color: #f5f5f5;
border: 2px solid #f5f5f5;
border-radius: 50%;
padding: 0.5em;
transition: all .5s ease;
z-index:1040
}
.home-icon:hover {
border: 2px solid #00B9DA;
color: #00B9DA;
}
.particles-js-canvas-el {
top: -200px;
position: relative;
height: 200px;
}
This should resolve your issue:
HTML:
<!-- particles.js container -->
<div id="particles-js">
<div class="test">AAA</div>
</div>
CSS:
canvas {
index: 0;
display: block;
vertical-align: bottom;
}
.test {
index: 50;
top: 100px;
position: absolute;
}
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background-color: #b61924;
background-image: url("");
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}}
Related
I want to repeat my image Horizontally. However, it's not repeating
My index.html page
body {
margin: 0;
background-image: linear-gradient(to top, #1e3c72 0%, #1e3c72 1%, #2a5298 100%);
overflow: hidden;
/** Scroll bar right side in your screen **/
}
.night {
height: 80vh;
width: 70vw;
border: 1px solid black;
margin: 5rem auto;
background: url(http://placekitten.com/5/5);
background-size: cover;
position: relative;
box-shadow: 1px 2px 60px rgba(0, 0, 0, 0.4);
overflow-x: hidden;
}
.surface {
height: 140px;
width: 200px; /* 500px; */
background: url(http://placekitten.com/10/10);
display: block;
position: absolute;
bottom: 0%;
left: 0%;
background-repeat: repeat-x;
/*animation: moveRight 6s linear infinite;*/
}
.car {
position: absolute;
bottom: 8%;
}
<div class="night">
<div class="surface"></div>
<div class="car">
<img src="http://placekitten.com/100/75" alt="Car">
</div>
</div>
This is how it currently looks
What is the fault? I checked articles on w3schools but as I see there are no syntax errors.
How the correct image looks like
You had width: 200px; on that element (in your snippet). If you change that to width: 100%;, the background repeats until the right border of its parent:
body {
margin: 0;
background-image: linear-gradient(to top, #1e3c72 0%, #1e3c72 1%, #2a5298 100%);
overflow: hidden;
/** Scroll bar right side in your screen **/
}
.night {
height: 80vh;
width: 70vw;
border: 1px solid black;
margin: 5rem auto;
background: url(http://placekitten.com/5/5);
background-size: cover;
position: relative;
box-shadow: 1px 2px 60px rgba(0, 0, 0, 0.4);
overflow-x: hidden;
}
.surface {
height: 140px;
width: 100%;
background: url(http://placekitten.com/10/10);
display: block;
position: absolute;
bottom: 0%;
left: 0%;
background-repeat: repeat-x;
/*animation: moveRight 6s linear infinite;*/
}
.car {
position: absolute;
bottom: 8%;
}
<div class="night">
<div class="surface"></div>
<div class="car">
<img src="http://placekitten.com/100/75" alt="Car">
</div>
</div>
I have a div with a background image that I am trying to give a transparent type border to.
Currently, this works for the side borders but the top and bottom borders do not fill with the image. How would I achieve this?
.picture-div {
background: url(https://www.princeton.edu/sites/default/files/styles/half_2x/public/images/2022/02/KOA_Nassau_2697x1517.jpg);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
border: 25px solid rgba(100, 100, 100, .50);
width: 200px;
height: 200px;
border-radius: 60px;
}
<div class="picture-div" />
Add background-origin to border-box, so the image will fill the border.
You can read the detail in : https://www.w3schools.com/cssref/css3_pr_background-origin.asp
.picture-div {
background: url(https://www.princeton.edu/sites/default/files/styles/half_2x/public/images/2022/02/KOA_Nassau_2697x1517.jpg);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-origin: border-box;
border: 25px solid rgba(100, 100, 100, .50);
width: 200px;
height: 200px;
border-radius: 60px;
}
<div class="picture-div" />
You can use border on the pseudo :before of the picture-div class as follows:
.picture-div {
background: url(https://www.princeton.edu/sites/default/files/styles/half_2x/public/images/2022/02/KOA_Nassau_2697x1517.jpg);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
position: relative;
width: 200px;
height: 200px;
border-radius: 60px;
}
.picture-div:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border: 25px solid rgba(100, 100, 100, .50);
border-radius: 60px;
}
<div class="picture-div" />
Am sure that I am doing something stupid, but cannot figure out how to get the contents of a DIV to fully render in front of another DIV that has a masked background.
See sample here: https://jsfiddle.net/pLwbsqjv/
What I am trying to do is to get the circle to fully display in front of the green circle that is a masked background.
The only constraint is that the circle with the number in it cannot be positioned absolutely as needs to have its width / height set on a % basis, eg: percentage of the outer container.
Anyone tell me what I am doing wrong?!
Thanks
body {
background: #252526;
}
.ontop {
margin: -50% 0 0 0;
border-radius: 50%;
width: 22%;
height: 22%;
padding: 10px;
background: rgb(34, 51, 68, .5);
border: 2px solid #def;
color: #def;
text-align: center;
font: 30px Arial, sans-serif;
}
.bounds {
width: 200px;
height: 200px;
}
.color-circle {
-webkit-mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
background-color: #26bf75;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
}
.bottom {
height: 80%;
width: 100%;
}
<div id="bounds" class="bounds">
<div class="bottom">
<div class="color-circle"></div>
</div>
<div class="ontop">01</div>
</div>
You can add position: relative and z-index to .ontop:
body {
margin: 0;
background: #252526;
}
.ontop {
position: relative;
z-index: 1;
margin: -50% 0 0 0;
border-radius: 50%;
width: 22%;
height: 22%;
padding: 10px;
background: rgb(34, 51, 68, .5);
border: 2px solid #def;
color: #def;
text-align: center;
font: 30px Arial, sans-serif;
}
.bounds {
width: 200px;
height: 200px;
}
.color-circle {
-webkit-mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
background-color: #26bf75;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
}
.bottom {
height: 80%;
width: 100%;
}
<div id="bounds" class="bounds">
<div class="bottom">
<div class="color-circle"></div>
</div>
<div class="ontop">01</div>
</div>
Note:
Regarding this comment:
The only constraint is that the circle with the number in it cannot be
positioned absolutely as needs to have its width / height set on a %
basis, eg: percentage of the outer container.
Position absolute would have worked as well. You need to designate the container for the absolutely positioned element. To do so, the container must have any position that is not static. In this example I've added position relative to .bounds:
body {
margin: 0;
background: #252526;
}
.ontop {
position: absolute;
z-index: 1;
margin: -50% 0 0 0;
border-radius: 50%;
width: 22%;
height: 22%;
padding: 10px;
background: rgb(34, 51, 68, .5);
border: 2px solid #def;
color: #def;
text-align: center;
font: 30px Arial, sans-serif;
}
.bounds {
position: relative; /** this sets the container **/
width: 200px;
height: 200px;
}
.color-circle {
-webkit-mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
mask: url('https://perlmaven.com/img/circle.svg') no-repeat center;
background-color: #26bf75;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
}
.bottom {
height: 80%;
width: 100%;
}
<div id="bounds" class="bounds">
<div class="bottom">
<div class="color-circle"></div>
</div>
<div class="ontop">01</div>
</div>
I have a div with a background image, what I would like to do, is when I hover over it, the hidden part of background-image to display like in the example below:
My jsfiddle example:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: cover;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
transform: scale(1.2);
}
body {
text-align: center;
}
<div class="test">
</div>
As you can see, in my example the image is just getting larger, instead I want to display another 20px of the image (without compromising border-radius).
Example with one html element:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) no-repeat 50% 50%;
background-size: 140px;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
transform-origin: center center;
}
.test:hover{
width: 90px;
height: 90px;
margin-left: -10px;
margin-top: -10px;
}
body {
text-align: center;
}
<div class="test">
</div>
Example with clip-path and shape-inside:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) no-repeat 50% 50%;
background-size: cover;
shape-inside: circle(30% at 50% 50%);
clip-path: circle(30% at 50% 50%);
-webkit-clip-path: circle(30% at 50% 50%);
width: 70px;
height: 70px;
background-position: center;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
transform-origin: center center;
}
.test:hover{
shape-inside: circle(50% at 50% 50%);
clip-path: circle(50% at 50% 50%);
-webkit-clip-path: circle(50% at 50% 50%);
}
body {
text-align: center;
}
<div class="test">
</div>
you might oversize a bit the background image
(background-size:auto 90px;) and add some padding and reset position on hover (.test:hover{padding:10px; margin:-10px;})
those rules are suppose to be understood by most of actual browsers if not all.
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size:auto 90px;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
padding:10px;
margin:-10px;;
}
body {
text-align: center;
}
<div class="test">
</div>
another possibility is to use an inset shadow
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: auto 90px;
width: 90px;
height: 90px;
/* hide buggy ff render */
background-clip: content-box;
padding: 1px;
/* end fix ff */
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 90px;
box-shadow: inset 0 0 0 10px white;
}
.test:hover {
box-shadow: inset 0 0 0 0px white;
}
body {
text-align: center;
}
<div class="test">
</div>
There is also : padding, box-sizing and background-clip
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) ;
background-size: auto 90px;
width: 90px;
height: 90px;
padding: 10px;
background-clip:content-box;
box-sizing:border-box;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 90px;
}
.test:hover {
padding:0px;
}
/* show transparency */
html {
min-height:100%;
text-align: center;
background:linear-gradient(45deg, gray, yellow,purple,lime,pink,turquoise, gray, yellow,purple,lime,pink,turquoise);
}
<div class="test"></div>
You are missing to remove border-radius property on the hover event:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: cover;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
transform: scale(1.2);
border-radius: 0px;
}
body {
text-align: center;
}
<div class="test">
</div>
I have the following HTML + CSS:
.item {
position: relative;
width: 400px;
height: 400px;
background: url('http://i.imgur.com/FOmRt87.jpg') no-repeat;
}
.item .gradient {
width: 100%;
height: 100%;
position: absolute;
bottom: 0;
left: 0;
background: url('http://i.imgur.com/oSpOTeK.png') repeat-x center bottom;
}
<div class="item">
<div class="gradient">
</div>
</div>
It's rendered in the browser properly. But on mobile (see the attached screenshot) there's a one thick line across the gradient, I have no idea why is that.
Here's also I js fiddle: https://jsfiddle.net/tcxka242/1/
First I thought that is repeated vertically as well, but the inspector says that the rule I've set: background: url(...) repeat-x center bottom; is expanded to :
background-image: url("http://i.imgur.com/oSpOTeK.png");
background-position-x: 50%;
background-position-y: 100%;
background-size: initial;
background-repeat-x: repeat;
background-repeat-y: no-repeat;
background-attachment: initial;
background-origin: initial;
background-clip: initial;
background-color: initial;
That's on Android Phone with Google Chrome.
Sorry but i cannot properly verify this , but i have an idea for you .
.item .gradient {
width:100%;
height: 100%;
position: absolute;
bottom: 0;
left: 0;
outline: 0;
border: none;
background: url('http://i.imgur.com/oSpOTeK.png') repeat-x center bottom;
}
As you can see i have set the outline to 0 and the border to none . There's a possibility that there is an outline from the div or a hidden border .
Specifying border-top: 0px; and box-shadow: none; will work for you
.item .gradient {
width: 100%;
height: 100%;
position: absolute;
bottom: 0;
box-shadow: none;
left: 0;
background: url('http://i.imgur.com/oSpOTeK.png') repeat-x center bottom;
border-top: 0px;
}
I think this is caused on screens with high DPI. Therefore I am providing a CSS-only alternative.
https://jsfiddle.net/tcxka242/6/
.item {
position: relative;
width: 400px;
height: 400px;
background: url('http://i.imgur.com/FOmRt87.jpg') no-repeat;
}
.item:after {
content: "";
width: 100%;
height: 100%;
position: absolute;
bottom: 0;
left: 0;
z-index: 1;
pointer-events: none;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.6) 100%);
}