如何在第二部分html CSS的顶部添加部分?

时间:2019-11-14 12:59:41

标签: html css

我想将search-from放在第二部分section seller-listings的顶部

enter image description here

这是我的搜索表,灰色位于顶部:

enter image description here

我尝试将position:absoulte赋予search-block,但看起来像这样

enter image description here

这是我的 HTML代码

完整代码

<body>

    <!-- Navigation -->
    <section>
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <nav class="navbar navbar-expand-lg navigation">
                        <a href="/" class="navbar-brand">
                            <img src="images/site-logo.png">
                        </a>
                        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                          <span class="fas fa-bars"></span>
                        </button>
                        <div class="collapse navbar-collapse" id="navbarNav">
                            <ul class="navbar-nav ml-auto main-nav">
                                <li class="nav-item">
                                    <a class="nav-link" href="#">Buy bitcoins</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" href="#">Sell bitcoins</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" href="#">Post a trade</a>
                                </li>                                                               
                            </ul>
                            <ul class="navbar-nav ml-auto mt-10">
                                <li class="nav-item">
                                    <a class="nav-link login-button" href="#">Log In</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link register-button" href="#">Register</a>
                                </li>
                            </ul>                           
                        </div>
                    </nav>
                </div>
            </div>
        </div>
    </section>

    <!-- Hero -->
    <section class="hero text-center">
        <div class="container">
            <div class="content-block">
                <h1>Buy and sell bitcoins near you</h1>
                <h2>Instant. Secure. Private.</h2>
                <h4 class="mb-4">Trade bitcoins in <span>7824 cities</span> and <span>248 countries</span> including <span>Pakistan.</span></h4>
                <a href="/" class="btn btn-primary btn-lg">Sign up free</a>
            </div>  

            <!-- Search -->
            <div class="search-block">
                <div class="search-form">
                    <form>
                        <div class="inner-form">    
                            <div class="input-field first-wrap">
                                <input class="form-control mb-2 mr-sm-2 mb-sm-0" id="search" type="text" placeholder="Amount">
                            </div>
                            <div class="input-field second-wrap">
                                <select class="form-control mb-2 mr-sm-2 mb-sm-0">
                                    <option>PKR</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                </select>
                            </div>
                            <div class="input-field third-wrap">
                                <select class="form-control mb-2 mr-sm-2 mb-sm-0">
                                    <option>Pakistan</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                </select>                   
                            </div>
                            <div class="input-field fouth-wrap">
                                <select class="form-control mb-2 mr-sm-2 mb-sm-0">
                                    <option>All online offers</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                    <option>Example</option>
                                </select>                   
                            </div>
                            <div class="input-field fifth-wrap">
                                <button class="btn-search" type="button">Search</button>
                            </div>  
                        </div>
                    </form> 
                </div>
            </div>          
        </div>  
    </section>

    <section class="seller-listings section bg-gray">
        <div class="container">
            <div class="row">
                <table class="table">
                  <thead class="black white-text">
                    <tr>
                      <th scope="col">#</th>
                      <th scope="col">First</th>
                      <th scope="col">Last</th>
                      <th scope="col">Handle</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <th scope="row">1</th>
                      <td>Mark</td>
                      <td>Otto</td>
                      <td>@mdo</td>
                    </tr>
                    <tr>
                      <th scope="row">2</th>
                      <td>Jacob</td>
                      <td>Thornton</td>
                      <td>@fat</td>
                    </tr>
                    <tr>
                      <th scope="row">3</th>
                      <td>Larry</td>
                      <td>the Bird</td>
                      <td>@twitter</td>
                    </tr>
                  </tbody>
                </table>
            </div>
        </div>
    </section>
</body>
  

修改

我通过给search-block position: relative解决了问题。

谢谢!

2 个答案:

答案 0 :(得分:1)

如果有人遇到同样的问题。您可以通过添加postion:realtive;

来解决此问题。
.search-block {
  position: relative;
}

它将出现在顶部:

enter image description here

谢谢

答案 1 :(得分:0)

尝试以下代码。我添加了引导程序类。您可以相应地编辑表的CSS和内容。

<section class="hero text-center">
  <div class="container">
    <div class="content-block">
      <h1>Buy and sell bitcoins near you</h1>
      <h2>Instant. Secure. Private.</h2>
      <h4 class="mb-4">
        Trade bitcoins in <span>7824 cities</span> and
        <span>248 countries</span> including <span>Pakistan.</span>
      </h4>
      <a href="/" class="btn btn-primary btn-lg">Sign up free</a>
    </div>

    <!-- Search -->
    <div class="search-block">
      <div class="search-form">
        <form>
          <div class="inner-form row">
            <div class="input-field first-wrap col">
              <input
                class="form-control mb-2 mr-sm-2 mb-sm-0"
                id="search"
                type="text"
                placeholder="Amount"
              />
            </div>
            <div class="input-field second-wrap col">
              <select class="form-control mb-2 mr-sm-2 mb-sm-0">
                <option>PKR</option>
                <option>Example</option>
                <option>Example</option>
                <option>Example</option>
                <option>Example</option>
              </select>
            </div>
            <div class="input-field third-wrap col">
              <select class="form-control mb-2 mr-sm-2 mb-sm-0">
                <option>Pakistan</option>
                <option>Example</option>
                <option>Example</option>
                <option>Example</option>
                <option>Example</option>
              </select>
            </div>
            <div class="input-field fouth-wrap col">
              <select class="form-control mb-2 mr-sm-2 mb-sm-0">
                <option>All online offers</option>
                <option>Example</option>
                <option>Example</option>
                <option>Example</option>
                <option>Example</option>
              </select>
            </div>

            <div class="input-field fifth-wrap col">
              <button class="btn-search" type="button">Search</button>
            </div>
          </div>

          </table>
        </form>
        <table class="row">
          <tr class="col-3">
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
          </tr>
          <tr class="col-3">
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
          </tr>
          <tr class="col-3">
            <td>Jill</td>
            <td>Smith</td>
            <td>50</td>
          </tr>
          <tr class="col-3">
            <td>Eve</td>
            <td>Jackson</td>
            <td>94</td>
          </tr>
      </div>
    </div>
  </div>
</section>