Closed. This question needs to be more focused。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
                        
                        2年前关闭。
                                                                                            
                
        
我试图建立一个布局来显示一个梦幻联赛球队,最初我是在表格视图中以球员姓名命名的,但是我想将其更改为看上去有点像球队阵容的图形表示。

尽管我可以按照自己的要求获得类似的经验,但我对编写CSS的经验不是很丰富,但是该网站是用PHP编写的,因此我认为我将不得不根据位置和位置上的玩家人数来选择几种样式。然后使用php动态地交换它们,除非有更好的方法。

我的问题是我该如何像在守门员位置中那样使位置居中并使其内联,我正在使用float: left使位置内联但却无法使其居中。



.section-heading{
    border-bottom: 1px solid #c8c8c8;
}
.section-heading-text{
    text-align: center;
}

.section-content{
    /* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#009b29+0,009b29+20,61bf7a+20,61bf7a+40,009b29+40,009b29+60,61bf7a+60,61bf7a+80,009b29+80 */
    background: #009b29; /* Old browsers */
    background: -moz-linear-gradient(left,  #009b29 0%, #009b29 20%, #61bf7a 20%, #61bf7a 40%, #009b29 40%, #009b29 60%, #61bf7a 60%, #61bf7a 80%, #009b29 80%); /* FF3.6-15 */
    background: -webkit-linear-gradient(left,  #009b29 0%,#009b29 20%,#61bf7a 20%,#61bf7a 40%,#009b29 40%,#009b29 60%,#61bf7a 60%,#61bf7a 80%,#009b29 80%); /* Chrome10-25,Safari5.1-6 */
    background: linear-gradient(to right,  #009b29 0%,#009b29 20%,#61bf7a 20%,#61bf7a 40%,#009b29 40%,#009b29 60%,#61bf7a 60%,#61bf7a 80%,#009b29 80%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#009b29', endColorstr='#009b29',GradientType=1 ); /* IE6-9 */

    padding-left: 30px;
    padding-right: 30px;
    height: 300px;
}
.gk{
    text-align: center;
}
.kit-image{
    height: 40px;
    width: 35px;
}
.defender{
    padding-left: 30px;
    padding-right: 30px;
    padding-top: 10px;
    float: left;
    text-align: center;
}

<div class="section-box">
  <div class="section-heading">
    <h2 class="section-heading-text">Team Name</h2>
  </div>
  <div class="section-content">
    <div class="row">
      <div class="col-sm-12">
        <div class="gk">
          <img src="www.gamingcentury.com/img/keeperKit.png" class="kit-image">
          <div>
            Goal keeper
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="defender">
        <img src="www.gamingcentury.com/img/outKit.png" class="kit-image">
        <div>
          Defender
        </div>
      </div>
      <div class="defender">
        <img src="www.gamingcentury.com/img/outKit.png" class="kit-image">
        <div>
          Defender
        </div>
      </div>
      <div class="defender">
        <img src="www.gamingcentury.com/img/outKit.png" class="kit-image">
        <div>
          Defender
        </div>
      </div>
      <div class="defender">
        <img src="www.gamingcentury.com/img/outKit.png" class="kit-image">
        <div>
          Defender
        </div>
      </div>
    </div>
  </div>

最佳答案

这是我的解决方案建议,它提供了以col为中心和以行为中心的css类的创建,并按如下所示应用它们:

CSS:

.row-centered {
   text-align:center;
}


.col-centered {
   display:inline-block;
   float:none;
}


的HTML:

    <div class="section-box">
  <div class="section-heading">
    <h2 class="section-heading-text">Team Name</h2>
  </div>
  <div class="section-content">
    <div class="row">
      <div class="col-sm-12">
        <div class="gk">
          <img src="www.gamingcentury.com/img/keeperKit.png" class="kit-image">
          <div>
            Goal keeper
          </div>
        </div>
      </div>
    </div>
    <div class="row row-centered">
      <div class="defender col-centered">
        <img src="www.gamingcentury.com/img/outKit.png" class="kit-image">
        <div>
          Defender
        </div>
      </div>
      <div class="defender col-centered">
        <img src="www.gamingcentury.com/img/outKit.png" class="kit-image">
        <div>
          Defender
        </div>
      </div>
      <div class="defender col-centered">
        <img src="www.gamingcentury.com/img/outKit.png" class="kit-image">
        <div>
          Defender
        </div>
      </div>
      <div class="defender col-centered">
        <img src="www.gamingcentury.com/img/outKit.png" class="kit-image">
        <div>
          Defender
        </div>
      </div>
    </div>
  </div>

关于php - Bootstrap足球队的动态布局,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42188058/

10-10 13:58