Styling text within a bootstrap button using CSS

I am currently using Bootstrap and have an accordion with collapsible buttons. Each button consists of two columns of text and an icon on the right.

My issue is that I'm attempting to break the text in the second column into multiple lines so that it can fit within the button.

Any suggestions or ideas on how to achieve this?

You can view an example in this CodePen: https://codepen.io/averied/pen/gBoxbw

I specifically need to break the text inside the div with the id "bloc2".

<div class="container">
  <div class="row">
    <div class="col">
      1 of 3
    </div>
   <div class="col col-lg-4">
      <div id="accordion">
  <div class="card">
    <div class="card-header" id="headingOne">
      <h5 class="mb-0">
        <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
         <div id="block_container" cols="4">
                        <div  id="bloc1">SmallText</div>
                        <div  id="bloc2">Please break this text it's very large and doesn't fit</div>
                        <button id="delbtn"/></button>
                    </div>
        </button>
      </h5>
    </div>

    <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
      <div class="card-body">
         labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" id="headingTwo">
      <h5 class="mb-0">
        <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          Collapsible Group Item #2
        </button>
      </h5>
    </div>
    <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
      <div class="card-body">
        labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" id="headingThree">
      <h5 class="mb-0">
        <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
          Collapsible Group Item #3
        </button>
      </h5>
    </div>
    <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
      <div class="card-body">
        labore sustainable VHS.
      </div>
    </div>
  </div>
</div>
    </div>
  </div>
</div>

https://i.sstatic.net/wroP1.png

Answer №1

A possible solution is to

#bloc2 { white-space: normal; }

Answer №2

To enhance the appearance of the btn, consider adding a special class...

.text-wrap {
  white-space: normal;
}

In the bloc2 section, it is recommended to remove the word-break: break-all; property...

For further details, visit https://codepen.io/anon/pen/ePyGRJ

Answer №3

To start, make sure to update your #block_container by adding the property flex-wrap: wrap;. Adjust your CSS like this:

#block_container
{
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    cursor: pointer;
}

Additionally,

#bloc2 {
display: flex;
justify-content: center;
flex-wrap: wrap;
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
}

It's unclear why you want your button to expand in height rather than displaying ellipsis for long text.

Check out this code sample on CodePen

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

Can an advertisement's appearance be altered to include custom content using only CSS?

Dealing with SAP for our ticket system has been quite a challenge due to the design that is causing some frustration. In an attempt to make it more tolerable, I used CSS to make some adjustments. However, my problem now lies in the fact that they keep maki ...

Tips for repositioning the window when linking to a different section of a website

As a beginner in HTML and CSS, I am currently working on adding a navigation bar to my one-page website. I want the navigation bar to smoothly guide users to different sections of the page when they click on a link. To achieve this, I am using anchors and ...

Having trouble getting the card to adapt to different screen sizes on mobile devices

Can someone please take a look at this website? It seems to display correctly and function well when viewed in full size on a browser, but for some reason, when I try to access it from a mobile device or using the Chrome device emulator, both the bootstra ...

Warning button covers alert box

Bootstrap warning message covering the Create Repository button. Tried setting display:block, but it didn't fix the issue. Check out this JSFiddle for more details. <a href="#"> <button style="width:250px; display:block" class="btn btn-p ...

Tips for adjusting website display height on mobile devices

My desktop website appears exactly as I want it to. When inspecting the site on the console to test responsiveness, everything seems fine. However, once I upload the changes to AWS and view the website on my phone, the vh and flexbox properties are not fun ...

Why is the conversion of rgba to hsla happening in Scss?

Currently, I am utilizing web pack for compiling my scss files into css and Bootstrap 4 is being used in my project. An unusual occurrence caught my attention, within my scss file, the following property is defined: color: rgba(255, 255, 255, 0.9); Once ...

What is the best way to add space between Bootstrap buttons and a table?

https://i.sstatic.net/8Hy2M.png Recently, I started learning Bootstrap with a focus on keeping my code clean and simple while following best practices. However, I am facing an issue where the buttons are too close to the table in my design, making it look ...

What is the best way to align a group of social media icon background images in the center

Looking for assistance with centering a block of social icons on my website when viewed on a mobile browser. Here is the HTML: <div id="header-tel-no">Tel: 123456789</div> <div id="social-buttons-header"> <p><a class="social-bu ...

What is the best way to adjust the font size for a bootstrap-select dropdown menu?

I attempted to create a new CSS class to customize the appearance of the dropdown menu, but unfortunately, it doesn't seem to be taking effect. #form.py class fundForm(forms.Form): fund = forms.ChoiceField(choices=FUND, required=True, widget=for ...

What is the best way to transfer a row value from one table to another and then reinsert it back into the original table

I attempted to transfer a row value from one table to another and then back to the original table, but unfortunately, I was unable to find a solution. $('#one tbody tr td input.checkbox').click(function() { if ($(this).attr('checked&apo ...

What is preventing the adjacent DIVs from aligning on the same row as this DIV?

In the code snippet below, I've introduced another div.website-thumbnail. However, the div containing <span class="website-title">Business Coach</span> appears isolated on its own line, almost as if it has clear: left; applied to it. None ...

Hide a div element upon selecting an option from a dropdown menu

On iPhone 6plus and lower, I created a dropdown menu that opens when users click on "jobs" or "contact." However, after clicking on these options, the drop-down menu remains open. How can I make it hide automatically after a list item is clicked at this sp ...

What is your preferred method for adjusting the size of Divs on your webpage according to the screen size?

Currently working on a coding test and facing an issue with the display of div sizes across different screens. The discrepancy in appearance between my laptop and a Mac computer monitor is causing some trouble, as on my small laptop the divs appear overs ...

Steps to conceal an accordion upon loading the page and reveal it only when clicking on a specific element

Below is the code I am using to display an accordion in a Fancybox popup. However, I do not want the accordion to be visible on page load. If I hide it, the content inside also gets hidden when showing the accordion in the popup. When user clicks on Click ...

Tips on determining the type of DOM element for CSS Selector adjustment

In this case, $self is not returning the expected result and I am getting "undefined". To adjust the CSS selector to correctly target the desired element, I need to determine which element type I am dealing with. Is it the "ul", "li", or "a" element? Whil ...

Strange floating error in Internet Explorer 7

Working on a webpage at this link, I have structured my HTML as follows: <div id="wrapper"> <div id="main"> <div class="images"> <p>Content</p> <div class="clear"></div> ...

Tips on attaching a suffix icon to a material-ui-pickers input box

Here is a snippet of my code: <Box p={6}> <Grid container spacing={2}> <Grid item xs={6}> <TimePicker autoOk label={t('checkIn')} value={time1} onChange={handlecheckIn} clearable /> </Grid> < ...

Is there a way to initiate a background fade-in once an animation has finished?

I have customized the background of the parent element called "banner". Is there a way to smoothly fade in this background after the child elements "block" and "block2" finish animating and reveal the underlying text? <section id="banner"> &l ...

Create a CSS border that resembles the one used in Google's signup form

lies a curious inquiry: what unique border style is in play here? It rests slightly raised against the backdrop, creating an intriguing visual effect. After combing through various sources online, the answer still eludes me. Perhaps turning to Google' ...

Choosing the right jQuery selector to target a section that contains div elements

Whenever the h2 element within a section is clicked, I want all the fields in that section to be displayed. For example, if the user clicks on 'Contact Information', the three form inputs (fields) below the Contact Information heading should appe ...