The elements are out of sync and not properly aligned

Having trouble creating a navbar and encountering two issues.

  1. The search text bar's width is not 100%, it should fill the width to 100% of its column.
  2. The Glyphicons are not vertically aligned.

For reference, you can check out this JSFiddle link

Any assistance would be greatly appreciated. Thank you.

html {
  background-color: #F4F5F9
}

body {
  padding-top: 50px;
}

.navbar.navbar-default {
  background-color: #3b5998;
  color: #fff;
}

.navbar-default .navbar-collapse,
.navbar-default .navbar-form {
  border-color: transparent;
  box-shadow: none;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="col-xs-8 col-md-8 col-lg-8">
      <form class="navbar-form navbar-right">
        <div class="form-group">
          <div class="input-group input-group-md">
            <span class="input-group-addon transparent"><span class="glyphicon glyphicon-search" style="margin-top: 0px;"></span></span>
            <input class="form-control left-border-none" placeholder="Search things..." type="text" name="search_text">
          </div>
        </div>
      </form>
    </div>
    <div class="col-xs-4 col-md-4 col-lg-4">
      <form class="navbar-form navbar-left">
        <div class="form-group">
          <a href="#"><span class="glyphicon glyphicon-home" style="font-size: 21px; margin-top: 0px;"></span></a>
          <a href="#"><span class="glyphicon glyphicon-envelope" style="font-size: 21px;margin-top: 0px;"></span></a>
          <a href="#"><span class="glyphicon glyphicon-user" style="font-size: 21px;margin-top: 0px;"></span></a>
        </div>
      </form>
    </div>
  </div>
</nav>

Answer №1

1.

.navbar-default .container {
  display: flex;
}
.navbar-default .container [class^="col-"]:first-child, 
.navbar-default .container [class^="col-"]:last-child {
  width: auto;
  white-space: nowrap;
}

I'm curious about the use of col-*-* here when it seems like their default behavior is being overridden.
Additionally, it's recommended to always use col-*-* directly within .rows.


2.

.navbar-left .glyphicon {
  line-height: 34px;
}

Functional demonstration:

html {
  background-color: #F4F5F9
}

body {
  padding-top: 50px;
}

.navbar.navbar-default {
  background-color: #3b5998;
  color: #fff;
}

.navbar-default .navbar-collapse,
.navbar-default .navbar-form {
  border-color: transparent;
  box-shadow: none;
}

.navbar-default .container {
  display: flex;
}
.navbar-default .container [class^="col-"]:first-child, 
.navbar-default .container [class^="col-"]:last-child {
  width: auto;
  white-space: nowrap;
}

.navbar-left .glyphicon {
  line-height: 34px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="col-xs-8 col-md-8 col-lg-8">
      <form class="navbar-form navbar-right">
        <div class="form-group">
          <div class="input-group input-group-md">
            <span class="input-group-addon transparent"><span class="glyphicon glyphicon-search" style="margin-top: 0px;"></span></span>
            <input class="form-control left-border-none" placeholder="Search things..." type="text" name="search_text">
          </div>
        </div>
      </form>
    </div>
    <div class="col-xs-4 col-md-4 col-lg-4">
      <form class="navbar-form navbar-left">
        <div class="form-group">
          <a href="#"><span class="glyphicon glyphicon-home" style="font-size: 21px; margin-top: 0px;"></span></a>
          <a href="#"><span class="glyphicon glyphicon-envelope" style="font-size: 21px;margin-top: 0px;"></span></a>
          <a href="#"><span class="glyphicon glyphicon-user" style="font-size: 21px;margin-top: 0px;"></span></a>
        </div>
      </form>
    </div>
  </div>
</nav>


Remember to autoprefix your CSS before deployment. For broader browser compatibility, select > 0% in settings (small box at the bottom).

Side note: ensure that jquery(.min).js loads before bootstrap(.min).js.

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

Implementing CSS styles with jQuery

Looking for a way to dynamically add CSS attributes to different form elements like text fields, text areas, checkboxes, and dropdowns? There's also a separate block that lists possible CSS properties such as font, font-style, width, and padding. What ...

Unique float structure within a division of divs

Can divs be floated within another div like this? Here is the code: <div class="event_month"> <div class="event1">1</div> <div class="event2">2</div> <div class="event3">3</div> <div class="event4">4</di ...

sticky header on pinned tables in a React data grid

I have combined 3 tables together, with the middle table containing a minimum of 15 columns. This setup allows users to horizontally scroll through the additional columns conveniently. However, I am facing a challenge in implementing a sticky header featu ...

Website experiencing issues with image sizing

On my website, in the Current Books section, I have a row of images. To ensure that all the images are the same height, I initially set the height of the HTML book image to 378 using: <img alt="HTML & CSS" height= "378" src="html.jpg"> Using ...

Click a button to show or hide text

I am attempting to create a button that will toggle text visibility from hidden using 'none' to visible using 'block'. I have tried the following code but unfortunately, it did not yield the desired outcome. <p id='demo' s ...

Issue with rendering Html Element on FireFox compared to Chrome

Having some trouble with an individual component (a simple dropzone) while testing on Firefox. It seems to work fine on Chrome, and the CSS looks good. Css .container { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); wi ...

Ways to adjust brightness of a color using jquery

I have implemented color swatches and a slider to adjust the lightness and darkness of colors. I am seeking a way to change the lightness of the color based on the slider value. Here is what I have attempted: $("#darklight").slider({ range: "min", ...

Successful AJAX Post request functioning exclusively within the Web Console (Preview)

When a user clicks on an element on the website, I have a simple AJAX request to send the ID of that element. However, the script only works in the Web Console under the Network -> Preview section and this issue occurs across all browsers. Here is the ...

Developing a placeholder directive with AngularJS

Are you looking to create a unique element in AngularJS to facilitate nested ng-repeats? Take a look at the example below: data.test = [{h:1, d:[11,12]}, {h:2, d:[21,22]}]; ---------------------- <custom ng-repeat="a in data.test"> <h3>{{a ...

Getting Your Content Centered Horizontally with Fixed Positioning in CSS

I would like the div to be centered horizontally with a fixed position, but it doesn't seem to work in my code. Can someone help me troubleshoot? Check out the demo here. HTML: <div id="fancybox-thumbs" class="bottom" style="width: 675px;"> ...

Like button on Facebook within an unordered list (<ul>)

I'm having a headache with the Facebook button. I'm attempting to include all social buttons in one unordered list with "display: inline;" set on the list item elements. Check out the code below: <ul id="social" class="grid_3 alpha"> & ...

Counting each item with jQuery and assigning them numbers 02, 03, 04, etc., with the exception of the first item which will display as "Up Next

I'm still learning jQuery and here's the code I've put together after researching on stackoverflow and other platforms: var counter = 1; $('.next-page .nav-item').each(function () { if ($(this, ':gt(0)')) { $(this ...

Designing CSS elements that flow from top to bottom, left to right, and extend to the right when overflowing

I'm attempting to create a layout where divs are displayed from top to bottom, but once they reach the bottom of the browser window, any additional divs will overflow to the right. You can take a look at the desired layout here: https://i.stack.imgur. ...

Display images with sequential animation and a delay, combining fade-in and slide-up effects

I am attempting to create a cycling image display with specific effects: There should be a one-second delay before the first image is shown. The first image will appear with a fade-in and slide-up effect. Image #1 will remain visible for 5 seconds before ...

HTML integration of JavaScript not working as expected

My experience with separating files in HTML and JS has been positive - everything works smoothly when I link the JS file to the HTML. However, an issue arises when I decide to include the JS code directly within <script> tags in the HTML itself. The ...

Instructions on calculating the sum of a checkbox value and a textbox value

Here, my goal is to dynamically calculate the total value of selected checkboxes (Checkbox1 and Checkbox3) with the value in TextBox1, and then display the sum in TextBox2 without the need for any button click event. <div> <asp:Tex ...

invoking a function by utilizing nested controllers

Struggling with nested controllers, the main goal of this code is to link data extracted from a .json file to another function or file. .html file: <div ng-app="myApp" ng-controller="GetCtrl" > <li ng-controller="ChannelCtrl" ng-repeat="x in ...

Sign in with AJAX in codeigniter framework

I am currently working on implementing AJAX functionality into my project. I aim to enable user login upon clicking the login button. Below, you will find the relevant code snippets. The view is invoking the login function in my controller. View <form ...

What could be causing the bootstrap 4 col-md-3 block to shrink when using position fixed?

When working with Bootstrap 4, I encountered an issue where changing the block position from relative to fixed using a script caused the block to decrease in size. The script I used includes a .sticky class: .sticky { position: fixed !important; top: ...

Angular Recursive Bootstrap Breadcrumb Guide

I am looking to implement the bootstrap breadcrumb component (https://getbootstrap.com/docs/4.0/components/breadcrumb/) in my project. My goal is to use the breadcrumb to show the entire path to the current directory within a component that resembles a di ...