html - vertically centering search box in bootstrap -
backgroud:: having though problem vertically aligning search box , kind of tough nut crack , have been @ few hours , html markup clean , have @ ::
problem:: have been using display:table , display:table-cell properties search box align vertically, have @ markup :
<header> <img src="http://www.freestockphotos.name/wallpaper-original/wallpapers/download-images-of-gentle-dogs-6866.jpg" alt="image of laminates"> <div class="location-search-container"> <div class="input-group custom-search-form"> <input type="text" class="form-control"> <span class="input-group-btn"> <button class="btn btn-default" type="button"> <span class="glyphicon glyphicon-search"></span> </button> </span> </div><!-- /input-group --> </div> </header> note header position:relative, img display:block , location-search-container difficulty lies , positioned absolutly , has following css applied ::
.location-search-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: table; height: 100%; } theoretically search box should positioned in middle , not , see result in fiddle ::
now , little tweak , lets remove image element , add following additional properties header element ::
header { position: relative; /*add below 2 properties*/ height: 300px; background: yellow; } now see how search box centered (fiddle). relatively pretty new css , 1 though nut crack . can tell me missing ?
i know going take effort , thank time , patience.
alex-z.
you can't combine position: absolute , display: table , results you're expecting. instead, set 50% top position , negative top margin on search box equal half height:
.location-search-container { position: absolute; top: 0; left: 0; right: 0; bottom: 0; } .input-group { position: absolute; top: 50%; margin-top: -17px; }
Comments
Post a Comment