I'm working on making a sidebar on My main page something like google ventures (https://www.gv.com/lib/how-to-choose-the-right-ux-metrics-for-your-product). but the problem I'm getting is when I click to any menu item in the sidebar , the side bar gets collapse but the text for menu item is still there. I want to keep the sidebar open till the mouse cursor is in the sidebar area (even when user clicks on any menu it should remain opened/expended) but it gets collapse on cliking on any item while the text for the menu item remain in the air. I don't know how to fix it as Im not much hands-on with css and designing.
here is my jquery code for adding classes for collapse/expand the side bar
$('[data-toggle="offcanvas"]').mouseenter(function(e) {
e.preventDefault();
if ($("body").hasClass('sidebar-collapse')) {
$("body").removeClass('sidebar-collapse');
$("body").addClass('sidebar-open')
}
});
$('[data-toggle="offcanvas"]').mouseleave(function(e) {
e.preventDefault();
if ($("body").hasClass('sidebar-open')) {
$("body").removeClass('sidebar-open');
$("body").addClass('sidebar-collapse')
};
});
and here are css classes (with media queries) for this
.main-sidebar,
.left-side {
position: absolute;
top: 0px;
left: 0;
padding-top: 50px;
min-height: 100%;
width: 230px;
z-index: 0;
-webkit-transition: -webkit-transform 0.3s ease-in-out, width 0.3s ease-in-out;
-moz-transition: -moz-transform 0.3s ease-in-out, width 0.3s ease-in-out;
-o-transition: -o-transform 0.3s ease-in-out, width 0.3s ease-in-out;
transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
}
#media (max-width: 767px) {
.main-sidebar,
.left-side {
-webkit-transform: translate(-230px, 0);
-ms-transform: translate(-230px, 0);
-o-transform: translate(-230px, 0);
transform: translate(-230px, 0);
}
}
#media (min-width: 768px) {
.sidebar-collapse .main-sidebar,
.sidebar-collapse .left-side {
-webkit-transform: translate(-230px, 0);
-ms-transform: translate(-230px, 0);
-o-transform: translate(-230px, 0);
transform: translate(-230px, 0);
}
}
#media (max-width: 767px) {
.sidebar-open .main-sidebar,
.sidebar-open .left-side {
-webkit-transform: translate(0, 0);
-ms-transform: translate(0, 0);
-o-transform: translate(0, 0);
transform: translate(0, 0);
}
}
.sidebar {
padding-bottom: 10px;
}
and here is html code where my sidebar resides
<aside class="main-sidebar" data-toggle="offcanvas">
<section class="sidebar">
<ul class="sidebar-menu">
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
</section>
<aside>
I tried to implement it on mouseclick event by keeping adding the sidebar-open class but this didn't work. Any help would be highly appreciated. Thanks
You can put the text in an element like, say p's. Then you can you try hiding the them when mouse leaves and show them when mouse enters. You can add the lines similar to the below ones in your jquery.
// on mouse leave
$('ul.sidebar-menu li>p').hide();
// on mouse enter
$('ul.sidebar-menu li>p').show();
Edit ---
Alternatively you can try the below CSS for aside.main-sidebar,
white-space: nowrap;
overflow: hidden;
Related
i have this code and the image goes up with with the transition but I would like to came back with the transition down when my mouse goes somewhere else
my actually code;
.yt:hover {
transform: translateY(-30px);
transition-duration: 2s;
}
.yt {
transition: 2s;
}
.yt:hover {
transform: translateY(-30px);
}
Move the transition attribute to the whole object
img{
transition: all 2s;
}
img:hover {
transform: translateY(-30px);
}
<img src="some_src.jpg" />
So I'm trying to remove all hover features and auto loading from my site so I commented out all the code that is related to the :hover feature in my site but there is still hovering available.
I'm also trying to remove all the available auto load features like the loader transform and animations. I did but I still see both hovering and some animations.
Is there something that I could be missing?
Like this hover and transform features below I removed them
.cateogory ul li a:hover:before {
transform: scale3d(1, 1, 1);
transform-origin: 0 50%;
}
.category-2 {
transition: all 0.4s ease;
}
In your code it looks like there is a typo
cateogory
.category ul li a:hover:before {
transform: scale3d(1, 1, 1);
transform-origin: 0 50%;
}
.category-2 {
transition: all 0.4s ease;
}
If that does not solve You may create another class and copy all inside and change its classname with javascript
<!-- language: lang-css -->
.category ul li a:hover:before {
transform: scale3d(1, 1, 1);
transform-origin: 0 50%;
}
.category-nohover ul li a:hover:before {
}
.category-2 {
transition: all 0.4s ease;
}
hover is not working on my image. I honestly do not know why. Image is in a div class called portfolio as seen by code below
.portfolio {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.portfolio__item {
background: var(--clr-accent);
}
.portfolio__img{
transition: transform 750ms cubic-bezier(0.5, 0, 0.5, 1),
opacity 250ms linear;
}
.portfolio__img:hover {
transform: scale(2);
opacity: .75;
}
The hover is being carried out on (portfolio__img).
The class of the div is (portfolio__item).
That is the problem.
Try replacing class name with portfolio__img
You have a few mis-types in your CSS:
There should be no space between the colon and hover-- it is a pseudo-selector written as :hover:
(I removed the line regarding the colon after opacity because I misread it, thanks to #pete for the correction.
.portfolio__item {
background: var(--clr-accent);
}
.portfolio__img:hover { /* no space here between : and hover */
transition: transform 750ms cubic-bezier(0.5, 0, 0.5, 1),
opacity 250ms linear;
}
.portfolio__img:hover { /* no space here between : and hover */
transform: scale(2);
opacity: .75;
}
Also, as #bouh points out in the comments, there is no element with the class .portfolio__img in your mark-up, so no elements will be matched by this selector.
If we combine these two things we should have a working example:
.portfolio__item {
background: var(--clr-accent);
}
.portfolio__img:hover {
transition: transform 750ms cubic-bezier(0.5, 0, 0.5, 1), opacity 250ms linear;
}
.portfolio__img:hover {
transform: scale(2);
opacity: .75;
}
<div class="portfolio">
<a href="#" class="portfolio__item">
<p class="portfolio__img" src="../imagefolder/me.jpeg" alt="me">test test test</p>
</a>
</div>
I'm trying to make a button which, on hover, will go up 5px.
It works fine with transitions. But the problem is that, when I hover my mouse on the lower part of the button, as soon as I move the mouse (I'm guessing it checks :hover on mouse update, but I'm new to CSS...), since the button has gone up, it realizes it no longer hovers, so it snaps back into position, and it ends up flickering.
.btn {
display:inline-block;
transform: translate(0px,0px);
transition: transform 50ms ease ;
}
.btn:hover {
transform: translate(0px,-5px);
transition: transform 50ms ease ;
}
<button class="ui button btn"> That rocks!</button>
How can I prevent this behavior? Only possible solution I've found is to use display: inline-block, but it doesn't seem to make any difference.
Also, I've tried using a container div, but it still does the same thing.
Seems to work OK with a container, if you monitor :hover on the container, then transform the button. And you only need to define transition and transform once each.
.btn {
display: inline-block;
transition: transform 50ms ease;
}
div:hover .btn {
transform: translate(0px, -5px);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<button class="ui button btn"> That rocks!</button>
</div>
Put the button into a container, and make it so when you hover over the container it changes the child button:
.container:hover .btn {
transform: translate(0px,-5px);
}
If you set the hover event on the container it should work.
.btn {
display:inline-block;
transform: translate(0px,0px);
transition: transform 50ms ease ;
}
div {
transition: transform 50ms ease ;
background: pink;
}
div:hover .btn {
transition: transform 50ms ease ;
transform: translate(0px,-5px);
}
<div>
<button class="ui button btn"> That rocks!</button>
</div>
When hovering, add an ::after pseudoelement with these styles:
.btn:hover::after {
content: '';
display: block;
position: absolute;
width: 100%;
height: 10px;
}
It will keep the focus on the button.
Snippet:
.btn {
display:inline-block;
transform: translate(0px,0px);
transition: transform 50ms ease;
}
.btn:hover::after {
content: '';
display: block;
position: absolute;
width: 100%;
height: 10px;
}
.btn:hover {
transform: translate(0px,-5px);
transition: transform 50ms ease ;
}
<button class="ui button btn"> That rocks!</button>
Follow up on this topic
When I apply css transform to parent element, child element is not fixed anymore.
http://jsfiddle.net/z8fBD/7/
have tried using only one direction transform but no success.
when you remove transform: translate(0%,0px); everything works just fine, but as you will understand from previous topic, I need this for my animation
Do you mean the move 'button' should stay put? If so, you need to apply the transform to the container element since the body (you should consider renaming this div) will transform all its children. Here are the changes to do that:
JS:
jQuery(document).ready(function($){
$('#move').click(function(){
if(!$('#container').hasClass('move')){
$('#container').addClass('move');
} else {
$('#container').removeClass('move');
}
})
})
CSS:
#body {
position:absolute;
left: 0;
top:0;
width: 200px;
}
#container {
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
-webkit-transform: translate(0%,0px);
-moz-transform: translate(0%,0px);
-ms-transform: translate(0%,0px);
-o-transform: translate(0%,0px);
transform: translate(0%,0px);
}
#container.move {
-webkit-transform: translate(150%,0px);
-moz-transform: translate(150%,0px);
-ms-transform: translate(150%,0px);
-o-transform: translate(150%,0px);
transform: translate(150%,0px);
The rest of the CSS stays the same. Note how styles that were on the body were moved to #container.