如何使用Boostrap以水平方式显示游戏列表?

时间:2019-01-17 08:14:10

标签: html css

我是前端开发人员中的新手。.以垂直方式显示的游戏列表我还添加了boostrap链接并添加了一些类,但仍以垂直方式显示,如下所示: enter image description here

<html>
<head><title>Game Catalog</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"/>
</head>
<body>

<div class="container">
    <div class="col-12">    
        <div class="col-3">
            <form id="game_load0" method="post" action="play.php">
                <input type="hidden" name="url" value="">
            </form>
            <a href="#" target="_blank" onclick="document.forms['game_load0'].submit();" title="Biker Lane" style="padding-right: 12px;">
            <img src="http://cdn.marketjs.net/games/biker-lane/localization/en/media/graphics/promo/icons/128x128.png" style="width: 200px; height: 200px;"/></a>
        </div>
        <div class="col-3">
            <form id="game_load1" method="post" action="play.php">
                <input type="hidden" name="url" value="">
            </form>
            <a href="#" target="_blank" onclick="document.forms['game_load1'].submit();" title="Wild West Shootout" style="padding-right: 12px;">
            <img src="http://cdn.marketjs.net/games/wild-west-shootout/localization/en/media/graphics/promo/icons/128x128.png" style="width: 200px; height: 200px;"/></a>
        </div>
      </div>
   </div>
  </body>
</html>

我希望使用boostrap以列方式显示游戏列表

检查此链接https://codepen.io/anon/pen/BveNJj

3 个答案:

答案 0 :(得分:1)

在开始定义列之前,需要添加行作为父元素。在此处了解更多信息:Bootstrap Docs 示例:

<div class="row">
    <div class="col-md-3">
        Content Here
    </div>
</div>

我在这里固定了您的代码: https://codepen.io/anon/pen/WLBbMV

答案 1 :(得分:0)

您至少检查了Twitter Bootstrap Doc吗?在开始使用Bootstrap之前,您应该阅读以下页面:https://getbootstrap.com/docs/4.0/layout/grid/

.row {
  background: #f8f9fa;
  margin-top: 10px;
}

.col {
  border: solid 1px #6c757d;
  padding: 10px;
}
<div class="container">
  <div class="row">
    <div class="col">
      INSERT FORM OR DIV FROM GAME HERE
    </div>
  </div>
   <div class="row">
    <div class="col">
      INSERT FORM OR DIV FROM GAME HERE
    </div>
  </div>
   <div class="row">
    <div class="col">
      INSERT FORM OR DIV FROM GAME HERE
    </div>
  </div> 
</div>

答案 2 :(得分:0)

Demo image在使用任何 col类之前,您需要添加一个类,即行类

<div>
    <div class="row">
     //write col classes here
     </div>
</div>

行类用于在一行中划分列。因此默认情况下,它以水平方式设置所有内容。有关更多详细信息,请参阅此文档。Bootsrap grid structure

这是您要查找的确切代码。

    <html>
<head><title>Game Catalog</title>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>

<div class="container">
    <div class="row">    
        <div class="col-md-6">
            <form id="game_load0" method="post" action="play.php">
                <input type="hidden" name="url" value="">
            </form>
            <a href="#" target="_blank" onclick="document.forms['game_load0'].submit();" title="Biker Lane" style="padding-right: 8px;">
            <img src="http://cdn.marketjs.net/games/biker-lane/localization/en/media/graphics/promo/icons/128x128.png"/></a>
        </div>
        <div class="col-md-6">
            <form id="game_load1" method="post" action="play.php">
                <input type="hidden" name="url" value="">
            </form>
            <a href="#" target="_blank" onclick="document.forms['game_load1'].submit();" title="Wild West Shootout" style="padding-right: 8px;">
            <img src="http://cdn.marketjs.net/games/wild-west-shootout/localization/en/media/graphics/promo/icons/128x128.png" /></a>
        </div>
      </div>
   </div>
  </body>
</html>

使用此代码,可以将2张图像排成一行。您可以根据需要直接更改填充。