jquery - 如何将搜索框放在轮播的顶部?

标签 jquery css html twitter-bootstrap carousel

我想做类似 airbnb 的东西

这是我使用 Twitter Bootstrap 的轮播代码。

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
             <!-- Indicators -->
    <ol class="carousel-indicators">
         <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
         <li data-target="#carousel-example-generic" data-slide-to="1"></li>
         <li data-target="#carousel-example-generic" data-slide-to="2"></li>
    </ol>


     <!-- Wrapper for slides -->
    <div class="carousel-inner">
        <div class="item active">
          <img src="rio.jpg" alt="">
        </div>
        <div class="item">
          <img src="rio.jpg" alt="">
        </div>
        <div class="item">
          <img src="rio.jpg" alt="">
        </div>  
    </div>
    <!-- Controls -->
   <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
       <span class="glyphicon glyphicon-chevron-left"></span>
   </a>
   <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
       <span class="glyphicon glyphicon-chevron-right"></span>
   </a>
</div>

这是我创建的表单布局。

    <div class="form-group">    
        <div class="container">
            <div class="row">
            <div class="col-md-6">
                <input type="text" class="form-control input-lg" placeholder="Where do you wanna go?">  
            </div>
            <div class="col-md-2">
                <input type="date" class="form-control input-lg" name="start" placeholder="Check In">   
            </div>
            <div class="col-md-2">
                <input type="date" class="form-control input-lg" name="end" placeholder="Check Out">            
            </div>
            <div class="col-md-2">
                <a class="btn btn-lg btn-success" href="#" role="button">GO</a>
            </div>
            </div>
        </div>
    </div>

这是我尝试过的。

.form-group{
   margin-top: -250px;
}

但是没有用。请帮助我。

最佳答案

将“form-group”div 移动到 carousel div 的顶部。像这样:

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <div class="form-group">    
    ....
    </div>
    other carousel html here...
</div>

然后添加这个CSS:

div#carousel-example-generic {
    position:relative;
}

div.form-group {
    position:absolute;
    z-index:9999999;
    top:20px; /* change to whatever you want */
    left:10px; /* change to whatever you want */
    right:auto; /* change to whatever you want */
    bottom:auto; /* change to whatever you want */
}

这将适用于所有浏览器 (IE6+)。

关于jquery - 如何将搜索框放在轮播的顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22719409/

相关文章:

html - 我在 HTML 和 CSS 上更改图像大小时遇到​​问题

html - 为什么 z-index 不起作用?

javascript - 在Javascript中,这个语法是什么意思?

javascript - 保持div的纵横比

html - 有没有办法在加载器上方 float 按钮和文本?

javascript - 为什么这个 .click() 不像 .hover() 那样工作?

jquery - 触发 mousedown 并在事件中包含 e.which

ajax - 需要帮助使用 jQuery AJAX 将复杂对象传递到 ServiceStack

javascript - 如何从服务器注入(inject) HTML?

javascript - 使用 video.js 和 BigVideo 时无意中显示时间戳