gpt4 book ai didi

jquery - 如何隐藏不适合单行的 li?

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:56 25 4
gpt4 key购买 nike

我有一个 ul,产品信息和 li 一样。我想要做的是根据屏幕尺寸隐藏不适合单行的 li。

因此,显示的产品数量应该根据一行中的数量来增加或减少。这又取决于用户的屏幕尺寸。

这是我希望它看起来像的样子:

enter image description here

这是它目前的样子:

enter image description here

我该如何实现?我可以在纯 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;
}

最佳答案

如果有将列表分成两部分的选项 <ul> ... </ul>每个类别一个,然后你可以使用 overflow: hidden;

ul {
height: 300px;
width: 100%;
overflow: hidden;
}

fiddle :http://jsfiddle.net/5v3jL4wx/1/

关于jquery - 如何隐藏不适合单行的 li?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26317041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com