Organize the search bar and button over a background image using Bootstrap and CSS styling

I am facing a challenge in positioning the search bar on a background image, as well as placing a button at the bottom and center of the image. After that, I plan to include containers.

My Goal

https://i.sstatic.net/ZfYQj.png

However, I am struggling and feeling confused about the positioning. Additionally, the glyphicon is not working as expected.

https://i.sstatic.net/Dlfw3.png

Here is my Code

<style>
  .card {
    border: 0px solid;
  }
  
  .drop-shadow {
    -webkit-box-shadow: 0 0 2px 2px rgba(0, 0, 0, .5);
    box-shadow: 0 0 10px 1px rgb(211, 211, 211, 0.8);
    border-radius: 0px;
  }
  
  .container-fluid {
    width: auto
  }
  
  .container-fluid.drop-shadow {
    margin-top: 2%;
    margin-left: 5%;
    margin-right: 5%
  }
  
  .img-fluid {
    height: 200px;
  }
  
  #child {
    width: 100%;
    height: 20px;
    margin: auto;
    text-align: center;
    bottom: 0px;
    position: absolute;
  }
  
  .btn-checkin {
    display: inline-block;
    text-align: center;
    white-space: nowrap;
    color: #fff;
    border-color: #EC008c;
    text-transform: uppercase;
    background-color: #EC008c;
    font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
    padding: 0.375rem .75rem;
    font-size: 13px;
    border-radius: .25rem;
  }
</style>

</head>

<body id="page-top">

  <div class="card">

    <img class="img-fluid" src="img/1847p.png" alt="Card image cap">

    <div class="col-md-5">
      <div class="form-group">
        <div class="icon-addon addon-lg">
          <input type="text" placeholder="Search Class" class="form-control" style="height:30px;position:absolute" id="email">
          <label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
        </div>
      </div>
    </div>

    <div id="child">

      <button class="btn-checkin">Check in</button>

      <div class="container-fluid drop-shadow">
        <div class="row">
          frsjafksdalkdfsa
        </div>
        fsdfdasasd
      </div>

    </div>
  </div>

Challenges to Address:

  • Position the search bar on the background image
  • Ensure the background image always stays on top of the screen with full width and responsive height, instead of hard coding it to 200px
  • Troubleshoot the glyphicon display issue
  • Place the button at the bottom and center of the image

Answer №1

  1. To position the form on top of the image, use margin-top with a negative value.
  2. The Glyphicons are working perfectly here.

* {
  box-sizing: border-box;
}

img {
  width: 100%;
}

div#form-box {
  margin-top: -95px;
  
  text-align: center;
}

div#input-group {
  width: 80%;
  
  margin: 0 auto 20px;
  
  position: relative;

  background-color: #fff;
  
  border: none;
  border-radius: 5px;
}


input#email, label[for="email"] {
  display:inline-block;
  vertical-align: middle;
}

input#email {
  width: calc(100% - 40px);
  
  padding: 10px;
  
  border: none;
}

label[for="email"] {
  width: 40px;
  
  line-height: 40px;
}

button#btn-checkin {
  display: inline-block;
  
  padding: 6px 10px;
  
  border: none;
  border-radius: 5px;
  background-color: #EC008c;
  color: #fff;
  
  text-align: center;
  text-transform: uppercase;
}
<head>
  <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" />
</head>

<img src="http://wonderfulengineering.com/wp-content/uploads/2016/01/Desktop-Wallpaper-4.jpg" />

<div id="form-box">
  <form>
    <div id="input-group">
    <label for="email" class="glyphicon glyphicon-search"></label><!--
      --><input type="text" placeholder="Search Class" id="email">
    </div>
    <br/>
    <button id="btn-checkin">Check-in</button>
  </form>
</div>

<br/>
<br/>
<br/>

Answer №2

    .card{
            border:0px solid;
            position:relative;
            height:200px;
            background:url('https://preview.ibb.co/fex0wK/1847p.png') no-repeat top center;
            background-size:cover;
        }
        
        .card img {
          width:100%;
        }
        
        .search-box {
          position : absolute;
          display:inline-block;
          bottom:-30px;
          left:0;
          right:0;
          padding:15px;
          text-align:center;
        }
    
        .drop-shadow {
            -webkit-box-shadow: 0 0 2px 2px rgba(0, 0, 0, .5);
            box-shadow: 0 0 10px 1px rgb(211, 211, 211, 0.8);
            border-radius:0px;
        }
        .container-fluid{
            width:auto
        }
        .container-fluid.drop-shadow {
            margin-top:2%;
            margin-left:5%;
            margin-right:5%
    
        }
    
        .img-fluid {
            height: 200px;
        }
    
        #child{
                width:100%;
                height: 20px;
                margin: auto;
                text-align: center;
                margin-top: 40px;
        }
        .form-group {
          width:100%;
          margin-bottom:10px;
        }
        .btn-checkin{
            display: inline-block;
            text-align: center;
            white-space: nowrap;
            color: #fff;
            border-color: #EC008c;
            text-transform: uppercase;
            background-color: #EC008c;
            font-family:'Open Sans','Helvetica Neue',Arial,sans-serif;
            padding: 0.375rem .75rem;
            font-size: 13px;
            border-radius: .25rem;
    }
    
    .icon-addon {
      position:relative;
    }
    .icon-addon label {
        position: absolute;
        left: 2px;
        top: 2px;
        padding: 8px;
        font-size: 20px;
    }
    .icon-addon input {
        height:40px;
        padding-left:35px;
    }
     
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    
    <body id="page-top">
    
    <div class="card" >
        <!-- <img class="img-fluid" src="img/1847p.png" alt="Card image cap"> -->
        <div class="search-box">
            <div class="form-group">
                <div class="icon-addon addon-lg">
                    <input type="text" placeholder="Search Class" class="form-control" id="email">
                    <label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
                </div>
            </div>
            <button class="btn-checkin">Check in</button>
        </div>
    </div>
    <div id="child">
      <div class="container-fluid drop-shadow">
        <div class="row">
          frsjafksdalkdfsa
        </div>
        fsdfdasasd
      </div>
    </div> 

Give this code a try. Feel free to reach out if you need further assistance.

Answer №3

So you're looking to place the search bar within an image.

Start by creating a div with the image set as the background

   background: image_source;
   background-size: contain;
   position: relative; //this is necessary
   width: 100%;
   height: 100px; //adjust as needed

Next, style the search bar with CSS

   position: absolute;

Use properties like top, left, etc. to position the search bar accordingly

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

The Bootstrap select feature does not override the original dropdown menu; instead, it adds its own functionality alongside it

I have implemented a select combo using this library. After adding the necessary CSS and JS files, I encountered the following result. Here is what I have attempted so far: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.mi ...

Choosing only those elements that are not children of parents with a specific class by utilizing the `.not()` method

I am attempting to target all elements having the class .select that are nested somewhere within the DOM tree. The only condition is that these elements should not have any ancestors with the class .forbidden. This means it will not detect any elements ...

Rebel Spirit on a Wordpress Platform

I've encountered a strange issue on my Wordpress blog. For some reason, the code "&nbsp" is being inserted right after the opening <body> tag. I have checked the header.php file and there is no instance of this code present there. It's ...

Concealing and revealing information with jQuery and AJAX

Need help hiding a Message and displaying an alert message after 5 seconds, but it's not working. What I want is for the Message to be hidden and show an alert message 5 seconds after clicking submit. <script> $(document).ready(function () { ...

Is there a way to eliminate the CSS width and height properties and instead establish a custom max-width for an image tag?

Currently, I have incorporated my theme's CSS file into my application and it contains the following code: .status .who img { float: left; height: 40px; margin-right: 10px; width: 40px; } However, I want it to appear like this: .status .who ...

Steps to eliminate validation following the clearing of input fields

This is the code I've written for live validation using AJAX in an input field. My issue is that I want the validation to be removed if all inputs are deleted. <script type="text/javascript"> $(document).ready(function(){ ...

Having trouble with Python Selenium CSS Selector? If your element is not visible, it

My goal is to search for all hyperlinks on a webpage that contain an XML download link and download them in a continuous loop. When I click on these hyperlinks, a form pops up that needs to be completed before I can proceed with the download. However, I ...

Eliminate any empty spaces between the HTML tags

Is there a way to remove spaces between characters inside HTML tags? For example <option value="0" title="Advertising / Promotional Charges">Advertising / Promotional Charges</option> I tried using this code .replace(/\>\s+&bs ...

Steps for executing a function when a directory is clicked

Currently, I am working on creating a file browser and facing some issues with calling a function when the user clicks on a directory. Initially, I tried using onClick inside an href in the class part (right before FUNCTION folderSize), intending to open ...

Is there a way to position headline text behind another headline? Take a look at the image provided for reference

I need help creating headline text with a background image similar to the example below. I tried using relative positioning on the first heading, but I can't seem to get it to work correctly. If anyone can provide me with the code to achieve this ef ...

Dynamically getting HTML and appending it to the body in AngularJS with MVC, allows for seamless binding to a

As someone transitioning from a jQuery background to learning AngularJS, I am facing challenges with what should be simple tasks. The particular issue I am struggling with involves dynamically adding HTML and binding it to a controller in a way that suits ...

AngularJS ng-repeat nested loop allows you to iterate through an array

I am currently working with the following JSON data: { "ListNhomThanhTra": [ { "ListKeHoachThanhTra": [ { "ListDoiTuong": [ { "MA_DV_DUOC_TT": "DT01", ...

Conditionals in Angular 2 using Sass

Looking to apply this style with Sass or CSS: IF :host.form-control MATCHES .ng-valid[required] OR .ng-valid.required THEN :host ::ng-deep input.form-control = border-left: 5px solid #42A948; Appreciate the help! ...

jQuery SlideDown Navigation

Is there a way to implement jQuery code that will display dropdown menu options when the Trials link is clicked? Update: jQuery(document).ready(function () { $("a[href='http://sheep.local/cms/trials']").click(function(e){ e.prevent ...

Tips for properly aligning an image within an owl carousel

Currently, I am attempting to center a small image within the owl carousel. While I have managed to center it when it's active and in the center, I'm encountering issues when the item no longer carries the "center" class. You can access Owlcarou ...

Flexbox ancestor causing Bootstrap 5 Carousel width to double

A peculiar issue arises with the Bootstrap 5 Carousel placed inside a Flexbox where it unexpectedly expands in width (pushing other flex-items aside) when transitioning between images. This behavior persists even when the immediate container is set to disp ...

Struggle for dominance between Bootstrap carousel and Flexslider

Issue with Bootstrap carousel and Flex-slider. When both included, the flex slider does not work properly if I remove bootstrap.js. However, without bootstrap.js, the flex slider works but the carousel malfunctions. Code Snippet: <div class="carousel- ...

Anchor tag remains in fixed location in HTML

Here's a link that I need help with: <a id="readmore" href="#">READ MORE</a> Currently, when the user clicks on this hyperlink, I am using Jquery to toggle the content below it to show/hide the content. However, I have encountered an ...

Looking to position the Secondary Navigation Bar on squarespace at the bottom of the page, distinct from the primary Navigation Bar

When SALES PAGE becomes the secondary navigation option Instructions for positioning style to Bottom Center I am attempting to place it at the bottom of the navigation bar. Can you provide me with the necessary code or styles in squarespace? When I choose ...

Show data in a popup using jQuery DataTables and loading content asynchronously via Ajax

I am attempting to display a list in a popup based on an Ajax request. Prior to the Ajax call, the list is contained within the popup. However, after the Ajax request, the list remains on the page instead of inside the popup, and the old list still appears ...