Background image URL cannot find the path on localhost - html

I have an image located in the assets folder within the root directory. Within the assets folder, I have the img folder and in that I have the image in question. My scss folder is also in my root which houses my style.css and my style.scss. I have tried a variety of ways to get the image to appear but have already spent an hour trying to figure this out.
In my html, I have:
<div class="popUpMain">
<div class="box">
<div class="image-area">
<div class="close-button">×</div>
<div class="img"></div>
</div>
</div>
</div>
and my css for these elements are as follows:
.popUpMain {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1099;
background-color: rgba(0, 0, 0, 0.6);
visibility: hidden;
opacity: 0;
transition: all 1s ease;
}
.popUpMain.show {
visibility: visible;
opacity: 1;
}
.popUpMain .box {
// width: 750px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
opacity: 0;
margin-left: 50px;
transition: all 1s ease;
}
.popUpMain.show .box {
opacity: 1;
margin-left: 0;
}
.popUpMain .box .image-area {
position: relative;
}
.close-button {
position: absolute;
top: -20px;
right: -20px;
background-color: transparent;
color: #fff;
border: 3px solid #fff;
padding: 1px 19px 10px 19px;
border-radius: 50%;
background: #000;
font-size: 30px;
cursor: pointer;
}
.popUpMain .box .image-area .img {
position: absolute;
left: 0;
top: 0;
background-image: url(../assets/img/mesa-de-trabajo.png);
width: 100%;
height: 100%;
}
I am sure it is something simple that I am missing but for the life of my, I cannot see the forest through the tree. Any help would be appreciated.
Thank you in advance.
Edit: The reason I have some hidden properties is in my javascript call here:
const popUpControl = document.querySelector('.popUpMain');
const close = document.querySelector('.close-button');
window.addEventListener("load", function() {
showPopup();
});
function showPopup () {
const timeLimit = 2; // seconds
let i = 0;
const timer = setInterval(function() {
i++;
if(i == timeLimit) {
clearInterval(timer);
popUpControl.classList.add("show");
}
console.log(i);
}, 1000);
}
close.addEventListener("click", function() {
popUpControl.classList.remove("show");
});

It depends on both your stylesheet and image location. Your syntax is correct, but you need to remember you're calling the image from the stylesheet location.
Example:
Root
- css
- styles.css
- assets
- img
- yourImage.jpg
In this case, in your stylesheet you would write
background: url(../assets/img/yourImage.jpg);
Take a look at your stylesheet location and adjust!

Issues:
.popUpMain .box .image-area .img - Here you are calling .img class, in HTML, you have written "image" class. So, fix this.
Remove opacity:0 from .popUpMain .box
Remove visibility: hidden; opacity: 0; from .popUpMain
.popUpMain {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1099;
background-color: rgba(0, 0, 0, 0.6);
transition: all 1s ease;
}
.popUpMain.show {
visibility: visible;
opacity: 1;
}
.popUpMain .box {
// width: 750px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
margin-left: 50px;
transition: all 1s ease;
}
.popUpMain.show .box {
opacity: 1;
margin-left: 0;
}
.popUpMain .box .image-area {
position: relative;
}
.close-button {
position: absolute;
top: -20px;
right: -20px;
background-color: transparent;
color: #fff;
border: 3px solid #fff;
padding: 1px 19px 10px 19px;
border-radius: 50%;
background: #000;
font-size: 30px;
cursor: pointer;
}
.popUpMain .box .image-area .image {
position: absolute;
left: 0;
top: 0;
background-image: url("https://picsum.photos/200/300");
width: 500px;
height: 500px;
}
<div class="popUpMain">
<div class="box">
<div class="image-area">
<div class="close-button">×</div>
<div class="image"></div>
</div>
</div>
</div>

Related

Why does the opacity not work when I hover over the square?

When I hover over the square, I want the text "MENU" to go and "Google" and "Youtube" to appear. I gave the opacity value for it. "MENU" text disappears but other texts are not visible. Why is Youtube and Google text not showing?
I gave visibility: visible and visibility: hidden instead of opacity but I still get the same result. Am i selecting the wrong div's?
CSS body {
background-color: aquamarine;
}
.square {
width: 100px;
height: 100px;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform: scale(4);
}
.div1::after {
position: absolute;
content: "MENU";
right: 27px;
top: 40px;
}
.square:hover div:nth-child(1) {
opacity: 0;
}
.div2::after {
content: "- Google";
position: absolute;
bottom: 25px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(2) {
opacity: 1;
}
.div3::after {
content: "- Youtube";
position: absolute;
bottom: 2px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(3) {
opacity: 1;
}
HTML
<div class="square">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
If you have added content using after , then add after in those hover also to work the way you want.
That is use .square:hover div:nth-child(2):after instead of .square:hover div:nth-child(2) only
It works like this see below snippet :
body {
background-color: aquamarine;
}
.square {
width: 100px;
height: 100px;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform: scale(4);
}
.div1::after {
position: absolute;
content: "MENU";
right: 27px;
top: 40px;
}
.square:hover div:nth-child(1) {
opacity: 0;
}
.div2::after {
content: "- Google";
position: absolute;
bottom: 25px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(2):after {
opacity: 1;
}
.div3::after {
content: "- Youtube";
position: absolute;
bottom: 2px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(3):after {
opacity: 1;
}
<div class="square">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
I changed your code a bit. See if this does what you need:
I added transform-origin: top left; to prevent the scaling from happening in all directions which caused some of the element to be displayed outside of the viewport.
I got rid of the :after pseudo-elements as they did not contribute to the desired outcome and only complicated things (in my opinion).
CSS body {
background-color: aquamarine;
}
.options {
height: 100px;
margin-top: 5px;
display: none;
}
.options>div {
border: 2px solid gray;
margin-bottom: 4px;
}
.square {
width: 100px;
height: 100px;
border: 1px solid gray;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform-origin: top left;
transform: scale(4);
}
.menu {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.square:hover .options {
display: block;
font-size: 10px;
padding: 2px;
}
.square:hover .menu {
display: none;
}
<div class="square">
<div class="menu">Menu</div>
<div class="options">
<div class="div2">Google</div>
<div class="div3">You Tube</div>
</div>
</div>

CSS border opacity affected by translucent overlay [duplicate]

This question already has answers here:
How do I reduce the opacity of an element's background using CSS?
(29 answers)
Closed 5 years ago.
I have this project:
https://jsfiddle.net/3xw9aqew/
When a user hovers over the grey box, a red overlay appears with a green border/outline. However this border is applied to the overlay which has an opacity value applied to it on hover.
.image-container:hover .overlay {
opacity: 0.3;
}
I want the overlay to be translucent, allowing the image below to be seen, but I want the border around this to be solid so its a standard "green" colour. This is the CSS for the overlay:
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: red;
border:10px solid green;
box-sizing:border-box;
}
How can i achieve this?
For the intended behaviour, apply the required transparency directly to the background-color property value instead of the containing element as a whole. This can be done by adjusting the rgba value as demonstrated in the embedded code snippet below.
opacity applies to the element as a whole, including its contents,
even though the value is not inherited by child elements. Thus, the
element and its children all have the same opacity relative to the
element's background, even if they have different opacities relative
to one another.
opacity - CSS | MDN
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 1;
transition: .5s ease;
background-color: transparent;
border: 10px solid transparent;
box-sizing: border-box;
}
.image-container:hover .overlay {
background-color: rgba(255, 0, 0, 0.3);
border: 10px solid green;
}
Updated JSFiddle
Code Snippet Demonstration:
var imgContainer = document.getElementById("imgContainer");
var lorem = document.querySelector(".hdr-left");
var ipsum = document.querySelector(".hdr-right");
//When clicking on imgContainer toggle between class to change colour and position
imgContainer.addEventListener('click', function() {
lorem.classList.toggle("hdr-color-white");
ipsum.classList.toggle("hdr-color-white");
lorem.classList.toggle('hdr-left-middle');
ipsum.classList.toggle('hdr-right-middle');
});
body {
max-width: 100%;
overflow-x: hidden;
background: yellow;
font-family: sans-serif;
}
.container {
width: 85%;
max-width: 700px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
img {
width: 100%;
max-width: 920px;
}
p {
font-size: 18px;
color: blue;
font-weight: bold
}
p.left {
position: absolute;
top: 0;
bottom: 0px;
right: -32%;
transform: rotate(-90deg);
}
p.right {
position: absolute;
top: 0;
bottom: 0;
left: -32%;
transform: rotate(90deg);
}
h2 {
font-size: 5em;
position: absolute;
text-transform: uppercase;
letter-spacing: 2px;
font-weight: bold;
margin: 0;
z-index: 5;
color: blue;
transition: all 0.5s ease-in-out;
}
.hdr-color-white {
color: white;
}
.hdr-left {
left: -12%;
top: -35%;
}
.hdr-left-middle {
left: 7%;
top: 40%;
}
.hdr-right {
right: -10%;
top: 110%;
}
.hdr-right-middle {
right: 7%;
top: 40%;
}
/*Hovers*/
.container:hover {
cursor: pointer
}
.container:hover>p {
color: red;
}
.container .image-container:hover {}
/*Hovers Ends*/
/*Overlay*/
.image-container {
position: relative;
width: 100%;
padding: 10px;
box-sizing: border-box;
}
.image {
display: block;
width: 100%;
height: auto;
outline: 5px solid blue;
}
.container .image-container:hover>.image {
outline: none;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 1;
transition: .5s ease;
background-color: transparent;
border: 10px solid transparent;
box-sizing: border-box;
}
.image-container:hover .overlay {
background-color: rgba(255, 0, 0, 0.3);
border: 10px solid green;
}
/*Overlay Ends*/
<div class="container">
<!--Rotated Text-->
<p class="right">Harolds</p>
<p class="left">Harolds</p>
<!--//Rotated Text-->
<h2 class="hdr-left hdr-color" id="lorem">Lorem</h2>
<div class="image-container" id="imgContainer">
<img src="http://via.placeholder.com/980x550" alt="gucci" class="image">
<!--colour overlay-->
<div class="overlay"></div>
<!--//colour overlay-->
</div>
<h2 class="hdr-right hdr-color" id="ipsum">Ipsum</h2>
</div>

CSS3 different background color element coming from top

Right now I'm doing this to animate an element background color.
<style>
.container{
padding: 30px;
}
.element {
position: relative;
font-size: 20px;
line-height: 20px;
background-color: #c00;
display: inline-block;
overflow: hidden;
}
.element div {
position: absolute;
top: -20px;
left: 0;
background-color: #0c0;
transition:top 0.5s ease;
}
.element:hover div {
top: 0px;
transition:top 0.5s ease;
}
</style>
<div class="container">
<div class="element">some text<div>some text</div></div>
</div>
JsFiddle demo.
Is there any "cleaner" way to have the same animation? Right now I'm duplicating my content to achieve this.
You can use pseudo elements for this, and not have to duplicate any content:
It's basically moving one pseudo from above the element, and bringing it down over the element on the hover
div {
position: relative;
display: inline-block;
overflow: hidden;
}
div:before,
div:after {
content: "";
position: absolute;
left: 0;
height: 100%;
width: 100%;
transition: all 0.6s;
z-index: -1;
}
div:before {
top: 0;
background: red;
}
div:after {
top: -100%;
background: green;
}
div:hover:before {
top: 100%;
}
div:hover:after {
top: 0;
}
<div>Text? Why would you ever want text?</div>
If you want the text to 'move' as well, you can do something similar:
div {
position: relative;
display: inline-block;
overflow: hidden;
height:20px;
width:300px;
}
div:before,
div:after {
content: attr(data-text);
position: absolute;
left: 0;
height: 100%;
width: 100%;
transition: all 0.6s;
z-index: -1;
}
div:before {
top: 0;
background: red;
}
div:after {
top: -100%;
background: green;
}
div:hover:before {
top: 100%;
}
div:hover:after {
top: 0;
}
<div data-text="Text? Why would you ever want text?"></div>
Note: canIuse suggests it is widely supported (bit I admit only tested in latest chrome, so only going by this for cross browser). However, This may affect SEO, and so I would be reluctant to use this in production.
If you just wanted the 'upper' element to flow over the top of the text (instead of 'lower' text scrolling as well), You could do:
div {
position: relative;
display: inline-block;
overflow: hidden;
height: 20px;
width: 300px;
background: red;
}
div:before {
content: attr(data-text);
position: absolute;
left: 0;
height: 100%;
width: 100%;
transition: all 0.6s;
top: -100%;
background: green;
}
div:hover:before {
top: 0;
}
<div data-text="The text I always wanted">The text I always wanted</div>
You could do it with background-position
Set a linear-gradient to 50% of each of the background colors and set the background size to be 200% of the actual div.
Then animate it and move the background 100% up. Like this:
.container {
padding: 30px;
}
.element {
position: relative;
font-size: 20px;
line-height: 20px;
background-color: #c00;
display: inline-block;
overflow: hidden;
background-size: 100% 200%;
background-image: linear-gradient(to bottom, #c00 50%, #0c0 50%);
}
.element:hover {
background-position: 0 -100%;
transition: background-position 1s;
}
<div class="container">
<div class="element">some text</div>
</div>
This cuts out the need for any duplicate content in either the css or the html.
Yes, you can use pseudo element :before and get the text with attribute like:
<div class="container">
<div class="element" data-text="some text">some text</div>
</div>
And css:
.container{
padding: 30px;
}
.element {
position: relative;
font-size: 20px;
line-height: 20px;
background-color: #c00;
display: inline-block;
overflow: hidden;
}
.element:before {
content: attr(data-text);
position: absolute;
top: -20px;
left: 0;
background-color: #0c0;
transition:top 0.5s ease;
}
.element:hover:before {
top: 0px;
transition:top 0.5s ease;
}
http://jsfiddle.net/Pik_at/g3Lxrou4/3/
just similar to jbutler483, but using just a single pseudo class. FIDDLE
.container {
padding: 30px;
}
.element {
position: relative;
font-size: 20px;
line-height: 20px;
background-color: #c00;
display: inline-block;
transition: top 0.5s ease;
overflow: hidden;
}
.element:after {
position: absolute;
top: -60px;
content: 'some text';
font-size: 20px;
line-height: 20px;
left: 0;
display: inline-block;
background-color: #0c0;
transition: top 0.5s ease;
}
.element:hover:after {
top: 0px;
}
<div class="element">some text</div>

CSS transition, collapsing width/height to center of div

Below is my effort.
http://liveweave.com/i1qkNw
Below is also my code
.container {
display: inline-block;
position: relative;
border: 1px solid green;
}
.middle {
position: relative;
width: 300px;
height: 250px;
background: black;
}
.door {
position: absolute;
width: 300px;
height: 250px;
background: red;
top: 0;
left: 0;
opacity: 0.5;
transition: .5s;
transform-origin: center center;
}
.container:hover .door {
transition: .5s;
opacity: 0;
width: 0;
height: 0;
}
<div class="container">
<div class="middle"></div>
<div class="door"></div>
</div>
What i want to do is, when user hovers over container, I want the door div's width/height to be zero. As you can see, I am achieving this effect but it disappears to upper left corner. Is there any way I can make it disappear to its center?? Like the width and height are reduced till its center and disappear.
Kindly guide me how to achieve this effect.
You have to set top / bottom / left / right values to 50%.
.container {
display: inline-block;
position: relative;
border: 1px solid green;
}
.middle {
position: relative;
width: 300px;
height: 250px;
background: black;
}
.door {
position: absolute;
width: 300px;
height: 250px;
background: red;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0.5;
transition: .5s;
transform-origin: center center;
}
.container:hover .door {
transition: .5s;
opacity: 0;
top: 50%;
bottom: 50%;
left: 50%;
right: 50%;
width: 0;
height: 0;
}
<div class="container">
<div class="middle"></div>
<div class="door"></div>
</div>

CSS - Placing <divs> over transparent <div>'s

Is there any way I can make the content/images none-transparent when inside a <div> that has a transparency?
Here's the HTML:
<div id="main-button-wrapper" class="left">
<div id="button-bg-layer" class="box-bg-layer corners"></div>
<div class="buttons-bg-overlay box-bg-overlay corners">
<img alt="Test" src="http://www.schroff.co.uk/railway/src/symbol_test.gif" />
</div>
</div>
CSS:
#main-button-wrapper {
height: 319px;
margin-left: 22px;
position: relative;
width: 321px;
}
#button-bg-layer {
position: absolute;
right: 0;
height: 319px;
width: 321px;
}
.buttons-bg-overlay {
position: relative;
right: 0;
margin: 11px;
height: 66px;
width: 299px;
text-align: center;
padding-top: 26px;
}
#buttons-wrapper {
position: relative;
width: 299px;
height: 297px;
z-index: 3;
margin: 22px;
}
/* Background Layers */
.box-bg-layer {
background-color: #010101;
z-index: 1;
zoom: 1;
filter: alpha(opacity=40);
opacity: 0.4;
}
.box-bg-overlay {
background-color: #010101;
z-index: 2;
zoom: 1;
filter: alpha(opacity=40);
opacity: 0.4;
}
I've tried putting a z-index: 4; on the image. The only other way I can think of is setting the div backgrounds as absolute positioning, then positioning the content outside of the div but there must be an easier way?
Any help would be much appreciated!
See JSFiddle:
http://jsfiddle.net/Sa8jw/
Instead of using opacity use rgba where a stands for alpha. This will make the child elements non transparent...
background-color: rgba(0,0,0,.5); /* RGBA for #010101 will be rgba(1,1,1,.4) */
Where .4 for a is equivalent to opacity: 0.4
Demo
Here's a js fiddle for your help :-)
FIDDLE
and the changed code . where the opacity is being added to pseudo class after
#main-button-wrapper {
height: 319px;
margin-left: 22px;
position: relative;
width: 321px;
}
#button-bg-layer {
position: absolute;
right: 0;
height: 319px;
width: 321px;
}
.buttons-bg-overlay {
position: relative;
right: 0;
margin: 11px;
height: 66px;
width: 299px;
text-align: center;
padding-top: 26px;
}
#buttons-wrapper {
position: relative;
width: 299px;
height: 297px;
z-index: 3;
margin: 22px;
}
/* Background Layers */
.box-bg-layer{
background-color: #010101;
z-index: 1;
zoom: 1;}
.box-bg-layer : after{
filter: alpha(opacity=40);
opacity: 0.4;
}
.box-bg-overlay { background-color: red;
z-index: 2;
zoom: 1;
}
.box-bg-overlay :after{
filter: alpha(opacity=40);
opacity: 0.4;
}