im trying to make the background of a parent div change when hovering over a li in its child.. i did that but now i want to display a different img when hovering over a different li inside the same child div... i cant seem to do that and cant find anyone else having the same problem.. and if it needs JavaScript also i dont mind
i tried to specify the li but it doesnt work
heres the css code
#mainpage{
pointer-events: none;
}
#listman {
pointer-events: auto;
}
#mainpage:hover {
background: url("bg1.jpg");
background-repeat: no-repeat;
height: 500x;
background-position: top;
background-size: 100%;
}
and heres the html part
div id="mainpage">
<div id="listman">
<ul class="bigger">
<li id="listman1" href="#"> <a> 1 </a> </li>
<li id="listman2" href="#"> <a> 2 </a> </li>
<li id="listman3" href="#"> <a> 3 </a> </li>
<li id="listman4" href="#"> <a> 4 </a> </li>
<li id="listman5" href="#"> <a> 5 </a> </li>
<li id="listman6" href="#"> <a> 6 </a> </li>
<li id="listman7" href="#"> <a> 7 </a> </li>
<li id="listman8" href="#"> <a> 8 </a> </li>
</ul>
</div>
</div>
</div>
i want to make a different img to appear when hovering over (listman2) can anyone help me?
Try using this CSS syntax:
div#listman > ul.bigger > div#listman2 > li {
background-image: url("bg1.png");
}
div#listman > ul.bigger > div#listman2 > li:hover + div#listman > ul.bigger > div#listman2 > li {
background-image: url("bg2.png");
}
I'm not sure it will work though
If the li elements do not have their own position and you can make mainpage be the closest positioned element to them then you can put the image on an absolutely positioned pseudo element on each li when it is hovered.
This snippet uses a CSS variable to set the background image for each li element.
#mainpage {
pointer-events: none;
}
#listman {
pointer-events: auto;
}
ul.bigger {
position: relative;
}
li:hover::after {
content: '';
position: absolute;
background: var(--bg);
background-repeat: no-repeat;
background-position: top;
background-size: 100%;
width: 100%;
height: 500px;
z-index: -1;
top: 0;
left: 0;
}
#listman1 {
--bg: url(https://picsum.photos/id/1015/1024/768);
}
#listman2 {
--bg: url(https://picsum.photos/id/1016/1024/768);
}
#listman3 {
--bg: url(https://picsum.photos/id/1018/1024/768);
}
#listman4 {
--bg: url(https://picsum.photos/id/1019/1024/768);
}
#listman5 {
--bg: url(https://picsum.photos/id/1020/1024/768);
}
#listman6 {
--bg: url(https://picsum.photos/id/1022/1024/768);
}
#listman7 {
--bg: url(https://picsum.photos/id/1023/1024/768);
}
#listman8 {
--bg: url(https://picsum.photos/id/1024/1024/768);
}
<div id="mainpage">
<div id="listman">
<ul class="bigger">
<li id="listman1" href="#"> <a> 1 </a> </li>
<li id="listman2" href="#"> <a> 2 </a> </li>
<li id="listman3" href="#"> <a> 3 </a> </li>
<li id="listman4" href="#"> <a> 4 </a> </li>
<li id="listman5" href="#"> <a> 5 </a> </li>
<li id="listman6" href="#"> <a> 6 </a> </li>
<li id="listman7" href="#"> <a> 7 </a> </li>
<li id="listman8" href="#"> <a> 8 </a> </li>
</ul>
</div>
</div>
Related
I'm trying to set up a menu bar with the
following template
I'm trying this with FlexBox but I can't figure out what's wrong. Here's the HTML :
<nav>
<ul>
<li id="navleft">
<img src="images/logo.png" alt="logo wikihow">
</li>
<li class="navothers">
<img src="images/contribuye.png" alt="contribuye">
<p>CONTRIBUYE</p>
</li>
<li class="navothers">
<img src="images/explora.png" alt="explora">
<p>EXPLORA</p>
</li>
<li class="navothers">
<img src="images/entrar.png" alt="entrar">
<p>ENTRAR</p>
</li>
<li class="navothers"><img src="images/mensajes.png" alt="mensajes">
<p>MENSAJES</p>
</li>
</ul>
</nav>
And I apply the following styles in CSS :
nav {
padding: 0 30% 0 30%;
}
nav ul {
display:flex;
justify-content:center;
align-items:center;
background-color: #93B874;
}
#navleft{
flex-grow:32;
flex-shrink:1;
}
#navleft img{
width: 144px;
vertical-align:center
}
.navothers{
flex-grow:1;
flex-shrink:4;
}
I get the following result
My problem is that all the elements in the right part (with the "navothers" class) dont have the same width ! They just adapt depending on the size of the text they have.
I may have mixed a lot of things, what have I done wrong ?
Your flex-grow value for #navleft is too big, and your container is too small. Your items can't grow they don't have enough room. Try this :
CSS :
nav {
padding: 0 10% 0 10%; // imho it's a strange way to center your nav. Reduced to show you that you're lacking room.
}
nav ul {
display: flex;
justify-content: center;
align-items: center;
background-color: #93B874;
}
#navleft {
flex: 2; // You may tune this one but keep room for your other items !
}
#navleft img {
width: 144px;
vertical-align: center
}
.navothers {
flex: 1;
border: solid 1px #000;
}
HTML :
<nav>
<ul>
<li id="navleft">
<img src="images/logo.png" alt="logo wikihow">
</li>
<li class="navothers">
<img src="images/contribuye.png" alt="contribuye">
<p>CONTRIBUYE</p>
</li>
<li class="navothers">
<img src="images/explora.png" alt="explora">
<p>EXPLORA</p>
</li>
<li class="navothers">
<img src="images/entrar.png" alt="entrar">
<p>ENTRAR</p>
</li>
<li class="navothers">
<img src="images/mensajes.png" alt="mensajes">
<p>MENSAJES</p>
</li>
</ul>
</nav>
https://jsfiddle.net/me7t2hv3/
CodePen is here: http://codepen.io/anon/pen/BKVMoY
ul {
width: 40%;
border: 1px solid black;
list-style: none;
padding: 0;
}
span:last-of-type {
float: right;
}
<ul>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
Why isn't the floated element underlined?
How can I make it clickable for space between the spans?
Why isn't the floated element underlined?
16.3.1 Underlining, overlining, striking, and blinking: the 'text-decoration' property
Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables.
To fix that, you can set text-decoration: inherit on the floated span.
span:last-of-type {
float: right;
text-decoration: inherit;
}
How can I make it clickable for space between the spans?
You can set the <a> to display:block, it will the occupies the entire width available.
a {
display: block;
}
ul {
width: 40%;
border: 1px solid black;
list-style: none;
padding: 0;
}
a {
display: block;
}
span:last-of-type {
float: right;
text-decoration: inherit;
}
<ul>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
I think you can just add display: block; to the anchor tags in order to make the entire row clickable. I'm not exactly sure why the floated element removes the underline.
<ul class="whole-row-link">
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
ul.whole-row-link li {
position: relative;
}
ul.whole-row-link li a {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0
}
I was able to make the space between the link clickable but it stillls looks weird when you dont have underline.
I used the flexbox to acheive the effect of the clickable.
`http://codepen.io/Ebeldev/pen/BKVMwP`
I have been searching for a way to change the background image of my banner when I hover my menu bar.
here you have my html
<div id="container">
<header>
<nav>
<ul>
<li>
home
</li>
<li>
bedrijf
</li>
<li>
diensten
</li>
<li>
foto's
</li>
<li>contacteer ons</li>
</ul>
</nav>
</header>
So what i wanna do is when I hover over one of my buttons the background of header should change to a picture I pick for this page.
I hope this is possible it would be great.
You could do that in jQuery:
$("li > a").hover(function(){
$("header").css("background-image", "img.jpg");
});
This code says if you hover over an element with a-Tag which is in a li-Tag then it changes the background-image of the header to img.jpg.
Now if you want that the background-image changes back if you don't hover then add this code too:
$("li > a").mouseleave(function(){
$("header").css("background-image", "none");
});
You could use pseudo elements (:before) on the LI's when you hover over them.
It's a bit hacky, but does work and without javascript too.
working demo here:
http://jsfiddle.net/ezjjyptk/
Here is a solution I've come up with. Basically, add an empty, absolutely positioned div inside each <li> element, and move it up from behind the header on hover.
JSFiddle
<div id="container">
<header>
<nav>
<ul>
<li>
home
<div style="background:green">
</div>
</li>
<li>
bedrijf
<div style="background:yellow">
</div>
</li>
<li>
diensten
</li>
<li>
foto's
</li>
<li>contacteer ons</li>
</ul>
</nav>
</header>
header {
position: relative;
width: 100%;
background: red;
}
ul li a {
position: relative;
z-index: 3;
}
ul li:hover div {
z-index: 1;
}
ul li div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
I wouldn't say it's impossible without javascript, but I certainly wouldn't call this code pretty
.fixed {
position: absolute;
top: 50px;
left: 0;
opacity: 0;
transition: opacity .5s ease-in-out;
}
li {
display: inline-block;
}
.show1:hover + #header1 {
opacity: 1;
}
.show2:hover + #header2 {
opacity: 1;
}
.show3:hover + #header3 {
opacity: 1;
}
.show4:hover + #header4 {
opacity: 1;
}
<li>
<a class="show1" href="index.html">Show 1</a>
<img class="fixed" id="header1" src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Color_blocks.svg/800px-Color_blocks.svg.png" />
</li>
<li>
<a class="show2" href="bedrijf.html">Show 2</a>
<img class="fixed" id="header2" src="http://static1.squarespace.com/static/534d1b21e4b077040469bae0/t/5362730de4b04c365eb65a37/1398960956409/The+two+colour+shirt" />
</li>
<li>
<a class="show3" href="diensten.html">Show 3</a>
<img class="fixed" id="header3" src="http://i1.wp.com/makeapowerfulpoint.com/wp-content/uploads/2015/03/Drunk-Tank-Pink.png" />
</li>
<li>
<a class="show4" href="pictures.html">Show 4</a>
<img class="fixed" id="header4" src="http://3.bp.blogspot.com/-YFX5nFtmjiA/T7co_rB3keI/AAAAAAAAI0c/EkNV9tX3xt8/s920/color%2Bwheel%2Bstar%2Bblock%2Blogo%2Bv1.jpg" />
</li>
Below is my code:
#sam_ul li {
height: 41px;
border-bottom: 1pt solid #DEDEDE;
background-color: #F8F8F8;
}
#sam_ul li {
list-style-type: none;
}
#u_l_add:before {
content: '\0FBF';
}
<ul id="sam_ul" style="margin:0px;">
<li>
<a href="#">
<span id="u_l_add" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Add</div>
</a>
</li>
<li>
<a href="#">
<span id="u_l_sear" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Search Artifact</div>
</a>
</li>
</ul>
The content pseudo element is displayed differently in both IE and mozilla. By different I mean in IE it is displaying correctly while in mozilla it is adding some extra padding and displaying the content.
check the difference between the first li element and the second li element.
Can anyone help me with this?
Add padding:0 to unordered list
#sam_ul{
padding:0
}
#sam_ul li {
height: 41px;
border-bottom: 1pt solid #DEDEDE;
background-color: #F8F8F8;
list-style-type: none;
}
#u_l_add:before {
content: '\0FBF'; }
#u_l_sear:before {
content: '\0FBF'; }
<body>
<ul id="sam_ul" style="margin:0px;">
<li>
<a href="#">
<span id="u_l_add" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Add</div>
</a>
</li>
<li>
<a href="#">
<span id="u_l_sear" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Search Artifact</div>
</a>
</li>
</ul>
</body>
Try to normalize everything. HTML and body has default margin and padding for every browser that could ruin your design. Almost all block elements has that.
Try:
html,body{
margin: 0;
padding:0;
}
Or download and add normalize.css
I'm creating a menu and using (position:"absolute" & height:"100%") but does not respond to screen resize properly because of 50px space from top and the last item does not fit into view.
and I don't want to make (top:"0").
Here is the HTML:
<section class="sidebar">
<div class="user-name">
<img src="/" alt="user-name" />
<span>User Name</span>
</div>
<nav class="menu-list">
<ul>
<li>
<a href="#">
<i>☺</i>
<span>Coffee Bourse</span>
</a>
</li>
<li class="current">
<a href="#">
<i>☺</i>
<span>Coffee Bourse</span>
</a>
<ul>
<li>
<a href="#">
<span>fghjk</span>
</a>
</li>
<li class="active">
<a href="#">
<span>fghjk</span>
</a>
</li>
<li>
<a href="#">
<span>fghjk</span>
</a>
</li>
</ul>
</li>
<li>
<a href="#">
<i>☺</i>
<span>Coffee Bourse</span>
</a>
</li>
<!-- some other lis here -->
<li>
<a href="#">
<i>☺</i>
<span>End</span>
</a>
</li>
</ul>
</nav>
</section>
The css:
.sidebar {
background: #333;
position: fixed;
width: 200px;
height: 100%;
right: 0;
top: 0;
direction:rtl;
}
.menu-list {
margin-top: 5px;
}
.menu-list ul{
position:absolute;
width:100%;
height:100%;
overflow:hidden;
}
.menu-list ul:hover{
overflow:auto;
}
and here is jsFiddle I created:
http://jsfiddle.net/Meysam/dcPN8/
Thanks to #GCyrillus, I finally fixed it this way
.menu-list ul {
position:absolute;
width:100%;
height:100%;
/* fix */
/* top:0;
padding-top:1.5em; */
box-sizing:border-box;
padding-bottom:55px;
/* end fix */
overflow:hidden;
}
Here is the fixed version :
http://jsfiddle.net/Meysam/dcPN8/9/
you can use box-sizing to include a padding at top of ul and height:100%;
.menu-list ul {
position:absolute;
width:100%;
height:100%;
/* fix */
top:0;
padding-top:1.5em;
box-sizing:border-box;
/* end fix */
overflow:hidden;
}
http://jsfiddle.net/dcPN8/2/
http://jsfiddle.net/dcPN8/5/ (added position:relative for .user-name )