Reputation: 1
community.
I've tried many things but I don't really get it why it's not working.
I want that these keywords don't break the line:
https://www.dropbox.com/s/rgka8jkxzxcw1ez/screenshots.PNG
If a keyword is longer, it should float into the next line without breaking.
The code looks like this:
keyWordList.append('<span><span class="keyword" id="' + ui.item.id + '">' + ui.item.value + '</span>');
$('#' + ui.item.id).append('<span><p class="remove_btn" onclick="removeKeyword(this);">' +
'✖</p></span></span>');
I've tried nowrap, white-space: pre, white-space: nowrap and some other things. But with "nowrap" or "white-space: nowrap;" the keywords run out of the window.
What can I do?
Upvotes: 0
Views: 405
Reputation: 27609
This answer is based on Aaron Digulla's but with some modifications to make it more suitable (I feel). The key modification is replacing the white-space: nowrap
with display: inline-block
. The latter changes the keyword span into a mix of block and inline which means it will take a rigid block size but flow like an inline element. This means if the block wouldn't fit on a line
This should work:
<div id="tags">
<span class="keyword">Tag1</span>
<span class="keyword">Tag2</span>
<span class="keyword">Tag3</span>
<span class="keyword">word1 word2 word3</span>
<span class="keyword">A very long wordxxxxxxxxxxxxxx</span>
</div>
CSS:
#tags {
width: 250px;
border: 1px solid red;
}
.keyword {
background: yellow;
display:inline-block;
margin:2px;
}
Upvotes: 0
Reputation: 328604
This should work:
<div id="tags">
<span class="keyword">Tag1</span>
<span class="keyword">Tag2</span>
<span class="keyword">Tag3</span>
<span class="keyword">word1 word2 word3</span>
<span class="keyword">A very long wordxxxxxxxxxxxxxx</span>
</div>
CSS:
#tags {
width: 100px;
border: 1px solid red;
}
.keyword {
background: yellow;
white-space: nowrap;
}
Upvotes: 0