Animating Bootstrap 5 dropdown - css

I am attempting to animate a right-aligned Bootstrap dropdown with CSS and am not able to get it working. I thought by setting the transition property to apply to the element's width property it would work, but it does not.
I can see the width of the element is initially set to 0 in my browser inspector, and is set to "auto" after the menu is made visible. I can see the transition getting applied if I adjust the width manually, but for some reason it won't happen when the menu is shown. I've tried using pixel values instead of "auto" with no change.
I'm expecting to see the menu "slide out" to the right at the same rate as the menu button rotates. Is this possible?
div.dropdown > .btn {
transition: transform 0.8s cubic-bezier(0,-0.14,.27,1.55);
transform: rotate(90deg);
}
div.dropdown > .btn.show {
transform: rotate(270deg);
}
div.dropdown > .dropdown-menu {
transition: width 0.8s cubic-bezier(0,-0.14,.27,1.55);
width: 0;
}
div.dropdown > .btn.show + .dropdown-menu {
width: auto;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.bundle.min.js"></script>
<div class="dropdown dropend p-4">
<button class="btn btn-secondary" type="button" data-bs-toggle="dropdown">
++
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
</ul>
</div>

You can try this solution.
Animation in transition is your own.
div.dropdown > .btn {
transition: transform 0.8s cubic-bezier(0,-0.14,.27,1.55);
transform: rotate(90deg);
}
div.dropdown > .btn.show {
transform: rotate(270deg);
}
div.dropdown>.dropdown-menu {
display: inherit;
transform: translate(69px, 19px) scaleX(0);
transition: all 0.8s cubic-bezier(0,-0.14,.27,1.55);
transform-origin:left;
left: 0;
}
div.dropdown>.btn.show+.dropdown-menu {
display: inherit;
transform: translate(69px, 19px) scaleX(1);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/js/bootstrap.bundle.min.js"></script>
<div class="dropdown dropend p-4">
<button class="btn btn-secondary" type="button" data-bs-toggle="dropdown">
++
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
</ul>
</div>
Fixed for firefox
div.dropdown>.btn.show+.dropdown-menu {
display: inherit;
transform: translate(69px, 19px) scaleX(1);
}

Related

Translate3D overlaps absolute position elements

I have a navbar with an absolute position and an mage slider. I want to animate the image transition with translate3d/translateX the image ends up overlapping my navigation bar.
Quick example: https://jsfiddle.net/tqu0n4za/
What's a good way to keep the absolute positioning but push the navigation bar in front of the image slider?
My navbar html:
<div id="navbar">
<a id="branding" href="index.html">Hi</a>
<img id="navbar-menu-image" src="..\Images\Menu-Icon-White.svg" alt="Menu_Icon.svg"/>
<!-- Navigation Bar -->
<nav>
<ul>
<li>
<a href="index.html" id='current'>Home</a>
</li>
<li>
<a href='#'>About</a>
</li>
<li>
<a href='#'>Contact</a>
</li>
<li>
<a href='#'>CV</a>
</li>
</ul>
</nav>
</div>
My navbar css:
#navbar
{
position: absolute;
width: 100%;
transition: 0.2s ease;
}
My image slider html:
<div id="image-slider">
<img class="image-slider-images" src="..\Images\Wallpaper1.jpeg"/>
<img class="image-slider-images" src="..\Images\Wallpaper2.jpeg"/>
<img class="image-slider-images" src="..\Images\Wallpaper3.jpeg"/>
</div>
My image slider css:
.image-slider-images
{
width: 1920px;
transform: translate3d(-1000px, 0px, 0px);
height: 800px;
}
z-index: 1;
In my navbar css fixed my issue.
This is what my css looks like now:
#navbar
{
position: absolute;
width: 100%;
z-index: 1;
transition: 0.2s ease;
}
Also, updated jsfiddle: https://jsfiddle.net/tqu0n4za/1/

Css focus on button is working in Edge and in Chrome, but in Firefox and IE is not

I'm loking over stack and over internet to find a solution to fix a problem with
button:focus
I had creade dropdown focus menu, like for example (http://koen.kivits.com/articles/pure-css-menu/)
My CSS code:
.dropdown-button:focus > .dropdown-list {
display: block;
visibility: visible;
}
.dropdown-button {
padding-left: 0;
text-decoration: none;
display: list-item;
box-sizing: border-box;
position: relative;
list-style-type: none;
height: 100%;
}
.dropdown-list {
padding-left: 0px;
position: absolute;
background-color: #action-dropdown;
min-width: 180px;
z-index: 1;
text-align: left;
border: 1px solid #action-border;
display: none;
transition: display 0.2s;
}
And my HTML:
<button class="button button-border btn-large" ng-disabled="!hashMap['object:1'].active" ng-click="hashMap['object:1'].actionEvent()"><span class="hint">Press on me to expand extra buttons</span>
<ul class="dropdown">
<li class="dropdown-button" tabindex="0"><span ng-bind-html="hashMap['object:1'].icon" class="icon ng-binding"><i class="fa fa-ship"></i></span><span class="block"><span ng-bind="hashMap['object:1'].name" class="text ng-binding">Vessel visit</span><i class="fa fa-caret-down"></i></span>
<ul class="dropdown-list">
<li class="dropdown-button">
<button class="button button-border inline-style" ng-disabled="!hashMap['object:2'].active" ng-click="hashMap['object:2'].actionEvent()" disabled="disabled"><span ng-bind-html="hashMap['object:2'].icon" class="inline-icon ng-binding"><i class="fa fa-reply"></i></span><span ng-bind="hashMap['object:2'].name" class="inline-text ng-binding">btn1</span></button>
</li>
<li class="dropdown-button">
<button class="button button-border inline-style" ng-disabled="!hashMap['object:3'].active" ng-click="hashMap['object:3'].actionEvent()" disabled="disabled"><span ng-bind-html="hashMap['object:3'].icon" class="inline-icon ng-binding"><i class="fa fa-reply"></i></span><span ng-bind="hashMap['object:3'].name" class="inline-text ng-binding">btn2</span></button>
</li>
<li class="dropdown-button">
<button class="button button-border inline-style" ng-disabled="!hashMap['object:4'].active" ng-click="hashMap['object:4'].actionEvent()" disabled="disabled"><span ng-bind-html="hashMap['object:4'].icon" class="inline-icon ng-binding"><i class="fa fa-arrows"></i></span><span ng-bind="hashMap['object:4'].name" class="inline-text ng-binding">Replan</span><span class="hint">btn3</span></button>
</li>
</ul>
</li>
</ul>
In Google Chrome (version 56) and Microsoft Edge (version 38) is working.
But on the otherside in Mozilla Firefox (version 52) and Internet explorer (version 11)

How to adapt bootstrap navbar drop-down to be inline

I've been asked to have inline sub-menu items for a site I'm making using Bootstrap.
The default with Bootstrap for drop-down is a nice 'downdown-toggle' class where items are stacked and only width of items with some padding.
How can I adapt that class for the sub-menu background to be 100% screen width, then sub-menu items in container and items (li's) to be inline not stacked? See mock-up image of what I want to achieve.
Note that unlike the current sub-menu, this would need to push all content below down rather than hover over it.
EDIT after mk14 gave really good code below. This is what I get (see image below). I just need items to be in a container (i've shown in yellow) and to push the content of the page down and back up as menu shows and hides. To reiterate, I want the grey background to be 100% width of screen as I said, but items in the container.
Okay, I'm expanding on the first answer based on the comments you made under it and adding more specificity and the media query.
http://jsbin.com/rusup/1/edit
DEMO: http://jsbin.com/rusup/1/
CSS (add your breakpoint when the larger viewport menu kicks in )
#media (min-width:768px) {
body { padding-top: 60px } /* height of the menu collapsed */
.nav-bg {
height: 0px;
width: 100%;
position: absolute;
top: 50px;
background: #e7e7e7;
transition: all .5s ease-in-out;
}
.menu-open .nav-bg { height: 50px } /* change to your height of the child menu */
.menu-open #page {
padding-top:60px;
transition: all .2s ease-in-out;
}
.navbar-nav.nav > li { position: static }
.navbar-nav.nav .dropdown-menu {
left: 0 !important;
right: 0 !important;
box-shadow: none;
border: none;
margin: 0 auto;
max-width: 1170px;
background: transparent;
padding: 0;
}
.navbar-nav.nav .dropdown-menu > li { float: left }
.navbar-nav.nav .dropdown-menu > li > a {
width: auto !important;
background: transparent;
line-height: 49px;
padding-top: 0;
padding-bottom: 0;
margin: 0;
}
}
jQuery:
$('.navbar').append('<span class="nav-bg"></span>');
$('.dropdown-toggle').click(function() {
if (!$(this).parent().hasClass('open')) {
$('html').addClass('menu-open');
} else {
$('html').removeClass('menu-open');
}
});
$(document).on('click touchstart', function (a) {
if ($(a.target).parents().index($('.navbar-nav')) == -1) {
$('html').removeClass('menu-open');
}
});
HTML
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li>Link</li>
</ul>
<li class="dropdown">
Dropdown 2 <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Dropdown 2 Child 1</li>
<li>Dropdown 2 Child 2</li>
<li>Dropdown 2 Child 3</li>
<li>Dropdown 2 Child 4</li>
</ul>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container" id="page">
Me finks this is a page.
</div>
This post covers this topic as a general solution.
Here is an adaptation for bootstrap:
.nav > li{
position: static !important;
}
.dropdown-menu {
left: 0 !important;
right: 0 !important;
}
.dropdown-menu > li{
float: left !important;
}
.dropdown-menu > li > a{
width:auto !important;
}

Font-awesome hover seems have a delay

I am trying to achieve hover animation with font-awesome fa icon-circle.
Problem is "Facebook circle" animation seems comes with delay. How can i achieve faster light on animation without giving smaller number of animation time with transitions.
HTML
<ul class="social-icons">
<li>
<a href="#www.facebook.com/mobge">
<span class="fa-stack fa-3x socialSpan">
<i class="fa fa-circle fa-stack-2x circleIco">
</i>
<i class="fa fa-facebook fa-stack-1x secondIco">
</i>
</span>
</a>
</li>
[...]
</ul>
SCSS
.socialSpan, .circleIco, .secondIco{
-webkit-transition:all 0.4s; /* For Safari 3.1 to 6.0 */
transition:all 0.4s;
}
.social-icons{
li{
a{
color: $sublimeGray;
}
a:hover{
color: $facebookColor;
margin-top: 20px;
}
}
}
Example: http://codepen.io/anon/pen/zaBxE/
Thank you.
You apply a CSS transition to two extra elements here, which may slow the transition.
It concerns socialSpan's children so remove the transitions applied to:
.socialSpan {
transition:all 0.4s;
}
instead of
.socialSpan, .circleIco, .secondIco{
transition:all 0.4s;
}
Demonstration!

applying grayscale on unordered list images

What is the simplest way to fade my 3 images into grayscale when hovered upon. This is for my footer.
Here is my html code:
<ul class="review-icons">
<li><a href="http://www.tripadvisor.ca/Restaurant_Review-g154943-d708757-Reviews-Balilicious-Vancouver_British_Columbia.html" target="_blank"><img class"grayscale" src="http://dev.baliliciousrestaurant.com/wp-content/uploads/2013/12/social-trip-advisor.jpg" alt="Trip Advisor" height="26" width="26">
</a>
</li>
<li><a href="http://www.urbanspoon.com/r/14/181587/restaurant/South-Cambie-Street/Balilicious-Modern-Indonesian-Vancouver" target="_blank"><img class"grayscale" src="http://dev.baliliciousrestaurant.com/wp-content/uploads/2013/12/social-urban-spoon.jpg" alt="Urbanspoon" height="26" width="26">
</a>
</li>
<li><a href=http://www.yelp.ca/biz/balilicious-modern-indonesian-vancouver?nb=1" target="_blank"><img class"grayscale" src="http://dev.baliliciousrestaurant.com/wp-content/uploads/2013/12/social-yelp.jpg" alt="Trip Advisor" height="26" width="26">
</a>
</li>
</ul>
my CSS so far:
ul.review-icons > li {
display: inline;
list-style: none;
margin: 15px;
top: 5px;
position: relative;
}
what it looks like in fiddle:
http://jsfiddle.net/FLBRG/2/
** extra - is it possible for the grayscale to scroll in from bottom to top
Plz n Thx
One easy way (but depends on your background color being white):
ul.review-icons > li:hover {
opacity: 0.5;
}

Resources