Home > Mobile >  How to move the Header and search bar to the center of the screen?
How to move the Header and search bar to the center of the screen?

Time:09-27

I'm trying to create a website using bootstrap where the title and the search bar is at the center of the screen. I tried adding the my-auto, but that doesn't do anything. It shouldn't be difficult, but I can't make it work. Any ideas?enter image description here

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="stylesheet.css" rel="stylesheet">
    
  </head>
  <body>
   <div class="container" style="margin-top: 8%;">
       <div class="col-md-6 col-md-offset-3">     
        <div class="row">
              <div id="logo" class="text-center">

              <h1>Movie</h1>
       
              </div>
           <form role="form" id="form-buscar">
             <div class="form-group">
               <div class="input-group">
                 <input id="1" class="form-control" type="text" name="search" placeholder="Search..." required/>
                 <span class="input-group-btn">
                   <button type="button" class="btn btn-outline-primary">search</button>
                   <i class="glyphicon glyphicon-search" aria-hidden="true"></i>
                 </span>
               </div>
             </div>
          </form>
         </div>            
       </div>
       <p>movie!</p>
    </div>
      
      
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

CodePudding user response:

What youre looking for is flex box, Try adding to the <div class="row"> the style of

display: flex;
flex-direction: column;
align-items: center;

CodePudding user response:

You can use display:flex; property to center the content.

.container{
display: flex;
flex-direction:column;
align-items: center;
justify-content: center;
text-align: center;
}
<div class="container" style="margin-top: 8%;">
       <div class="col-md-6 col-md-offset-3">     
        <div class="row">
              <div id="logo" class="text-center">

              <h1>Movie</h1>
       
              </div>
           <form role="form" id="form-buscar">
             <div class="form-group">
               <div class="input-group">
                 <input id="1" class="form-control" type="text" name="search" placeholder="Search..." required/>
                 <span class="input-group-btn">
                   <button type="button" class="btn btn-outline-primary">search</button>
                   <i class="glyphicon glyphicon-search" aria-hidden="true"></i>
                 </span>
               </div>
             </div>
          </form>
         </div>            
       </div>
       <p>movie!</p>
    </div>

  • Related