How to change bootstrap in wordpress? - wordpress

I am using this code to make a nav menu bar. As you can see the menu items are too close and it doesnt change the background color when hover. I want to edit the css for those items. What do I need to write in design.css ? Thankyou
header.php
<div class="container">
<div class="row">
<div class="col">
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-dark">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand text-white" href="#" style="margin-left: 50px;">Web</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<?php wp_nav_menu(array('theme_location'=>'primary', 'container'=>false, 'menu_class'=>'nav navbar-nav ml-auto','item_spacing'=>'preserve' )); ?>
<button class="btn btn-primary navbar-btn navbar-right" style="margin-left: 10px;">Login</button>
<button class="btn btn-default navbar-btn navbar-right" >Register</button>
</div>
</div>
</nav>
</div>
</div>
functions.php
//css
wp_enqueue_style('bootstrap', get_template_directory_uri().'/bootstrap/css/bootstrap.min.css', array(), '4.1.3', 'all');
wp_enqueue_style('customstyle', get_template_directory_uri().'/css/design.css', array('bootstrap'), '0.0.1', 'null');
//js
wp_enqueue_script('jquery');
wp_enqueue_script('bootstrapjs',get_template_directory_uri().'/bootstrap/js/bootstrap.min.js', array(), '4.1.3', true);
wp_enqueue_script('customjs', get_template_directory_uri().'/js/code.js', array(), '1.0.0', true);
I tried this in design.css
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
color: #000; /*Sets the text hover color on navbar*/
}

I fixed it. I changed CSS Classes in Appearance, menus to navbar-default then this:
wp_enqueue_style('customstyle', get_template_directory_uri().'/css/design.css', array(), '1.0.0', 'all');
.navbar-default a:hover {
background: #222;
color: #ffffff;
}

Related

Joomla 4 with Bootstrap 5 template custom css not working

I made a basic bootstrap 5 template for my Joomla 4 website and trying to customize navbar but css added to user.css some how not working.
I see the user.css is loaded in the source code of the page and also see the code inside the user.css file on the web server.
Here is my navbar code and css:
user.css
nav .navbar-dark .nav-link {
text-decoration: none !important;
}
Index.php
<nav class="navbar navbar-dark bg-dark navbar-expand-lg">
<div class="container-fluid">
<?php echo ($sitename); ?>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainmenu" aria-controls="mainmenu" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Put menu links in the navbar -->
<?php if ($this->countModules('menu')): ?>
<div class="collapse navbar-collapse" id="mainmenu">
<jdoc:include type="modules" name="menu" style="none" />
</div>
<?php endif; ?>
</div>
</nav>
https://jsfiddle.net/nLp4je5m/
text-decoration: underline is applied to the a tag. Therefore you need to
remove the space between nav .navbar-dark AND
add a
nav.navbar-dark .nav-link a {
text-decoration: none;
}
to remove the line. !important should only be needed if you have other CSS definitions modifying the text-decoration for a elements.

Bootstrap 4.5.0: My Toggle Button Appears Just to the Right of my Brand Image/Name?How Do I Position it to the Left?

I have a problem where the toggle button appears just to the right of my brand image. The same thing happens if I use a brand name. This is what it looks like.
I want the toggle to look like this.
I have searched for solutions but all of them are dealing with earlier versions of Bootstrap. I started having the problem when I upgraded the Bootstrap gem to 4.5.0.
Here is my html code.
<div class="navbar-header">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-main-collapse">
<i class="fas fa-bars"></i>
</button>
<%= link_to image_tag("ibraini_navbar.png", class: "img-fluid navbar-brand", alt: "#{t :page_title_home}"), home_path %>
</div>
Here is the related CSS code. I didn't include the code where I set the height of the navbar to adjust the size of the image.
.navbar-custom .navbar-brand, .navbar-custom .navbar-header, .navbar-custom .navbar-nav { a { color: $linkColorHeader; } a:hover, a:focus { text-decoration: none; color: $linkColorHover; } }
.navbar-custom .navbar-toggler { color: $linkColorHover; #include font-size(24px); border-radius: 2px; padding: 0 4px; }
.navbar-custom .navbar-toggler:hover, .navbar-custom .navbar-toggler:focus { background-color: #599ed7; color: $linkColorHeader; }
.navbar-custom .navbar-brand .navbar-toggler:focus, .navbar-custom .navbar-brand .navbar-toggler:active, .navbar-custom .navbar-brand:focus { outline: 0; }
I have the same problem if I use a brand name. The toggle is still positioned just to the right of the name.
I have similar html and css code in the other program that is working like the second picture.
I checked the current documentation and it says that the toggle goes to the left by default which is what I want. I have never had this problem with a toggle. Hopefully there is something that I'm not seeing that can be easily fixed.
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand text-light" href="#">
<img src="" alt="logo-here" style="width:40px;"> Brand Name
</a>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-light" href="#">Link Here</a>
</li>
</ul>
</div>
</nav>
I took another look at the Bootstrap documentation. I realized that class 'navbar-header' no longer exists in Bootstrap 4.5.0. I rewrote my markup to look like the documentation found here.
The markup in my question is gone. Here is my new code.
<nav class="navbar fixed-top navbar-expand-lg navbar-custom">
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target=".navbar-main-collapse"> <i class="fas fa-bars"></i> </button>
<div class="collapse navbar-collapse navbar-right navbar-main-collapse">
<%= link_to locale_root_path(anchor: "overview"), class: "navbar-brand page-scroll" do %>
<span class="text-red">Light</span><span class="text-blue">Be Corp</span>
<% end %>
......
</div>
</nav>
I have the toggle to the left without the brand name as expected. All of my websites will need to be modified. That's why my second image shows the brand name.

Wordpress Boostrap NavMenu on mobile hides after displaying

Here is my code, the overall design will get an improvement soon enough. Just currently getting it functional.
Anyway the issue is when on a mobile phone and you click on the navbar toggle button, then menu shows and disappears instantly.
<div class="header-main white">
<div class="container-fluid">
<div class="logo">
<img src="<?php echo get_template_directory_uri(); ?>/img/logo.png" alt="Mission Curling">
</div>
<div class="responsive-logo">
<img src="<?php echo get_template_directory_uri(); ?>/img/mcc-logo.png" alt="Mission Curling">
</div>
<div class="main-menu">
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-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 visible-xs" href="#"></a>
</div>
<div class="navbar-collapse collapse" id="bs-navbar-collapse">
<ul class="nav navbar-nav list-inline">
<?php
wp_nav_menu( array(
'menu' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-navbar-collapse',
'menu_class' => 'nav navbar-nav list-inline sub-menu normal-sub',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
</ul>
</nav>
</div>
</div>
</div>
Though better yet here is a link to the website that I am having the issue on. Curling Website I am in the midst of building them a new wordpress site.
From what I can find is this becomes active after the toggle is clicked.
.collapse {
display: none;
visibility: hidden;
}
So manually if I change that visibility then it works fine. Anything obvious stick out?
in mobile layout when the menu button clicked it is adding "show" class in "navbar-collapse collapse" so the visibility hidden property of collapse is remaining as it is. to solve this either you can add visibility : visible property in show class or you can remove the visibility : hidden property from collapse class because show class is overwriting the display property of collapse so it will work fine without visibility property..
Just try overriding your bootstrap property.
.collapse {
display: none;
visibility: visible !important;
}

change button border color when the button is being clicked and after

What to do to change navbar-toggle button behaviour when the button is being clicked and after?
It gets some blue border color.
<nav 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="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
</div>
</div>
</nav>
It might be this, bootstrap has some automatic styling for .navbar-toggle. You can add something like below to counteract it's default styling.
.navbar-default .navbar-toggle:focus, .navbar-default .navbar-toggle:hover{
border:none;
}
.btn.active.focus, .btn.active:focus, .btn.focus, .btn:active.focus, .btn:active:focus, .btn:focus {
outline: 0;
}
.navbar button {
outline: none !important;
}
This did the trick for me.
I am not quite sure how your button is being displayed when it has a class="navbar-toggle" but I think what you need is something like :
$('button.navbar-toggle').on('click', function () {
$(this).css('border', '1px solid blue');
});
If you wish to not use jQuery, you can do :
document.querySelector('button.navbar-toggle').addEventListener('click', function (e) {
e.target.style.border = '1px solid blue';
});
try css:
[your-btn] {out-line: none;}

Rails navbar color not changing completely Bootstrap

I'm new in rails, so far I'm stuck trying to change the color of the navbar.
I have read almost everything about the subject and I haven't seen anything like my case.
As you can see in the pictures, the navbar changed to the color I wanted but for some reason the corners are still in black and also the background of my dropdown menu still in black.
Well I cannot upload pictures because I'm new here.
The github repository is at https://github.com/nanurbina/janus.git
I hope someone can give me a hand.
Here is my code on _navigation.html.erb
<nav class="navbar navbar-inverse navbar-fixed-top">
<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>
<%= link_to 'Janus BPO', root_path, class: 'navbar-brand' %>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<%= render 'layouts/navigation_links' %>
</ul>
</div>
and the code on the css.scss
#import "bootstrap-sprockets";
#import "bootstrap";
.navbar-brand {
font-size: inherit;
background-color:#2d246d;
border-color:#2d246d;
color:#2d246d;
}
.navbar-collapse
{
background-color:#2d246d;
border-color:#2d246d;
color:#2d246d;
}
.navbar-inverse .container {
background-color:#2d246d;
border-color:#2d246d;
color:#2d246d;
}
Thanks!
Replace navbar-inverse with myNavbar on your html and add the following to your CSS:
.myNavbar {
background-color: #ccc;
color:#222;
border: 1px solid #333;
}
Just change the color codes to what you want and you're good to go.

Resources