我有一个带有产品信息的ul作为li。我想要做的是根据屏幕尺寸隐藏不适合单行的符号。
因此,显示的产品数量应根据单条线上的适合数量增加或减少。这又取决于用户的屏幕尺寸。
这就是我想要的样子:
目前的情况如下:
我如何做到这一点?我可以在纯HTML / CSS中执行此操作,还是需要使用JS / JQuery?
JSFiddel :
http://jsfiddle.net/narzero/5v3jL4wx/
HTML:
<body>
<div class="content_panel active">
<ul class="unstyled items_board">
<!-- AARDAPPEL - GROENTE - FRUIT -->
<li class="item_header">AARDAPPEL - GROENTE - FRUIT</li>
<!-- One -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/6KJFwk" alt="One">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€2.03</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">Aarts Frambozen op siroop</span>
<span class="item_size muted">370 ml</span>
</div>
</div>
</li>
<!-- Two -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/A4IzmQ" alt="Two">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€2.63</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Aardappelen iets kruimig</span>
<span class="item_size muted">3 kg</span>
</div>
</div>
</li>
<!-- Three -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/CpPGvi" alt="Three">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€3.47</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Aardappelen iets kruimig voordeelzak</span>
<span class="item_size muted">5 kg</span>
</div>
</div>
</li>
<!-- Four -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/VhbPh9" alt="Four">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€1.48</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Aardappelpartjes</span>
<span class="item_size muted">450 gr</span>
</div>
</div>
</li>
<!-- Five -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/bzQua4" alt="Five">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€2.03</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Aardappelschijfjes spek en ui</span>
<span class="item_size muted">500 gr</span>
</div>
</div>
</li>
<!-- Six -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/3CkHGK" alt="Six">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€2.39</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Aardbeien</span>
<span class="item_size muted">250 gr</span>
</div>
</div>
</li>
<!-- BAKKERIJ -->
<li class="item_header">BAKKERIJ</li>
<!-- One -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/Ca4snB" alt="One">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€5.99</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Aardbeien bavaroise vlaai half</span>
<span class="item_size muted">per stuk</span>
</div>
</div>
</li>
<!-- Two -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/FCJCqU" alt="Two">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€5.99</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Aardbeienslof</span>
<span class="item_size muted">per stuk</span>
</div>
</div>
</li>
<!-- Three -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/wl7yYI" alt="Three">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€3.59</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Abrikozenvlaai half</span>
<span class="item_size muted">per stuk</span>
</div>
</div>
</li>
<!-- Four -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/j3JZBP" alt="Four">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€0.94</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Allinson volkoren half</span>
<span class="item_size muted">per stuk</span>
</div>
</div>
</li>
<!-- Five -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/KJzJuq" alt="Five">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€4.79</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Appel-abrikozentaartje</span>
<span class="item_size muted">per stuk</span>
</div>
</div>
</li>
<!-- Six -->
<li class="item ">
<div class="media">
<img src="http://goo.gl/Lx2YMo" alt="Six">
<div class="info_group">
<span class="price_info"><button class="btn btn_price">€6.59</button></span>
<span class="add_button"><button class="btn btn_success">Add</button></span>
</div>
</div>
<div class="item_info">
<div class="item_name item_row">
<span class="full_item_name">AH Appelkruimelvlaai</span>
<span class="item_size muted">per stuk</span>
</div>
</div>
</li>
</ul>
</div>
CSS:
body {
background: #fcfcfc;
font-family: "Open Sans", "Helvetica Neue", Helvetica, sans-serif;
}
/*==== Content panel ====*/
.content_panel .active {
display: inherit;
}
/*==== Product grid ====*/
.unstyled {
font-size: 0;
margin-left: 0;
list-style: none;
}
ul {
display: block;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;
margin: 0 0 10px 25px;
list-style: none;
padding-left: 0;
margin-left: 0;
}
li {
line-height: 20px;
font-size: 16px;
}
ul > .unstyled {
margin-left: 0;
list-style: none;
}
.items_board {
padding: 4px;
min-height: 500px;
}
.item_header {
font-size: 20px;
font-weight: 600;
background: transparent;
width: 100%;
margin-right: 0;
padding: 0;
margin-bottom: 20px;
margin-top: 42px;
cursor: auto;
border: none;
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}
.item_header:first-child {
margin-top: 8px;
}
.items_board > .item {
height: 300px;
margin: 0 -1px -1px 0;
display: inline-block;
position: relative;
vertical-align: top;
width: 205px;
background: #fff;
text-align: left;
color: #5a5a5a;
font-weight: 400;
border: 1px solid #e5edec;
cursor: pointer;
}
/*==== Single product ====*/
/* Media */
.items_board .item:hover .media {
-webkit-user-select: none;
}
.items_board .item .media {
margin-top: 0;
position: relative;
overflow: visible;
}
img {
display: block;
width: 175px;
height: 175px;
margin: 0 auto;
padding: 10px;
max-width: 100%;
vertical-align: middle;
border: 0;
}
/* Info Group */
.info_group {
position: absolute;
bottom: 4px;
display: none;
width: 185px;
height: 32px;
padding: 10px;
border-top: 1px solid #e5edec;
background-image: linear-gradient(rgba(255,255,255,0.75), #fff);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#d9ffffff', endColorstr='#ffffff',GradientType=0 );
}
.price_info {
color: #fff !important;
background-color: #fff;
border-color: #ccc;
pointer-events: none;
cursor: not-allowed;
filter: alpha(opacity=85);
-webkit-box-shadow: none;
box-shadow: none;
opacity: .85;
float: left;
}
.add_button {
margin-right: 4px;
margin-left: 0;
float: right;
}
.item:hover .info_group {
display: block;
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
.btn_success {
color: #fff;
background-color: #5cb85c;
}
.btn_price {
color: white;
background-color: #929292;
}
.btn_success:hover,
.btn_success:focus,
.btn_success.focus,
.btn_success:active,
.btn_success.active {
color: #fff;
background-color: #449d44;
}
/* Item info */
.item_info {
padding: 10px 25px 0 20px;
background: #fff;
min-height: 61px;
font-size: 13px;
}
.item_name {
line-height: 1.5em;
}
.item_row {
margin-bottom: 4px;
}
.full_item_name {
max-height: 70px;
overflow: hidden;
display: inline-block;
text-overflow: ellipsis;
line-height: 1.4em;
}
.muted {
display: block;
color: #999;
}
答案 0 :(得分:3)
如果您可以选择将列表分成两个<ul> ... </ul>
,则可以使用overflow: hidden;
ul {
height: 300px;
width: 100%;
overflow: hidden;
}
答案 1 :(得分:1)
我添加了一个ul并结束了第一个。
也进行了一些css更改,结果是
<强> FIDDLE 强>
.unstyled {
font-size: 0;
margin-left: 0;
list-style: none;
outline: 1px solid red;
white-space: nowrap;
overflow-x: scroll;
}
正如您所看到的,我添加了overflow-x: scroll;
,因此您可以向左或向右滚动以查看其余内容。我还添加了一个white-space: nowrap;
来保持一行。