【问题标题】:div positions are not being responsive cssdiv位置没有响应css
【发布时间】:2017-11-06 14:44:24
【问题描述】:

我正在尝试实现一个单页应用程序,我希望 div 在其中一个显示在另一个之下。但是在将视口调整为各种屏幕尺寸时,定位会重叠并在两者之间留下额外的空间。我有 codepen 示例可以更好地解释问题。

https://codepen.io/SaloniDesai/pen/zPBZJr

如何使每个屏幕尺寸的 div 看起来都一样?我是否需要改变我创建页面布局的方式?

<div id="headliner" class="jumbotron text-center">
          <h1>SearchGIFY app</h1>
          <p>search for any GIF you want!</p> 
        </div>
        <div id="search">
            <form>
                <input type="search" ng-model="vm.search.gif" value="" placeholder="type what you're looking for" />
                <button type="submit" class="btn btn-primary" ng-click="vm.performSearch()">Search</button>
            </form>
        </div>
        <div class="row">
            <div class="card">
                <img ng-repeat="g in vm.giphies" ng-src="{{g.images.original.url}}" height="{{g.images.fixed_height}}" title="{{g.title}}">
            </div>
        </div>
        <div class="jumbotron text-center" id="trendingBar">
            <h3>Trending gifs</h3>
            <div class="row"> 
                <div class="thumbnail">
                    <img ng-repeat="trending in vm.trendingGifs" ng-src="{{trending.images.original.url}}" height="{{trending.images.fixed_height.height}}" title="{{trending.title}}">
              </div>
            </div>
            </div>

【问题讨论】:

    标签: html css angularjs twitter-bootstrap


    【解决方案1】:

    首先,您的引导结构不好,没有容器,也没有行或列。 试试这个:

    <div class="container-fluid">
      <div class="row">
        <div id="headliner col-md-12" class="jumbotron text-center">
          <h1>SearchGIFY app</h1>
          <p>search for any GIF you want!</p>
        </div>
      </div>
      <div class="row">
        <div id="search">
          <div class="col-md-12">
            <form class="form-inline text-center col-md-6 col-md-offset-3">
              <div class="form-group">
                <input class="form-control" type="search" ng-model="vm.search.gif" value=""
                       placeholder="type what you're looking for"/>
              </div>
              <button type="submit" class="btn btn-primary" ng-click="vm.performSearch()">Search</button>
            </form>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <div class="card">
          <img ng-repeat="g in vm.giphies" ng-src="{{g.images.original.url}}" height="{{g.images.fixed_height}}"
               title="{{g.title}}">
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <div class="jumbotron text-center" id="trendingBar">
          <h3>Trending gifs</h3>
          <div class="thumbnail">
            <img ng-repeat="trending in vm.trendingGifs" ng-src="{{trending.images.original.url}}"
                 height="{{trending.images.fixed_height.height}}" title="{{trending.title}}">
          </div>
        </div>
      </div>
    </div>
    

    其次,您添加了很多具有 % 高度和宽度的绝对类。如果您使用引导程序,则不必这样做,所有响应式内容都由带有 col 类的引导程序网格处理。快速查看网格引导文档:https://getbootstrap.com/docs/3.3/css/#grid

    这里的 codepen 通过一些修改响应式地工作:https://codepen.io/anon/pen/MOemgw ;)

    【讨论】:

    • 谢谢,我会试试的!如果我不希望每行之间有空格怎么办?
    • .jumbotron 类有一个 margin-bottom: 30px,直接覆盖它
    猜你喜欢
    • 2019-11-11
    • 2016-01-12
    • 2013-12-16
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    相关资源
    最近更新 更多