I want to give hover effect to specific div, but that div is not a child of that div, which I hover
I have code, so, you can understand
$(".pannel-icon").click(function(){
$(".opening-menu").toggleClass('show');
});
body{overflow:hidden}
a{cursor:pointer}
.opening-menu{float:right;position:absolute;right:-100px; top: 50px;transition:0.2s all linear}
.main-menu{float:right}
.show{right:0;transition:0.2s all linear}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div class="main-menu">
<span>coins:$100</span>
<a class="pannel-icon">
<span class="pannel-menu-hover">Menu</span>
</a>
</div>
<div class="opening-menu">
<ul>
<li>menu1</li>
<li>menu1</li>
<li>menu1</li>
<li>menu1</li>
</ul>
</div>
Inside this code, I want to hover .opening-menu when I hover .pannel-icon.
is it your answer?
$(".pannel-icon, .opening-menu").hover(function(){
$(".opening-menu").toggleClass('show');
});
body{overflow:hidden}
a{cursor:pointer}
.opening-menu{float:right;position:absolute;right:-100px; top: 10px;transition:0.2s all linear}
.main-menu{float:right}
.show{right:0;transition:0.2s all linear}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div class="main-menu">
<span>coins:$100</span>
<a class="pannel-icon">
<span class="pannel-menu-hover">Menu</span>
</a>
</div>
<div class="opening-menu">
<ul>
<li>menu1</li>
<li>menu1</li>
<li>menu1</li>
<li>menu1</li>
</ul>
</div>
I think I see what you're saying, check this Fiddle: https://jsfiddle.net/nhnb9a5g/1/. If you hover over Menu, the menu appears but then disappears as soon as you try and click an item?
If so, check this revised fiddle: https://jsfiddle.net/zm93hL3e/3/
Add the following jQuery:
$(".pannel-icon, .opening-menu").hover(function(){
$(".opening-menu").toggleClass('show');
});
You could use a jquery hover function or selector to achieve this. But I prefer to place the opening-menu within the link. That way it's always hovered when you are hovering an item in the menu.
If I've understand correctly your question, do you want to change CSS properties in the class called opening-menu, right?
So, you can add in your CSS:
.opening-menu:hover{float:right;position:absolute;right:-100px; top: 50px;transition:0.2s all linear}
The complete CSS code will be:
body{overflow:hidden}
a{cursor:pointer}
.opening-menu:hover{float:right;position:absolute;right:-100px; top: 50px;transition:0.2s all linear}
.main-menu{float:right}
.show:hover{right:0;transition:0.2s all linear}
Alternatively, you can use a javascript function like this:
$(".pannel-icon").hover(hoverDiv);
function hoverDiv(){
$(".opening-menu").css({
'float':'right';
'position':'absolute';
'right':'-100px';
'top': '50px';
'transition':'0.2s'})
}
Related
I am trying to introduce new class for specific div element using nth-child() pseudo-class but it is not working!
Am I doing something wrong?
Note that menu, container, newClass are already defined in CSS section and I'm not showing them here.
Here is what I am trying:
$(function() {
$("button").click(function {
$("div:nth-child(2)").toggleClass("newClass");
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>Toggle CSS</button>
<div class="container">
<div class="menu">
<lu>
<li>option 1</li>
<li>option2</li>
<li>option 3</li>
</lu>
</div>
</div>
There are lots of mistakes in your code. Which div are you want to add a class newClass? I think your code should be like this
$(function() {
$("button").on('click', function() {
$(".menu").toggleClass("newClass");
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>Toggle CSS</button>
<div class="container">
<div class="menu">
<ul>
<li>option 1</li>
<li>option2</li>
<li>option 3</li>
</ul>
</div>
</div>
My mistake
I should not use
<script>
$("div:nth-child(2)").toggle Class("newClass");
</script>
this to introduce new class for div element, with the class menu , as it is not a second child of div . What given below is though working fine for me:
Correction
<script>
$("div.menu").toggleClass("newClass");
</script>
That is: to specify div element(whose class is going to be toggled) by tagging its class menu , to call jQuery for div with the class menu .
Also by mistake parentheses () were missing.
I want to apply CSS to all pages except sidebars. Let me show you an example
.page #buddypress ul.group li
I want to apply CSS to all <li> tags that are children of ul.group class. Problem here is that this class is also exist in sidebar and I don't want to change styling of sidebar. I just want to apply CSS to the page section and not to the sidebar.
I except some kind of :not(.class) operation to do that.
Here is what I am trying to do
.page :not(.sidebar) #buddypress ul.group li
But this trick doesn't work for me. I really appreciate if someone could solve my problem. I want to apply CSS to all sections except sidebar.
Here is what my HTML looks like:
<body>
<div id="buddypress">
<ul class="groups">
<li> </li>
</div>
<div class="sidebar">
<ul class="groups">
<li> </li>
</div>
Try this code
div:not(.sidebar) ul.group li {
border: 1px solid red;
}
// Here i have used div, but you can use whatever tag you have used for sidebar
<body class="page">
<div class="sidebar">
<ul class="group">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
<div class="page-section">
<ul class="group">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</body>
You can override all css for that element by using its ID (css id overrides css class).
A possibility would be:
#id{all:unset}
However, this has limited browser support and your specified element should have an ID.See also: https://stackoverflow.com/a/36892781/9204431
How can I get my sticky navigation menu to change background color (i.e. blue to white) after sticking to the top of the screen specifically using the GetUIKit framework?
Here's my code:
<nav class="uk-navbar-container" uk-navbar data-uk-sticky>
<div class="uk-navbar-center">
<ul class="uk-navbar-nav">
<li class="uk-parent"><a href="#works" uk-scroll>works</a></li>
<li class="uk-parent"><a href="#about" uk-scroll>about</a></li>
<li class="uk-parent">resume</li>
</ul>
</div>
</nav>
I read something about being active and inactive, but I don't know what I'm supposed to do. I would prefer to only use the GetUIKit framework in this situation, but if there are easy solutions that are compatible with GetUIKit's code, I'd be willing to try! Thank you!!
As written in docs, you need to provide a class for active state with cls-active: uk-navbar-sticky
For valid HTML5 code, I'm using data-uk instead of uk (which works fine as well)
.tall-placeholder {
height: 1000px;
}
.uk-navbar-sticky {
background-color: powderblue!important;
}
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.42/css/uikit.min.css" />
<!-- UIkit JS & jQuery (not required by UIKit anymore) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.42/js/uikit.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.42/js/uikit-icons.min.js"></script>
<nav class="uk-navbar-container" data-uk-navbar data-uk-sticky="cls-active: uk-navbar-sticky">
<div class="uk-navbar-center">
<ul class="uk-navbar-nav">
<li class="uk-parent"><a href="#works" uk-scroll>works</a></li>
<li class="uk-parent"><a href="#about" uk-scroll>about</a></li>
<li class="uk-parent">resume</li>
</ul>
</div>
</nav>
<section class="tall-placeholder"></section>
You are using prefect, You just don't need to revise code, It's already adding a "uk-active " class when you scroll. So place background color on .uk-active class.
I am newbie and I've got a trouble. I have element with four elements and I can't put one on the right side.
My code is here:
<body>
<header>
<div id="topmenu" class="navigation">
<ul class="navul">
<li>FAQ</li>
<li>ABOUT</li>
<li>Next</li>
<li class="rightbutton"><div>Log In/Sign Up</div></li>
</ul>
</div>
</header>
And css is on jfiddle ( I was not able to attach it correctly)
http://jsfiddle.net/EGxWy/2/
Try putting float:right on one li element and display:inline-block on all li elements.
I am using jQuery Mobile to create my mobile application. I have a plus button which appears like this:
The issue is that it is down, touching the list item. How do I make the button positioned midway between the list item and the horizontal line above it? I attempted to use absolute positioning using css, which did not work.
Here is my code:
<span style="float:left;color:black;font-weight:bold;font-size:24px"><label for="newpostbutton">Posts</label></span>
<span style="float:right;"></span>
<br>
<ul data-role="listview" data-inset="true" id="threads">
<li>No conversations :(</li>
</ul>
Any help would be appreciated :D
nshah, you can always give your button a negative margin-top and play around with the numbers. But it looks like there is probably more going on with the default button styles. I would look there first.
margin-top: -15px;
The floated elements needed to be cleared.
div {
overflow:hidden;
}
<div>
<span style="float:left;color:black;font-weight:bold;font-size:24px"><label for="newpostbutton">Posts</label></span> <span style="float:right;"></span>
</div>
<ul data-role="listview" data-inset="true" id="threads">
<li>No conversations :(
</li>
</ul>
http://jsfiddle.net/g9UM4/2/