Having difficulty aligning Bootstrap elements with my custom CSS

My attempt to align my search bar with the "Art Store" text on the same vertical level has been unsuccessful so far.

   <div id="logoRow" >
            <h1>Art Store</h1>
            <form class="searchBar">
               <div class="input-group locationSearch">
                  <input type="text" class="form-control" placeholder="Search" name="search">
                  <div class="input-group-btn">
                     <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
                  </div>
               </div>
            </form>
         </div>

This is how my "Art Store" text and search bar look by default, without any additional CSS style: https://i.sstatic.net/NkyMN.png

However, when I apply custom CSS styles as shown below:

.searchBar {
    width: 250px;
    padding: 10px;
    margin-right: 50px;
}

https://i.sstatic.net/ePQ58.png I intend to have the search bar aligned at the same vertical position as the "Art Store" text on the right side. Unfortunately, using float: right causes the search bar to shift down into the bottom navbar instead of staying at the desired level. See example: https://i.sstatic.net/cQDQR.png This outcome is not what I desire. I'm puzzled by this behavior since it persists even when setting the position property to relative. Any assistance in resolving this issue would be highly appreciated. Here's a bit more code for context (including the bottom navbar):

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Chapter5</title>
      <!-- Custom styles for this template -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
      <link href="assign3.css" rel="stylesheet">
   </head>
   <body>
      <header>
         <div id="topHeaderRow" >
            <nav class="navbar navbar-inverse">
               <div class="container-fluid">
                  <div class="navbar-header">
                     <a class="navbar-brand" href="#">Welcome to Art Store, Login or Create a new Account</a>
                  </div>
                  <ul class="nav navbar-nav moveRight">
                     <li><a href="#">My Account</a></li>
                     <li><a href="#">Wish List</a></li>
                     <li><a href="#">Shopping Cart</a></li>
                     <li><a href="#">Checkout</a></li>
                  </ul>
               </div>
            </nav>
         </div>
         <!-- end topHeaderRow -->
         <div id="logoRow" >
            <h1>Art Store</h1>
            <form class="searchBar">
               <div class="input-group locationSearch">
                  <input type="text" class="form-control" placeholder="Search" name="search">
                  <div class="input-group-btn">
                     <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
                  </div>
               </div>
            </form>
         </div>
         <!-- end logoRow -->
         <div id="mainNavigationRow" >
            <nav class="navbar navbar-default">
               <ul class="nav navbar-nav mynavbar">
                  <li class="active"><a href="#">Home</a></li>
                  <li><a href="#">About Us</a></li>
                  <li><a href="#">Art Works</a></li>
                  <li><a href="#">Artists</a></li>
                  <li class="dropdown">
                     <a class="dropdown-toggle" data-toggle="dropdown" href="#">Specials
                     <span class="caret"></span></a>
                     <ul class="dropdown-menu">
                        <li><a href="#">Special 1</a></li>
                        <li><a href="#">Special 2</a></li>
                     </ul>
                  </li>
               </ul>
         </div>
         </nav>     
         </nav>
         </div>

Answer №1

I've inserted some code into your case

#logoRow {
display:flex;
width:100%
}
#logoRow h1 {
  margin-top:0;
}
#logoRow form.searchBar {
  width:40%;
  display:inline-block;
  margin-left:auto;
 }

I have utilized margin-top:0px to eliminate the margin from bootstrap in the #logoRow
This will result in an output like this

#logoRow {
display:flex;
width:100%
}
#logoRow h1 {
  margin-top:0;
}
#logoRow form.searchBar {
  width:40%;
  display:inline-block;
  margin-left:auto;
 }
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Chapter5</title>
  <!-- Custom styles for this template -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <link href="assign3.css" rel="stylesheet">
</head>

<body>
  <header>
    <div id="topHeaderRow">
      <nav class="navbar navbar-inverse">
        <div class="container-fluid">
          <div class="navbar-header">
            <a class="navbar-brand" href="#">Welcome to Art Store, Login or Create a new Account</a>
          </div>
          <ul class="nav navbar-nav moveRight">
            <li><a href="#">My Account</a></li>
            <li><a href="#">Wish List</a></li>
            <li><a href="#">Shopping Cart</a></li>
            <li><a href="#">Checkout</a></li>
          </ul>
        </div>
      </nav>
    </div>
    <!-- end topHeaderRow -->
    <div id="logoRow">
      <h1>Art Store</h1>
      <form class="searchBar">
        <div class="input-group locationSearch">
          <input type="text" class="form-control" placeholder="Search" name="search">
          <div class="input-group-btn">
            <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
          </div>
        </div>
      </form>
    </div>
    <!-- end logoRow -->
    <div id="mainNavigationRow">
      <nav class="navbar navbar-default">
        <ul class="nav navbar-nav mynavbar">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">About Us</a></li>
          <li><a href="#">Art Works</a></li>
          <li><a href="#">Artists</a></li>
          <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Specials
                     <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Special 1</a></li>
              <li><a href="#">Special 2</a></li>
            </ul>
          </li>
        </ul>
    </div>
    </nav>
    </nav>
    </div>

Answer №2

This is a functional solution

<!DOCTYPE html>
<html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Chapter5</title>
      <!-- Custom styles for this template -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
      <link href="assign3.css" rel="stylesheet">
     <style>
       .searchBar {
        width: 250px;
        padding: 10px;
        margin-left: auto;
    }
     </style>
    </head>
    <body>
        <header>
             <div id="topHeaderRow" >
                <nav class="navbar navbar-inverse">
                   <div class="container-fluid">
                      <div class="navbar-header">
                         <a class="navbar-brand" href="#">Welcome to Art Store, Login or Create a new Account</a>
                      </div>
                      <ul class="nav navbar-nav moveRight">
                         <li><a href="#">My Account</a></li>
                         <li><a href="#">Wish List</a></li>
                         <li><a href="#">Shopping Cart</a></li>
                         <li><a href="#">Checkout</a></li>
                      </ul>
                   </div>
                </nav>
             </div>
             <!-- end topHeaderRow -->
             <div id="logoRow" >
                <h1>Art Store</h1>
                
             </div>
             <!-- end logoRow -->
             <div id="mainNavigationRow" >
                <nav class="navbar navbar-default">
                   <ul class="nav navbar-nav mynavbar">
                      <li class="active"><a href="#">Home</a></li>
                      <li><a href="#">About Us</a></li>
                      <li><a href="#">Art Works</a></li>
                      <li><a href="#">Artists</a></li>
                      <li class="dropdown">
                         <a class="dropdown-toggle" data-toggle="dropdown" href="#">Specials
                         <span class="caret"></span></a>
                         <ul class="dropdown-menu">
                            <li><a href="#">Special 1</a></li>
                            <li><a href="#">Special 2</a></li>
                         </ul>
                      </li>
                   </ul>
                  <form class="searchBar">
                   <div class="input-group locationSearch">
                      <input type="text" class="form-control" placeholder="Search" name="search">
                      <div class="input-group-btn">
                         <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
                      </div>
                   </div>
                </form>
                </nav>
             </div>
        </header>
    </body>
</html>

Answer №3

Hello, I believe using display: flex can help achieve the desired layout. Check out the CSS code below that demonstrates how I tackled this issue. Take a look at this screenshot

#logoRow{
   display: flex;
   align-items: center;
}

#logoRow h1{
   margin: 2rem;
}
 

Answer №4

Here is a tip:

.customSearch {
    position:fixed;
    float:right;
    width: 300px;
    padding: 15px;
    margin-right: 60px;
}

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

In Laravel Blade, the modal content is obstructed by the Modal Backdrop on portrait screen orientation

Within my Laravel Blade, I encounter an issue where a modal pops up in portrait orientation on an iPad Pro, but is obstructed by the backdrop div. The message prompts the user to rotate the screen to landscape mode. However, the modal works perfectly in la ...

Masonry layout organizes images in a vertical stack, with one image per row

After implementing Masonry on my website, I encountered an issue where all the images stack vertically in a single row once the page loads. Instead, I would like them to stack both horizontally and vertically. You can view the problem on My Jsfiddle. This ...

Achieving sliders similar to those in the "level" window of GIMP can be done by customizing the shape of GtkScale in your C program

I have a query regarding the shape of GtkScale. Specifically, I am interested in making my GtkScale resemble the one found in the levels window of Gimp. To clarify: a bar 3 triangles (representing shadows, midtones, and highlights) https://i.stack.imgur ...

What are the best methods for placing content within a box and ensuring it is responsive?

Having trouble solving a simple problem that seems to have an easy solution. The code I'm working on is meant to display multiple bubbles with similar content, but the text gets distorted due to using strange margin values to fit a specific resolution ...

bootstrap used for creating horizontal radio buttons

I'm attempting to horizontally align radio buttons within a form without relying on the Bootstrap library. The following code achieves this: <form id="test_form"> <div class="control-group"> <label for="Q1">First question</ ...

Allow users to zoom in and out on a specific section of the website similar to how it works on Google Maps

I am looking to implement a feature on my website similar to Google Maps. I want the top bar and side bars to remain fixed regardless of scrolling, whether using the normal scroll wheel or CTRL + scroll wheel. However, I would like the central part of the ...

Styling Radio Buttons and Links in Horizontal Layout Using Bootstrap

Encountering an issue in Bootstrap while attempting to incorporate custom radio buttons and a hyperlink in the same row. It seems that either the hyperlink functions OR the data-toggle feature for radio buttons works, but not both simultaneously, especiall ...

A Simple Guide to Mastering the Flexbox Columns Concept

After exploring flexbox for some time and finally grasping its potential, I wanted to share an example showcasing how simple it is to create flexible column layouts without the need for CSS hacks involving excessive margins and paddings. I understand that ...

Assigning alphanumeric characters to the axis for identification purposes

review the code in index.html <!DOCTYPE html> <html> <head> <title>D3 test</title> <style> .grid .tick { stroke: lightgrey; opacity: 0.7; } .grid path { stroke-width: 0; } .ch ...

Is there a different option to use instead of the onChange event for the <select> element in ReactJS?

As I work on developing a Component with numerous <select> elements, the challenge arises when only one option is available and onChange event fails to trigger. Is there an alternative event in ReactJS, such as onSelect, that can be employed for this ...

The autofocus feature does not function properly in an input tag that is not located within a form element

Is there a way to set the autofocus property in an input element that is not part of a form? I have tried adding the "autofocus" attribute to the input tag but it doesn't seem to be working. <div> //I have added the autofocus property her ...

Background above another background, enveloping the surrounding elements

Currently, I am diving into the world of html/css/js/jquery coding, and after days of searching for answers, I am attempting to create a sleek website. My main question is regarding how to achieve the following design: I am struggling to create the "borde ...

Strategies for addressing frontend challenges in Bootstrap 4

Currently, I am enrolled in a program to enhance my knowledge of Angular and have encountered a challenge. My project is utilizing the most recent version of bootstrap, which is bootstrap 4. However, I am facing issues with the main page not functioning co ...

Running a Chrome content script once an AJAX request has been triggered by the <body> element

I am facing a challenge with running the content script before the DOM is fully loaded. To give context, there is an AJAX request within a tag which gets triggered on $(document).ready(). Once this request is completed, my extension code kicks in. To tra ...

What is the most effective way to incorporate the Google Analytics script into a Django project?

Is it recommended to add the Google Analytics script directly in <script> tag and push it to GitHub, or should it be kept secret by adding it to the .env file and called in? When I attempted the second method, it appeared in the source page as is an ...

How can I change the hover color of the navigation bar buttons in the Bootstrap freelancer template?

Having an issue with the hover color of the main navigation button menu while using the official freelancer template: https://github.com/BlackrockDigital/startbootstrap-freelancer The main button is displayed on narrower screens and should have a hover c ...

I am not receiving any response when I enter the IP and port of the browser where nodejs is listening. What could be the issue?

I'm currently exploring the inner workings of a nodejs server and how to configure it to send an HTML page in response to a request. My setup involves a nodejs server with express running on a VPS where I also host a webpage through vesta. I have wri ...

Looking for a personalized grid layout with 3 columns for your thumbnails?

I am trying to make this work and I stumbled upon this website. Instead of having 4 columns, I would like to have 3 columns with the same height. Is there a way to achieve this? This is how it appears on my webpage: x http://imagizer.imageshack.us/v2/15 ...

Personalizing the share button by changing the icon font to an image

I've been working on incorporating this share button into my website.... Although it functions properly as is, I want to switch out the icon font for an image. I attempted to modify certain CSS properties, but encountered some issues. http://jsfidd ...

margin-top: automatic adjustment, with a minimum of 50 pixels

I am trying to add a minimum of 50px margin to the top of my footer tag using CSS, but I haven't been successful with the min() function. I'm not sure if I am overlooking something or if there is another correct approach to achieve this. * { ...