1
我有一個彈性箱標籤雲,從外部進行大小調整。如果需要,我希望它內部的標籤可以一直摺疊到零(邊緣情況)。現在,他們只能填充2倍。flex-shrink如何贏得填充?
基本上,我需要一種方法來使flex-shrink
「贏」 對padding
。
如果可能,我希望在不使用overflow的情況下實現該功能:hidden,因爲這會干擾機箱內的其他內容。
可運行的代碼片段:
$('button').on('click', (e) => {
$('.tags').css({
width: $(e.target).text()
});
});
.tags {
display: flex;
margin-bottom: 20px;
background: red;
overflow: visible;
padding: 20px 5px;
}
.tag {
position: relative;
padding: 5px 10px;
background: #ccc;
border: 1px solid #aaa;
border-radius: 20px;
white-space: nowrap;
text-overflow: ellipsis;
flex-shrink: 1;
overflow: hidden;
}
.tag + .tag {
margin-left: 3px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h3>Tags will not collapse beyond 2 x padding</h3>
<div class="tags" style="width: 200px">
<div class="tag">Tag 1</div>
<div class="tag">Tag 2</div>
<div class="tag">Tag 3</div>
</div>
<br />
<div>
<button>200px</button>
<button>100px</button>
<button>50px</button>
<button>10px</button>
</div>
任何人有一個想法?
這做到了。謝謝! – panta82