ml-auto is not pushing navbar links to the right - css

I'm using reactstrap and have been following this link:
https://reactstrap.github.io/components/navbar/
In the example, the <nav className='ml-auto' navbar> is pushing the <NavItem> to the right. However, what I am trying to implement (which is really similar to the example) the <NavItem> is rendering right next to the <NavbarBrand>.
I've checked the syntax like 100 times and it looks correct. The custom CSS I have, which is very little, does not seem to be overriding anything. The CSS in the console looks pretty similar and it appears to be affected by the:
.ml-auto, .mx-auto {
margin-left: auto!important;
}
At least toggling it off in the console in the example, moves the <NavItem> right next to the <NavbarBrand> like it is in my app (which I don't want). Here is what I am looking at:
Reactstrap Example (correct spacing):
Console for my app (incorrect spacing):
How do I get the spacing right in my app?
It really isn't clear to me what is affecting margin-left: auto !important to work in one and not the other.

For Bootstrap-5 we have to use ms-auto instead of ml-auto

Starting from Bootstrap 5 2021, There are some changes in the side names of spacing utilities.
Margin Left is now called Margin Start, therefore use ms instead of ml
Example: For setting margin-left to auto : use ms-auto
Similarly for setting margin left to 3 : use ms-3 instead of ml-3
You can learn more about the new side names for margins and paddings in the official bootstrap documentation BootStrap Spacing Utilities

The navbar components (and many other components) will only work if you use them the way they've been designed to be used.
For example, ml-auto works on sibling elements.
It does NOT work if you destroy that sibling relationship.
In other words, you cannot just randomly wrap elements in unnecessary divs.
Remove the div you put around the navbar-toggler and the collapse component to make the sibling selector work as intended.
Also: Do NOT use the !important flag as a permanent solution in any of your custom css. That flag is for quick testing only.
P.S. You seem to have a habit of wrapping things in unnecessary divs. The container is also wrapped in such a useless div. Don't add unnecessary code for some sort of "esthetics". Only add code if it actually does something and use comments for everything else.

Explanation on how ml-auto works.
It appears this was already resolved in the comments. I just wanted to add an explanation that ml-auto was not working because it's flexbox parent needs to be full-width of the navbar. So, it could have also been solved by adding w-100 to the extra div..
<nav class="navbar navbar-expand-md navbar-light bg-faded">
<a class="navbar-brand" href="#">reactstrap</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="w-100">
<div class="navbar-collapse collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
...
</ul>
</div>
</div>
</nav>
ml-auto works because of the way the flexbox parent "shrinks" the child block element(s) by default. It has nothing to do with sibling elements, and would work fine with just one child in the flexbox parent: https://www.codeply.com/go/xPaoNJMzbG
Here's a good article on how auto-margins work with flexbox

In Bootstrap-5 there are some changes, earlier it was ml-auto for margin-left:auto which is now changed to ms-auto, similarly mr-auto is changed to me-auto. However for top and bottom it is same as earlier versions of bootstrap i.e versions before bootstrap-5
for more details visit docs

I am using bootstrap#5.0.X
If you are stuck with this problem in 2021,
It is because there has been migration and changes in the class name.
.ml-* and .mr-* to .ms-* and .me-*.
similarly many others class name has been changed.
Link to check migration
Bootstrap Migration link

Related

How to retain the background color when i hover to sibling using CSS

I have build a dropdown menu that works a sweet as it gets.
Right click on an element, brings up he dropdown menu, i hover over the first choise, soo far so good, the font color and the background color changes as it should and the sub-menue opens. The problem is that when i hover over the sub-menu, the i "loose" the gray background color of the "parent"
Any ideas ?
<div id="contextMenu" class="dropdown-menu" role="menu" style="display: block; left: 997px; top: 438px;">
<ul class="dropdown-menu side" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;"><li class="dropdown-submenu"><i class="fa fa-paste" aria-hidden="true"></i> PARENT OPTION <ul class="dropdown-menu"> <li> <a tabindex="-1" data-url="/common/docitem/copymove/?document=247&dest=1&obj_table=companydocument&f=null" id="add_id_copy_p" style="cursor:pointer;" class="js-movecopy-docitem"> Siblin Option</a> </li>
First things first, you must include a code segment to make it easier to understand the issue, as #Paulie-d and #Rokibol Hasan mentioned. To be honest, this sounds like maybe you have conflicting CSS rules or lack of specificity, which results in your parent element being affected on :hover.
These would be the steps I would use to solve this:
Use the find function of your development IDE (CTRL + F) to find :hover elements. Avoid using very broad CSS selectors.
Make sure you have assigned the correct id and class attributes in the desired section of code.
Refresh your memory on CSS specificity. I provide you this website instead of Mozilla only because I do not know if you can handle it. If you are experienced, prefer this website.
Refresh your memory on CSS selectors.
At this point, go in your CSS and start commenting out and testing one by one sections of code that may affect the parent element you speak of.

How to solve the problem of css block dropping out when making a website page?

When making an adaptive web page the child block "falls out" of the parent block. The entire page is shifted some distance to the left, and an empty bar appears on the right, which moves all the content.
I need to put all content in the correct place.
I've tried setting the block width to 100%, but it still gets larger than the parent block.
When making a web page, I used bootstrap v5.1.3, maybe the problem is in some properties in it that override the set width of my block?
I got this error when using the bootstrap 4. I wanted to make offset sections on the page, for this I used the “row” and “col” classes, but they got out of the parent block.
enter image description here
If you look at the picture, you can see that bootstrap does have built-in class indentation (strikethrough now).
To redefine them in the section itself, change the margin to the one you need.
<section class="row **m-0**">
<div class="col-3 brown-background **p-0**"></div>
<ul class="col white-background list-without-point p-0 m-0">
<li class="row align-items-center **m-5**">
//smth here
</li>
<li class="row **m-5** align-items-center">
// smth here
</li>
<li class="row **m-5** align-items-center">
// smth here
</li>
</ul>
</section>
If I understood the problem correctly, this might be the solution.

Bootstrap 3 Collapse Menu issue with Collapse

I have developed a site using wordpress and bootstrap 3 framework. My issue is when its uses the mobile collapse menu it doesn't display after I click the icon.
Been trying to debug a while now but no luck yet.
Site is question is
http://www.reillyscott.com.au/
thanks in advance
<div class="collapse navbar-collapse navbar-responsive-collapse">
Find this div and remove "collapse" class. Its not needed and its causing the issue.
Edit: Actually that div is not need it at all. You can move its innerHtml out of it and delete it.
It's because your JS is not changing the state of the menu to display block, maintaining the display:none;
The menu is being hidden in the bootstrap.css, line 3045.
You should be toggling the menu when a certain resolution comes, making one display:none and the other display:block.
To implement Bootstrap menus in Wordpress, I recommend you to use WP Bootstrap Nav Walker.
Took me a while to figure out your problem. Instead of going into too much detail, I'll just tell you what to delete, and it will work!
<div id="bs-example-navbar-collapse-1" class="navbar-collapse collapse in" style="height: auto;">
<!--
The WordPress Menu goes here
-->
<div class="collapse navbar-collapse navbar-responsive-collapse"> **<--- DELETE THIS DIV**
<ul id="main-menu" class="nav navbar-nav navbar-right"></ul>
You already have a navbar-collapse in your first div. You're using it twice and throwing off the JavaScript. Only delete the opening and closing div. Keep your wordpress menu php code there.
Message me if you have further questions.
Cheers,

Dropdown navigation menu item disappearing after hover

I am using bootstrap to build my site and the main navigation uses dropdowns for second level choices.
In IE10 only (works everywhere else), the dropdown menu is inconsistently accessible and if you are able to access the second level choices, they disappear after hovering off of them. In other words as you hover down the list of menu items, the one above will disappear when you hover onto the menu item below it. Perhaps there are two problems: one being you can't access the dropdown (maybe a padding issue?) but the disappearing problem, I have never seen before.
Here's my fiddle with the problem
(**When viewing the fiddle make sure to adjust the width of the Result panel otherwise it will be collapsed for mobile)
My html is pretty simple:
<div class="container">
<div class="row">
<div class="navbar navbar-inverse" role="navigation">
<div class="navbar-collapse collapse"><!--NAVIGATION-->
<ul class='nav navbar-nav'>
<li class='first'>Getting Around
<ul>
<li>Find Your Ride</li>
<li>Transit Overview</li>
<li>Carpool/Vanpool</li>
<li>Biking & Walking</li>
</ul>
</li>
<li>Travel Training
<ul>
<li>Do It Yourself</li>
<li>Transit Orientation</li>
<li>Transit Ambassadors</li>
<li>Schedule a Training</li>
</ul>
</li>
<li>Senior Safe Driving</li>
<li>Programs & Services
<ul>
<li>Mobility Programs & Services Locator</li>
<li>Mobility Programs Overview</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
Thank you in advance! I am stumped.
A variety of issues at work here, but I seem to have solved it. IE10 doesn't play well with display:none and once I replaced with visability: hidden on my navbar>li>ul, things seemed much better.
Also, can't confirm but since bootstrap adds a background color of transparent to its a tags, I think the background color of the list items we're going transparent. Adding a background color, adjusting the line-height seem to fix.
link to fiddle in original now works correctly in IE10.

Bootstrap tooltip causing buttons to jump

When I hover over a button and the tooltip appears, the buttons jump. If I disable the tooltip, it does not jump. Additionally, the right button loses the rounded edges. How can I prevent this from happening?
<div class="btn-group">
<a rel="tooltip" class="btn" href="#" data-title="View Details"><i class="icon-list-alt"></i></a>
<a rel="tooltip" class="btn" href="#" data-title="Delete"><i class="icon-trash"> </i></a>
</div>
Javascript:
$('[rel=tooltip]').tooltip();
Working version...
http://jsfiddle.net/BA4zM/147/
Here is a website that has it working without the jumping...
http://wrapbootstrap.com/preview/WB005S479
To avoid the jump, you need to set the container attribute. This is documented.
When using tooltips and popovers with the Bootstrap input groups,
you'll have to set the container option to avoid
unwanted side effects.
Try the following:
$('[rel=tooltip]').tooltip({container: 'body'});
As Howie said at https://stackoverflow.com/a/14770263/7598367, it's necesary to add the 'container' to tooltip.
That didn't solve my issue (I had the same problem), it's also necesary to declare at JS file BEFORE the .tooltip() initilization, this way:
$('[data-toggle=tooltip]').tooltip({container: 'body'});
$('[data-toggle="tooltip"]').tooltip();
Hope this helps if somebody has the same problem in the future.

Resources