2016-09-28 56 views
0

我有這個列表有兩個產品作爲例子。這個問題可能有多種產品,但現在只有兩種產品。如何水平列出產品?

.horizontal { 
 
    display: inline; 
 
    float:left; 
 
} 
 
.product{ 
 
    display: block; 
 
    height: 320px; 
 
    border: 1px solid #DDDDDD; 
 
    border-bottom: 1px solid #DDDDDD; 
 
    text-align: center; 
 
    padding: 10px 5px; 
 
} 
 
.image{ 
 
    display: block; 
 
    overflow: hidden; 
 
    position: relative; 
 
    text-align: center; 
 
    width: 100%; 
 
    max-height: 180px; 
 
    height: 200px; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    padding-left:.45cm; 
 
}
<ul class="horizontalul"> 
 
    <li class="horizontal" style="display: inline;"> 
 
    <div class="product"> 
 
     <div class="image"> 
 
     <img class="img-responsive" src="http://www.shingpoint.com.pk/Images/Thumbnails/pc-a1-470-59100-080316082835.jpg" /> 
 
     </div> 
 
     <div class="description"> 
 
     <h4 class="productname">ASUS VivoMini PC - UN65H-M030M</h4> 
 
     </div> 
 
     <div class="price"> 
 
     <span>Rs. 37,900</span> 
 
     <input type="button" class="btn btn-primary btn-sm" value="Details" /> 
 
     </div> 
 
    </div> 
 
    </li> 
 
    <li class="horizontal" style="display: inline;"> 
 
    <div class="product"> 
 
     <div class="image"> 
 
     <img class="img-responsive" src="http://www.shingpoint.com.pk/Images/Thumbnails/pc-a1-470-59100-080316082835.jpg" /> 
 
     </div> 
 
     <div class="description"> 
 
     <h4 class="productname">ASUS VivoMini PC - UN65H-M030M</h4> 
 
     </div> 
 
     <div class="price"> 
 
     <span>Rs. 37,900</span> 
 
     <input type="button" class="btn btn-primary btn-sm" value="Details" /> 
 
     </div> 
 
    </div> 
 
    </li> 
 
</ul>

我已經設置了horizontal類顯示爲內聯,但它似乎不喜歡工作,我想它的工作。我要水平對齊的項目。我怎樣才能讓它們水平對齊?

+1

剛剛成立'''ul''''''顯示:彎曲;''' – aavrug

回答

0

只需添加浮動:留在你的類也使用浮動:正確但不要忘記給下一個塊元素清除:兩者,嘗試一次

.horizontal { 
 
    display: inline; 
 
    float:left; 
 
    padding:10px 5px; 
 
    border:1px solid #dddddd; 
 
    margin-right:5px; 
 
    }
<ul> 
 
    <li class="horizontal" style="display: inline;"> 
 
    <div class="product"> 
 
     <div class="image"> 
 
     <img class="img-responsive" src="http://www.shingpoint.com.pk/Images/Thumbnails/pc-a1-470-59100-080316082835.jpg" /> 
 
     </div> 
 
     <div class="description"> 
 
     <h4 class="productname">ASUS VivoMini PC - UN65H-M030M</h4> 
 
     </div> 
 
     <div class="price"> 
 
     <span>Rs. 37,900</span> 
 
     <input type="button" class="btn btn-primary btn-sm" value="Details" /> 
 
     </div> 
 
    </div> 
 
    </li> 
 
    <li class="horizontal" style="display: inline;"> 
 
    <div class="product"> 
 
     <div class="image"> 
 
     <img class="img-responsive" src="http://www.shingpoint.com.pk/Images/Thumbnails/pc-a1-470-59100-080316082835.jpg" /> 
 
     </div> 
 
     <div class="description"> 
 
     <h4 class="productname">ASUS VivoMini PC - UN65H-M030M</h4> 
 
     </div> 
 
     <div class="price"> 
 
     <span>Rs. 37,900</span> 
 
     <input type="button" class="btn btn-primary btn-sm" value="Details" /> 
 
     </div> 
 
    </div> 
 
    </li> 
 
</ul>

+0

檢查我的編輯。我這樣做,但我得到的結果並不好。列表產品正在擠壓 –

+0

我分離了兩個李s作爲個人簽入我的片段一次 –

+0

在這裏你的CSS似乎工作,但不是在我的HTML。它根本不會浮動產品:\可以以某種方式與我聯繫? –

0

這裏說到:

ul { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    background-color: #333333; 
 
} 
 
li { 
 
    float: left; 
 
} 
 
li a { 
 
    display: block; 
 
    color: white; 
 
    text-align: center; 
 
    padding: 16px; 
 
    text-decoration: none; 
 
} 
 
li a:hover { 
 
    background-color: #111111; 
 
}
<ul> 
 
    <li class="horizontal" style="display: inline;"> 
 
    <div class="product"> 
 
     <div class="image"> 
 
     <img class="img-responsive" src="http://www.shingpoint.com.pk/Images/Thumbnails/pc-a1-470-59100-080316082835.jpg" /> 
 
     </div> 
 
     <div class="description"> 
 
     <h4 class="productname">ASUS VivoMini PC - UN65H-M030M</h4> 
 
     </div> 
 
     <div class="price"> 
 
     <span>Rs. 37,900</span> 
 
     <input type="button" class="btn btn-primary btn-sm" value="Details" /> 
 
     </div> 
 
    </div> 
 
    </li> 
 
    <li class="horizontal" style="display: inline;"> 
 
    <div class="product"> 
 
     <div class="image"> 
 
     <img class="img-responsive" src="http://www.shingpoint.com.pk/Images/Thumbnails/pc-a1-470-59100-080316082835.jpg" /> 
 
     </div> 
 
     <div class="description"> 
 
     <h4 class="productname">ASUS VivoMini PC - UN65H-M030M</h4> 
 
     </div> 
 
     <div class="price"> 
 
     <span>Rs. 37,900</span> 
 
     <input type="button" class="btn btn-primary btn-sm" value="Details" /> 
 
     </div> 
 
    </div> 
 
    </li> 
 
</ul>

+0

檢查我的編輯。我這樣做,但我得到的結果並不好。列表產品正在擠壓 –

+0

使用所有代碼和所有樣式進行編輯以查看發生了什麼,您可能會遇到一些錯誤或繼承的類,這些類會合並樣式並且不會給出預期的結果。檢查它檢查您的頁面元素和風格。 – JoelBonetR

+0

如果您想要在一個產品與其他產品之間保留間隔,您可以添加一個邊距或一個填充。但是爲了達到這個工作,使用bootstrap cols而不是無序列表可能會更好,呵呵? – JoelBonetR

0

只需添加li {float: left;}你的風格或者,如果你想顯示RTL使用li {float: right;}

+0

檢查我的編輯。我這樣做,但我得到的結果並不好。列表產品擠壓 –

+0

@Ali Rasheed添加一些可以解決擠壓的襯墊。像'padding:5px;' – SAM