I have a following section of css:
.navbar {
position: fixed;
display: flex;
z-index: 3;
width: 70px;
background-color: black;
height: 100%;
transition: 0.5s;
}
.navbar:hover {
width: 200px;
}
#media (width < 1080px) {
.navbar {
position: sticky;
transition: none;
flex-direction: row;
width: 100%;
height: 100px;
}
.navbar:hover {
width: 100%;
}
}
It describes a navigation bar that is a sidebar when the viewport is bigger than 1080px. When I hover over it, it stretches to 200px. If the vieport becomes smaller than 1080px, the sidebar becomes horizontal navigation bar.
What I wanted to achieve was a smooth transition of stretching the sidebar on hover and on hover leave. At this moment this works as intended.
What I also wanted was snappy transition from sidebar to horizontal navigation bar and vice versa.
Unfortunately it works only partialy. Although I have achieved the snappy transition from sidebar to horizontal navigation bar, I cannot figure out how can I create snappy transition from horizontal navigation bar to sidebar.
I understand what is the problem here (when changing from horizontal navigation bar to sidebar the transtion is set again to 0.5s hence the animation) but I am struggling to figure out how to achieve two-way snappines from sidebar to navbar while maintaining the "hover-in-and-out" transition.
What would be the correct way of achieving such effect ?
Here is example of current state of the sidebar/navbar in jsfiddle:
https://jsfiddle.net/mz29afyh/2/
Edited:
I have no luck either with purely CSS and I think it might have no solution by just in CSS way because the transition is in effect all the time while window resizing.
When transition is from transition:0.5s to transition:none (screen < 1080, sidebar to navbar), it see a snappy transition because the transition:none is taking effect immediately. Same goes to when transition:none is remove (screen > 1080px, navbar to sidebar), the transition:0.5s is taking effect immediately and that's why it is a smooth transition for all properties.
But there is a workaround with the help of JS, if you don't mind. Here the result sample : https://jsfiddle.net/qog0s7wb/1/
The solution is taking from this article: stop animations during window resize. The idea is stop to the transition while window is resizing with a little help from timer function as shown below :
let resizeTimer;
window.addEventListener("resize", function() {
$('.navbar').addClass('stop-transition');
window.clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
console.log('remove')
$('.navbar').removeClass('stop-transition');
}, 100);
});
And an additional .stop-transition class :
.stop-transition {
transition: none !important;
}
If you want to remain all transition smoothly, then it is simple, just remove the transition: none; when #media (width < 1080px).
Hope it helps!
Related
I'm using Angular4 and I wrote a simple a menu that opens horizontally. For unknown reason when "playing" a little with the menu on different zoom ratios, I noticed some black vertical lines that remains after closing the menu. if I change to another window or change the zoom ratio again, the lines disappear, but I don't understand why they are there from the first place.
NOTE:
The behavior is not consistent. Sometimes there are lines, sometimes not. If there are lines they appear on different places. On 100% scale there is no problems at all.
.menu-container {
background-color: #5a5a5a;
bottom: 23.81rem;
left: 1.625rem;
position: relative;
transition: 0.5s;
}
.menu-content-hide {
height: 0;
width: 0;
}
.menu-content-show {
height: 0;
width: 36.06rem;
}
html
<div class="menu-container"
[ngClass]="{'menu-content-show': selectedItem, 'menu-content-hide': !selectedItem}">
<app-menu-content (_onClose)="handleMenuClicked(null)" [_selectedItem]="selectedItem"></app-menu-content>
</div>
I'm pretty new to coding so it may be that I do not understand what I'm doing. I've tried every bit of code advice given on this website that seems to pertain to my situation and I cannot get results!
My carousel sliders are outside my images and I need them in/on my images. I want them the size they currently are so viewers do not have to scroll up and down to view my entire picture. You can view my predicament at http://mirandarodgers.com/lenoxhouse.html
Like I said, I've tried everything under the sun. Currently my code just says:
.carousel .item{
min-height: 525px; /* Prevent carousel from being distorted if for some
reason image doesn't load */
}
.carousel .item img{
margin: 0 auto; /* Align slide image horizontally center */
position: absolute;
min-width: 100%;
height: 525px;
max-width: none;
}
I'm ashamed of how much of a hack this is, but it might help you out:
.right {
right: calc(100vw / 2 - 374px);
}
.left {
left: calc(100vw / 2 - 374px);
}
So to solve this I gave both the images and the .carousel a fixed max-height (I used 400px).
.carousel .item img,
.carousel {
max-height: 400px;
}
You vertical images will scale to a height of this value.
You can play around with different max-height values and even have the height depend upon the screen size using CSS Media Queries.
Whats happening is that the slider images are aligned to the sides of the actual carousel itself, if you want to restrict the size of the carousel set a max-width on it. This is because the size of your images cannot fit the width/height of the carousel and there isn't any code for resizing the img or the carousel. If you work on the resizing of your elements it should solve the problems you are having and try to find better images that are roughly the same dimensions or the carousel will expand/shrink unexpectedly if it isn't handled correctly.
I added the following to .carousel and it looked much better on the site.
.carousel {
max-width: 70%;
position: relative;
margin: auto;
}
Also i would add an img tag with
img {
max-width:100%
}
And this
.carousel .item {
max-height: 525px;
}
I've just got started with Material Design Lite. I want to change the width of the drawer.
What I have tried is something along these lines:
.mdl-layout__drawer {
width: 25%;
}
This results in the drawer overlapping the content area.
How do I correct this issue?
The drawer is an absolute component that rest in it's parent container a defined left position. When you change it's width, you'll need to alter it's position too.
Here's the css only solution for a width of 500px -
.mdl-layout__drawer {
width: 500px;
left: -250px;
}
.mdl-layout__drawer.is-visible {
left: 0;
}
Here's a codepen example -http://codepen.io/mdlhut/pen/pJmjBe
I have a problem regarding CSS3's transitioning. As seen in the snippet of my CSS file below, I have made a footer slide up whenever it is toggled active (I do this using jQuery).
Whenever it becomes active, it pushes the content of the website upwards until it finishes its transition, at which point the content slides back down. It looks like the page expands, but this should not happen because of the position attribute. Why is this happening?
Thanks in advance for any help.
.footer {
height: 130px;
width: 100%;
position: absolute;
bottom: -130px;
background-color: #333;
transition: bottom 250ms ease-out;
}
.footer-active {
bottom: 0;
}
I found a solution to the problem. It seems whenever the element moves, the window will automatically scroll to the element's position. I fixed the problem by inserting overflow: hidden into the html's and body's CSS rule.
is the any solution for a pure CSS3 / HTML Thumbnail Zoomer?
2 Solutions would be Ok: A popup Window, or another Div remaining in the Site + showing the current hovered area of the thumbnail picture.
But it has to be without js for eBay.
Many thanks.
You could do this
#yourDiv:hover {
transform: scale(5);
}
The image might be a tad blurry. But give it a try and see how it works.
Or another option would be to create another div and then add the following css
#anotherDiv {
width: 800px; /* use whatever width you want, can be px or % */
height: 500px; /* use whatever height that works */
display: none; /* this will hide it from appearing until the user hovers over the thumbnail #yourDiv */
}
#yourDiv:hover #anotherDiv {
display: block; /* this will show it when they hover over thumbnail #yourDiv */
}