Tips on avoiding tags from causing line breaks?

My dilemma involves a collection of tags that I prefer not to be subject to word-wrap, but I do want the list of tags to wrap appropriately. For instance:

[first] [second thing] [yet another thing]

What I definitely do not want is:

[first] [second 
thing] [yet another thing]

In other words, I am against any breaking within the tag.

What I am aiming for is more like this:

[first] [second thing] 
[yet another thing]

I've tried various options such as

word-break: break-word;
/* white-space: nowrap; */

on both the parent and child elements, but with no luck. Either the entire field remains as one line with no breaks at all, or I end up with breaks within the tags.

My current CSS looks like this:

.tag-box {
  word-break: break-word;
}

.tag {
  color: white;
  background: #000;
  border: 1px solid white;
  border-radius: 5px;
  margin-bottom: 10px;
  margin-right: 5px;  
  padding: 5px;
  line-height: 200%;
  /* word-break: break-word; */
  /* white-space: nowrap; */
}

Answer №1

Have a look at this fiddle: http://jsfiddle.net/5fev6o2p/6/

Check out the CSS code below:

.tag-box {
  word-break: break-word;
}

.tag {
  color: white;
  background: #000;
  border: 1px solid white;
  border-radius: 5px;
  margin-bottom: 10px;
  margin-right: 5px;  
  padding: 5px;
  line-height: 200%;
  display:inline-block;
}

Here is the HTML snippet:

<ul class="tag-box">
  <li class="tag">[first]</li>
  <li class="tag">[second thing]</li>
  <li class="tag">[third thing]</li>
  <li class="tag">[yet another thing]</li>
  <li class="tag">[first]</li>
  <li class="tag">[second thing]</li>
  <li class="tag">[third thing]</li>
  <li class="tag">[yet another thing]</li>
</ul>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Triggering the function once the text field is tapped again

I recently integrated a JavaScript scroll framework to create a stylish scrollbar for windows. I simply added it to a div: this.displayDiv = function () { $("#myDiv").niceScroll(); } <a href="#" onclick="manager.displayDiv();"> It ...

What causes my animation to “reset” upon adding a new element using innerHTML?

One of the functionalities on my webpage involves a script that inserts a div called "doge" using innerHTML when a button is clicked. Additionally, there is a CSS keyframes animation applied to another div on the same page. However, whenever the button is ...

Tips for modifying the color of selected text

Is there a way to change the color of the dropdown text? Currently, it is set to red but initially appears as black. When clicked on, it changes to red. How can I make it so that the color is initially displayed as red? <select> <option style ...

Using Bootstrap for both modal popups and transforming the scale of the body element

When utilizing Bootstrap 4 (however, encountering the same issue with Bootstrap 3), I have applied a transform:scale(0.9) in my CSS for the body element. The problem arises when I open a modal, causing the page to scroll to the top while the modal and bac ...

Styling the Container Component in ReactJS

I need to apply some styling to the "Forms_formline__3DRaL" div (shown below). This div is generated by a component, but it seems that the style I want to add is being applied to the input instead of its parent div. How can I use ReactJS to set the style " ...

What is causing the inconsistency in the widths of these HTML elements?

I recently created multiple div elements with a uniform width of 5px. Here is the CSS code I used: div { background-color: black; width: 5px; height: 100px; display: inline-block; } To my surprise, despite setting the same width for all divs, som ...

Strange outcomes observed with CSS Selector nth-child

When utilizing the CSS nth-child selector, I am encountering some peculiar issues. The HTML structure is as follows: <div class="block feature-callout-c" id="overview"> <div class="row"> <div class="span twelve"> ...

Struggles with maintaining proper vertical alignment

Despite following numerous tutorials and tips, every time I make a change to center align my content, it ends up breaking something else and pushing me further away from my goal. While I have successfully centered the content horizontally, I am now strugg ...

Align the logo in the center of the navbar with items placed on either side

Looking for a way to center my brand logo within my navbar with menu items positioned around it? Preferably without the use of javascript? I've tried different methods, including adjusting the Bootstrap navbar styling, but haven't found a perfect ...

Trouble with the mobile layout - styling with CSS

Having an issue with the mobile view CSS. Visit: Looking to shift the navigation button to the right and widen the logo without changing its height. Any assistance would be appreciated. Thank you, ...

Incorporating an image prior to the "contains" term with the help of JavaScript

Seeking assistance with the code snippet below without altering the text targeted in my "a:contains" statement. The challenge lies in determining the appropriate placement of ::before in the script provided. Link: https://jsfiddle.net/onw7aqem/ ...

Issue with Next.js: Setting the width to 100vh prevents the height from being responsive on mobile devices

While I understand that using height: 100vh on mobile is generally discouraged for various reasons, I'm curious as to why height: 100vh paired with width: 100vh in Next.js doesn't produce the expected result. Instead of a full-height square, I en ...

Enlarge the div with a click

I was looking for a solution on how to make a div expand when clicked using jQuery I came across a tutorial that seemed simple and perfect, but I couldn't get it to work when I tried to replicate the code. Do you know if this code is still valid wit ...

What is the best way to customize the appearance of the initial row in each tr cluster?

Looking to add a button for expanding child rows within a datatable, with each group in the table having the same child elements.... The provided CSS currently displays the icon on every row throughout the entire table. td.details-control { backg ...

Utilize the appendTo() function and make a switch to dynamically insert content stored in variables into a specified

I am working on developing a page with a central content div, where users have the ability to choose various options that will introduce different additional content. This added content will then present more opportunities for adding new elements, ultimate ...

What is the best way to achieve this Bootstrap design without copying the content?

Trying to achieve a specific Bootstrap layout without repeating content is my current challenge. Essentially, I aim to divide some content into 2 columns at the sm/md breakpoints and then switch to 3 columns for the lg breakpoint. The layout for sm/md bre ...

Margin not being applied to last element in parent - any ideas why?

Why does the margin of the last element, whether it is a <p> or <h1>, not have any impact? It should be pushing the background of the parent container downwards. .container { background: grey; } h1 { margin-bottom: 3em } p { margin- ...

Tips for personalizing the color, font style, background color, and alignment of the WhatsApp share button I designed using HTML

Currently, I am working on adding a WhatsApp share button to a webpage. I would like to customize it using some CSS code. Could someone kindly provide me with the code for customizing this button? <a href="whatsapp://send?text=https://vcard.score ...

Switching the typeface within the content data

Recently, I incorporated this code: <div data-content="Reach" class="main-image"> along with the following CSS styling: .main-image:before { content: attr(data-content); I am now wondering if there is a method to adjust the font size and ...

Wait for AngularJS to load when the background image of a div becomes visible

Currently, I am utilizing the ng-repeat feature to fetch data from a $http.post request and then save it to the $scope.data variable. <div ng-repeat="key in [] | range:data.pages"> <div class="pageBackground" id="page_{{ (key+1) }}" ng-style= ...