Tips for perfectly aligning elements (such as text and images) within the navbar

Hi everyone, I hope you're doing well. Currently, I'm working on aligning a small icon with some text. I've tried using the d-inline class inside the a tag, but it doesn't seem to be working. Another issue I'm facing is related to the background color. The background color seems to be appearing just behind the ul tag for some reason. I added a class called navbar-custom to the nav tag, but it's not having the desired effect.

Here is the code snippet:

.navbar-custom {
    background-color: #fafafc;
}

/* Changing brand and text color */
.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
    color: #369d4a !important;
}
/* Changing link color */
.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item .nav-link {
    color: #369d4a !important;
}
/* Changing color of active or hovered links */
.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:hover .nav-link {
    color: #2b5c35 !important;
}

.navbar-custom .navbar-brand {
    color:#369d4a;
}
.navbar-custom .navbar-toggle {
    background-color:#369d4a;
}
.navbar-custom .icon-bar {
    background-color:#369d4a;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  <body>
  <nav class="container navbar-expand-lg fixed-top navbar-custom navbar-dark ">
    <div class="container">
      <a class="navbar-brand">
        <button class="navbar-toggler navbar-toggle btn_small_screen float-right" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
      </a>
      <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
        <ul class="nav">
          <li class="nav-item mx-4"> 
            <a class="nav-link d-inline" href="#">
              <span data-feather="home"></span>
              TEST1
            </a>
          </li>

         (Additional HTML code removed for brevity)

        </ul>
      </div>
    </div>
  </nav>
  <script src="https://unpkg.com/feather-icons/dist/feather.min.js"></script>
  <script>
    feather.replace()
  </script>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
 </html>

Best regards

Answer №1

One way to organize items in a navigation bar is by utilizing flexbox

.nav-class {
    display: flex;
    align-items: center;
    justify-content: space-between; /* or center based on your layout */
    padding: 1rem;
} 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a NgFor loop in Angular 8 to display a dropdown menu styled using Material

I'm currently facing an issue with incorporating a Materialize dropdown within a dynamically generated table using *ngFor. The dropdown does not display when placed inside the table, however, it works perfectly fine when placed outside. <p>User ...

Transform the snake code by incorporating a visual image as the face of the serpent

Can someone help me change the snake's face to an image instead of a color fill in this code? And how can I add arrows for mobile compatibility? (function() { // Insert JS code here })(); // Insert CSS code here This code snippet includes functi ...

In the Bootstrap Grid system, all posts are aligned to the left side

I have created a gallery with Bootstrap in React.js. The posts are currently displayed using the bootstrap grid system, however, all posts appear on the left side and I am struggling to center them. Any ideas on how to achieve this? https://i.sstatic.net/ ...

What's the best way to correct a word that is positioned at the bottom of a banner image?

https://i.sstatic.net/3gSoi.pngI am a newcomer to all of this. I have a banner image and I want to position a word at the bottom center of the banner. I've tried using padding, position, and text-align, but it's not responsive - when I widen the ...

Is it possible for search engines like google to index Javascript content that is stored within divs and loaded onto the page?

My website utilizes JavaScript to dynamically add content to div elements, like so: <script> //This content is generated by PHP var contents = [ "Item 1", "Item 2" ]; //Display the first item document.getElementById( "item" ).textCo ...

The conditional CSS appears to be malfunctioning

Hi, I am attempting to use conditional CSS in my stylesheet to set a different width for IE6. I have tried the following code but it is not working: div.box { width: 400px; [if IE 6] width: 600px; padding: 0 100px; } How can I su ...

Align multiple elements in a responsive fixed container

I have been attempting to center multiple elements, including images and buttons, within a fixed div at the top of the screen. Despite trying various tricks I found online, none seem to be effective. My goal is to ensure that the alignment works seamlessly ...

Newly added rows to the table after filtering remain visible

I am currently using the DataTable API and jQuery to create a table by fetching rows from the server. However, I encounter an issue when I click a button to load additional rows and append them to the end of the table. The problem arises when I try to hide ...

What is the proper way to utilize the name, ref, and defaultValue parameters in a select-option element in React Meteor?

I recently developed a Meteor project using ReactJS. I have a Create/Edit page where I use the same input field for various form elements. Here is an example of code snippet that I currently have: <FormGroup> <ControlLabel>Province</Control ...

Guide on displaying Adsense ads specifically for mobile devices

Can anyone provide me with a proper method to show/hide my AdSense ads on both mobile and desktop? I am currently using a method that results in 2 console errors. Here is the current approach: We are utilizing two classes, "mobileShow" and "mobileno," t ...

Is dividing a container into equal sections possible with flexbox?

Is there a way to create an HTML/CSS structure that divides a fixed-size container into three sections horizontally? The first section should expand based on its content, while the remaining two sections should evenly split the leftover space, with scrollb ...

Issue with Angular 2 NgFor Pattern Error Message Display Absence

I am attempting to incorporate inputs with a regex requirement within an ngFor loop, but I am not receiving the expected error message when entering something that does not match the required pattern. Even when I input an incorrect pattern, "Test" remains ...

Styling your Vuetify V-data-table with CSS

Struggling to add extra spacing between table rows, despite inspecting the page and verifying that my styles are not being overridden. Have read other Vuetify posts on applying CSS but still no luck. Any suggestions for why I can't style my table as d ...

Can we use CSS to animate the enlargement of an element without moving it?

Take a look at this jsFiddle. With CSS animations gaining popularity, I am interested in creating an effect where an element (.box) expands with an animation when the mouse hovers over it. The challenge is to keep the center of the element fixed while enla ...

Using media queries, one can adjust the positioning of elements in CSS

Can someone please help me? I'm struggling to change the position of a div from absolute to static when the page width reduces to 800px. The challenge is that I can't modify certain code because I am displaying a slideshow that maintains an aspec ...

Validation message causing Bootstrap form inline to lose center alignment

Could someone please assist me with form inline in Bootstrap? I am trying to ensure that all inputs are of the same height (or centered), but I'm facing an issue when a validation message is displayed. DEMO: http://codepen.io/Tursky/pen/gpvgBL?editor ...

Users using an iPhone are unable to adjust the scale or scroll on this website

I find myself wondering what I might be overlooking in this situation Here is the HTML code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="shortcut icon" href="../../nImg/favicon.ico" ...

Struggling to properly position my dropdown menu without causing the div content to shift downward

<div id="header"> <a href="#" id="logo"></a> </div> <div id="nav_cont"> <ul id="nav"> <li id="main_btn"><a class="mainlink" href="#">Parent 01</a></li> <li id="communities_btn">< ...

How do I create a navigation bar with dual sides?

I currently have a navigation bar implemented with the following code. * { margin:0px; padding:0px; } #bs-example-navbar-collapse-1 ul { list-style:none; } #bs-example-navbar-collapse-1 ul li { width:150px; line-height:50px; text-ali ...

Switching the image by clicking on the link

Looking for assistance with a code that displays three button images and fades in the relevant div when clicked using jQuery... http://jsfiddle.net/ttj9J/11/ HTML <a class="link" href="#" data-rel="content1"><img src="http://i.imgur.com/u1SbuRE ...