Z index - Hover menu - html

Im using a platform that only accepts html / css in line, and i was asked to make somehow a dropdown menu, where when i hover on one element, it resize it and there is an image show on it. The problem is that when i hover on one element, i cant hover and resize the second one, unless i take the mouse over this.
I tried to move backwards the hover elements with z index -1, but the transition got really bugged and goes up and down constantly.
<div id="mapa-expanduno"></div>
<div id="mapa-expanddos"></div>
<div id="mapa-expandtres"></div>
<div id="mapa-expandcuatro"></div>
<style type="text/css">
div {
position: absolute;
}
#mapa-expanduno {
border: 1px solid blue;
margin-left: 55px;
width: 110px;
height: 125px;
}
#mapa-expanduno:hover {
width:914px;
height: 450px;
margin-left: 0px;
background: url();
background-repeat: no-repeat;
}
#mapa-expanddos {
border: 1px solid red;
margin-left: 286px;
width: 110px;
height: 125px;
}
#mapa-expanddos:hover {
width:914px;
height: 450px;
z-index: -1;
margin-left: 0px;
background: url();
background-repeat: no-repeat;
}
#mapa-expandtres {
border: 1px solid lightgreen;
margin-left: 518px;
width: 110px;
height: 125px;
}
#mapa-expandtres:hover {
width:914px;
height: 450px;
z-index: -1;
margin-left: 0px;
background: url();
background-repeat: no-repeat;
}
#mapa-expandcuatro {
border: 1px solid black;
margin-left: 750px;
width: 110px;
height: 125px;
}
#mapa-expandcuatro:hover {
width:914px;
height: 450px;
margin-left: 0px;
background: url();
background-repeat: no-repeat;
}
</style>
Demo
Thanks on advice.

I'd switch to a sibling relationship:
div {
position: absolute;
}
.outer {
cursor: pointer;
width: 110px;
height: 125px;
}
.inner {
position: fixed;
top: 0;
left: 0;
width: 914px;
height: 450px;
z-index: -1;
display: none;
}
#mapa-expanduno {
border: 1px solid blue;
margin-left: 10%;
}
#mapa-expanduno:hover + .inner {
display: block;
background: url(http://lorempixel.com/1200/900/nature/4);
background-repeat: no-repeat;
}
#mapa-expanddos {
border: 1px solid red;
margin-left: 30%;
}
#mapa-expanddos:hover + .inner {
display: block;
background: url(http://lorempixel.com/1200/900/nature/3);
background-repeat: no-repeat;
}
#mapa-expandtres {
border: 1px solid lightgreen;
margin-left: 50%;
}
#mapa-expandtres:hover + .inner {
display: block;
background: url(http://lorempixel.com/1200/900/nature/2);
background-repeat: no-repeat;
}
#mapa-expandcuatro {
border: 1px solid black;
margin-left: 70%;
}
#mapa-expandcuatro:hover + .inner {
display: block;
background: url(http://lorempixel.com/1200/900/nature/1);
background-repeat: no-repeat;
}
<div class="outer" id="mapa-expanduno"></div>
<div class="inner"></div>
<div class="outer" id="mapa-expanddos"></div>
<div class="inner"></div>
<div class="outer" id="mapa-expandtres"></div>
<div class="inner"></div>
<div class="outer" id="mapa-expandcuatro"></div>
<div class="inner"></div>
<div id="preloader" style="position: absolute; left: -999em;">
<img src="http://lorempixel.com/1200/900/nature/3" />
<img src="http://lorempixel.com/1200/900/nature/4" />
<img src="http://lorempixel.com/1200/900/nature/1" />
<img src="http://lorempixel.com/1200/900/nature/2" />
</div>
JSFiddle demo
Here's a version with some transitions.

I don't know if this is helpful because the question is unclear, but I'll attempt to help.
It is hard to know exactly what's going on here without your HTML.
You can add a "> [desired element to change]" selector after your ":hover" selector.
so it would be something like
parent_element{
margin-left: 750px;
width: 110px;
height: 125px;
background: url();
background-repeat: no-repeat;
}
parent_element:hover > child_element{
width:914px;
height: 450px;
margin-left: 0px;
background: url();
background-repeat: no-repeat;
}
If it is not a child element you will have to use JavaScript to make the changes.
You might also consider using transitions in your css, which would make the box grow.

Related

How do you use background: auto; correctly?

I'm trying to make the background fill the whole page. The only way I figured out how to do it is by setting the height and width of <div id="All"> and putting that div around everything else. I know that if I change the size of the browser, though, it won't auto resize, so it would look weird if I made my browser smaller or bigger.
If I set height and width to auto on #All, it def doesn't fill out the whole webpage. Please advise what I am doing wrong. Plus if I do auto, the sticky #Move doesn't stay at the top of the page.
This code is just stuff I have learned, so not an actual project, but I want to learn how to do it for future projects.
#Move {
position: sticky;
top: 0;
color: red;
}
h1 {
color: red;
}
.Hello {
font-size: 36px;
}
.Hello2 {
font-size: 15px;
}
p {
color: white;
}
.DivClass {
width: 160px;
height: 220px;
padding: 40px;
border: 10px solid black;
border-radius: 60px;
margin: 50px;
background: url("https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSqOq9_iT948LTPmS5FuCMlaqlvn2KJQ-0d7Xw5kLMfWz69wwRA&usqp=CAU");
background-repeat: no-repeat;
background-size: cover;
opacity: 80%;
}
.image-whitecat {
width: 500px;
heigth: 500px;
background-color: red;
margin: 50px 50px 90px 250px;
transform: rotate(10deg);
}
.image-cat {
width: 700px;
height: 500px;
border-radius: 300px;
margin-left: 350px;
filter: opacity(70%)
}
.Purple {
color: purple;
}
.PurpleText {
background: teal;
text-align: center;
padding-top: 50px;
width: 150px;
height: 100px;
border: 5px solid red;
border-radius: 100px;
margin: 10px 0 0 1000px;
}
#All {
background-color: lavender;
position: absolute;
top: 10px;
bottom: 10px;
height: 1850px;
width: 1810px;
}
<div id="All">
<div class="DivClass">
<h1>HELLO!!!</h1>
<p class="Hello">Hello</p>
<p class="Hello2">Hello 2</p>
<p>Yes</p>
</div>
<p id="Move">I will stay at the top of the page!</p>
<div>
<img src="https://cdn.pixabay.com/photo/2014/11/30/14/11/kitty-551554__340.jpg" class="image-whitecat" />
</div>
<div>
<img src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634__340.png" class="image-cat" />
</div>
<div class="PurpleText">
<p class="Purple">Purple</p>
</div>
</div>
I think you will need to give both your html and body tags a css height ...
html, body {
height: 100%;
margin: 0;
}
So,
https://jsfiddle.net/z51crou7/

How can I get the position of a child element not fixed even though the parent is fixed?

As the title says: I need the 'info-box' to not be fixed while the head-box and head-in-block are fixed.
I know it is possible. I have a live example: http://www.marktplaats.nl/.
The orange box is fixed (head-box) then the white part (my info-box) is not fixed. And the Title block is fixed again (head-in-block).
This is the css and html I'm using right now. What adjustment needs to be made to make the middle (white) box not fixed?
#head-block{
width: 100%;
height: auto;
background: rgb(245,245,245);
border: 1px solid grey;
z-index: 1000;
margin-top: 0px;
}
#head-box{
height: 5px;
background: #37326a;
}
#info-box{
height: 50px;
background: white;
position: static;
}
#head-in-block{
width: 1100px;
height: 60px;
color: #37326a;
text-align: left;
margin: auto;
padding: 10px;
}
.fixed{
position: fixed;
}
<div id='head-block' class='fixed'>
<div id='head-box'></div>
<div id='info-box'></div>
<div id='head-in-block'>
</div>
</div>
<div style='height: 1500px;' id='content'>
</div>
Test
Do you guys see the website the same I do?
The website you linked to hides the white box when the header is sticky. So to do that here, you would hide #info-box when #head-block has class .fixed
.fixed #info-box {
display: none;
}
#head-block{
width: 100%;
height: auto;
background: rgb(245,245,245);
border: 1px solid grey;
z-index: 1000;
margin-top: 0px;
}
#head-box{
height: 5px;
background: #37326a;
}
#info-box{
height: 50px;
background: white;
position: static;
}
#head-in-block{
width: 1100px;
height: 60px;
color: #37326a;
text-align: left;
margin: auto;
padding: 10px;
}
.fixed{
position: fixed;
}
.fixed #info-box {
display: none;
}
<div id='head-block' class='fixed'>
<div id='head-box'></div>
<div id='info-box'></div>
<div id='head-in-block'>
</div>
</div>
<div style='height: 1500px;' id='content'>
</div>
Test

How to keep a div constantly above a single point on the background?

I have a div which has a background of a map. The map is centred and has a background size of 'contain'. The page is responsive so when the window resizes, so does the map. I need to be able to have a div on top of a certain country on the map, and on resize of the background map, the div stays directly on top of it.
So far I have
<div id="map-holder">
<div class="content">
<div class="placeholder"></div>
</div>
</div>
The div with the class of placeholder is the div i wish to keep on top of a certain country. The div with map-holder for ID is the div with the map background. Content is just to keep it all in place.
CSS
.content {
text-align: center;
width: 1200px;
margin: 0 auto;}
#map-holder {
position: relative;
height: 1000px;
width: 100%;
background: #F0F0F0;
background-image: url(../images/image-mapster.min.png);
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
padding: 30px;
}
.placeholder {
position: absolute;
right: 30px;
background: #fff;
width: 80px;
height: 50px;
border: 1px solid #000;
margin: 5px;
padding: 5px;
padding: 0;
cursor: pointer;
}
.placeholder img {
width: 100%;
height: 100%;
padding: 0;
}
.placeholder:before {
position: absolute;
top: 30%;
left: 45%;
font-weight: bold;
content: '+';
}
The only solution I can think if actually putting an image over the map.
You can do this by having multiple CSS backgrounds. Just change your code for #map-holder to this:
#map-holder {
position: relative;
height: 500px;
width: 500px;
background: #F0F0F0;
background-image: url(this_image_goes_on_top.png), url(your_map.jpg);
background-size: contain, contain;
background-position: center center, center center;
background-repeat: no-repeat, no-repeat;
padding: 30px;
}
I made a little JSFiddle out of your code for demonstration: https://jsfiddle.net/zamofL9g/1/
Basically, it's a little difficult, as I recall, when using background images.
Since the image is, technically speaking "content" you can use an inline image and suitable wrapping divs. The 'pins' can then be positioned using % based positioning values.
Here's a Codepen demo I made some time ago. This one has a tooltip too!
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.map {
width: 90%;
margin: 10px auto;
position: relative;
}
.map img {
max-width: 100%;
}
.box {
width: 2%;
height: 5%;
background-image: url(http://www.clipartbest.com/cliparts/ncX/qyL/ncXqyLdcB.png);
background-position: top center;
background-repeat: no-repeat;
background-size: contain;
position: absolute;
}
#pin-1 {
top: 25%;
left: 38%;
}
.box:hover > .pin-text {
display: block;
}
.pin-text {
position: absolute;
top: -25%;
left: 110%;
width: 300%;
display: none;
}
.pin-text h3 {
color: white;
text-shadow: 1px 1px 1px #000;
}
<div class="map">
<img src="http://connect.homes.com/wp-content/uploads/2012/05/200392710-0012.jpg" alt="" />
<div id="pin-1" class="box">
<div class="pin-text">
<h3>My House</h3>
</div>
</div>
</div>

div tag does not appear on the webpage

I seem to be having a slight problem here. My divs dont show up in the web page. I tried changing the position of the div to absolute but it still dosen't show up.
Here is my code:
body {
background: url("http://fux-media.com/yz/skyline_exp1.jpg");
background-size: cover;
background-repeat: no-repeat;
}
.header {
background-color: #DADAC8;
width: 900px;
height: 10%;
position: relative;
border-radius: 7px;
margin-top: -100px;
margin-left: 170px;
z-index: 500;
}
img {
border-radius: 70%;
border: 1px solid;
margin-left: 40%;
height: 175px;
width: 175px;
position: relative;
z-index: 1;
}
<img src="http://farm5.static.flickr.com/4118/4890853985_b34231ccfb_o.jpg" />
<div class="header"></div>
in your css add this
html, body { height: 100%; width: 100%; margin: 0; }
I've converted your example code into a code snippet and it seems to work fine. What exactly seems to be wrong? Are you missing the .header <div>? In that case give it some content or give it a fixed width. How should the .header look?
body {
background: url("http://fux-media.com/yz/skyline_exp1.jpg");
background-size: cover;
background-repeat: no-repeat;
}
.header {
background-color: #DADAC8;
width: 900px;
height: 10%;
position: relative;
border-radius: 7px;
margin-top: -100px;
margin-left: 170px;
z-index: 500;
}
img {
border-radius: 70%;
border: 1px solid;
margin-left: 40%;
height: 175px;
width: 175px;
position: relative;
z-index: 1;
}
<img src="http://farm5.static.flickr.com/4118/4890853985_b34231ccfb_o.jpg" />
<div class="header"></div>
Your div is present there. But it doesn't have any contents that's why it is not visible.
Add some content in it like text etc. or add some padding to the 'header' class. Then you will be able to see it.

have 3 divs to each other with spacers in between

I have 3 divs that I want next to each other on my page. If the container is 700px in width, they all connect well. But I want to have a max width of 800px on my container. And in that case, I want all my divs to space out (1st div to the left, 2nd div in the center and 3rd div on the right). I need to connect those divs with 2 spacers that I've got (1 to connect div 1 and 2. The other to connect 2 and 3).
Once I have achieved that, I want a second div (content) to float above the first div (background). But I have already achieved that.
I have tried a few things, but I can't find a solution, if anyone could help me, I would appreciate it!
Here are my code snippet:
* {
margin: 0;
padding: 0;
}
.container {
width: 800px;
margin: 0 auto;
background: #efefef;
height: 800px;
}
.content {
position: relative;
z-index: 100;
top: 0;
}
.background {
position: absolute;
z-index: 0;
top: 0;
width: inherit;
}
.bg-left {
height: 190px;
width: 268px;
background: url(images/left-1.png);
float: left;
}
.bg-left-spacer {
height: 190px;
width: 1px;
background: url(images/left-spacer.png);
float: left;
}
.bg-connector {
height: 190px;
width: 133px;
background: url(images/connector.png);
float: left;
margin: 0 auto;
}
.bg-right-spacer {
height: 190px;
min-width: 1px;
background: url(images/right-spacer.png);
float: left;
background-repeat: repeat-x;
}
.bg-right {
height: 190px;
width: 297px;
background: url(images/right-1.png);
float: left;
}
<div class='container'>
<div class='content'>
<h1>testheader</h1>
<p>testtext</p>
</div>
<div class='background'>
<div class='bg-left'></div>
<div class='bg-left-spacer'></div>
<div class='bg-connector'></div>
<div class='bg-right-spacer'></div>
<div class='bg-right'></div>
</div>
</div>
You could achieve it like this:
JSFiddle - DEMO
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
position: relative;
min-width: 700px;
max-width: 800px;
margin: 0 auto;
background: #efefef;
height: 800px;
}
.content {
position: relative;
z-index: 100;
top: 0;
}
.background {
position: absolute;
width: 100%;
z-index: 0;
top: 0;
display: table;
table-layout: fixed;
}
.bg-left {
height: 190px;
width: 268px;
background: url(images/left-1.png);
border: 1px solid #000;
display: table-cell;
}
.bg-connector {
height: 190px;
width: 133px;
background: url(images/connector.png);
border: 1px solid #000;
display: table-cell;
}
.bg-right {
height: 190px;
width: 297px;
background: url(images/right-1.png);
border: 1px solid #000;
display: table-cell;
}
.space {
display: table-cell;
width: 100%;
height: 190px;
background: #F00;
}
<div class='container'>
<div class='content'>
<h1>testheader</h1>
<p>testtext</p>
</div>
<div class='background'>
<div class='bg-left'></div>
<div class="space"></div>
<div class='bg-connector'></div>
<div class="space"></div>
<div class='bg-right'></div>
</div>
</div>
You should use percantages to achieve that:
.bg-left {
height: 190px;
width: calc( 100% / 3 - 1px );
background: url(images/left-1.png);
}
This way .bg-left is 33.3% in width -1px for the spacer.
DEMO: http://jsfiddle.net/6aor5u4m/