having difficulty resolving the problem when utilizing bootstrap classes

I am currently facing two issues with my code. The first one is that the header is not remaining fixed, and the second issue is that word wrapping is not working for the headers/rows. Even though I have used bootstrap classes, these problems persist. I am looking to fix the table header so that only rows are scrollable, and long text should automatically wrap. My application contains multiple columns, approximately 15 in total. Any advice on how to resolve this would be greatly appreciated.

To see a sample code snippet, click here.

Sample HTML code:

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    Launch demo modal
</button>

<div id="myModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Modal title</h4>
            </div>
            <div class="modal-body" id="modal-body">
                <table id="myTable" class="table table-fixedheader table-bordered table-striped">
                    <thead>

                        <tr class="row">
                            <th class="col-md-3">Header1</th>
                            <th class="col-md-4">Header2Header2Header2Header2</th>
                            <th class="col-md-3">Header3</th>
                            <th class="col-md-4">Header4</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="row">
                            <td class="col-md-3">111111111111111111111111111111111111111111111111111111111111111111111</td>
                            <td class="col-md-4">33333</td>
                            <td class="col-md-3">1111</td>
                            <td class="col-md-4">5443545435354543</td>
                        </tr>
                        // Additional rows...
                    </tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

Answer №1

Consider exploring a different approach instead of using tables. You can set specific widths for columns and allow content to wrap within the cells. Take a look at this example https://codepen.io/flurrd/pen/jmMNxK?editors=1100

Please note that the class names used in this example are not ideal. It would be better to follow BEM methodology for proper naming.

.table-body {
  max-height: 200px;
  overflow-y:auto;
}
.t-row {
  display: flex;
  border-bottom: 1px solid grey;
}
.t-row:nth-child(even){
  background: #e3e3e3;
}
.col {
  word-wrap: break-word;
  flex: 1 0 30%;
  max-width: 33.3333%;
}
.cell {
  padding: 8px;
}


<div class="table-wrap">
  <div class="t-row t-header">
    <div class="col">
      <div class="cell">
        Header 1
      </div>
    </div>
    <div class="col">
      <div class="cell">
        Header 1
      </div>
    </div>
    <div class="col">
      <div class="cell">
        Header 1
      </div>
    </div>  
  </div>
  <div class="table-body">
    <div class="t-row">
      <div class="col">
        <div class="cell">
          Lorem ipsum dolor sit amet, consectetur adipisicing elit.
        </div>
      </div>
      <div class="col">
        <div class="cell">
          1111
        </div>
      </div>
      <div class="col">
        <div class="cell">
          11111111
        </div>
      </div>
    </div>  
  </div>
</div>

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

Implementing JavaScript validation to alter the background image

I encountered a small issue while working on my project. I was designing a form in HTML using JavaScript, and for the input fields, I decided to use a background image with padding on the left to enhance its appearance. Everything seemed fine until I ran i ...

Is there a way to invoke a function using $scope within HTML that has been inserted by a directive in AngularJS?

After moving the following HTML from a controller to a directive, I encountered an issue where the save button no longer functions as expected. I attempted to change the ng-click to a different function within the directive code, and while that worked, I u ...

Retrieve the value of a variable by using either an HTTP GET or POST request

Here's the HTML code snippet that I'm working with: <head> <h1>Sample Page</h1> </head> <body> <form method="POST" action=""> Enter Keyword <input type="text" name="key"> ...

Anchors that need to be clicked multiple times before activating

'I recently encountered a strange bug. My CSS3 anchors/buttons, which I have been simplifying by removing properties, sometimes require multiple clicks to function. This is completely new to me and quite perplexing. The issue seems to occur randomly, ...

Ways to create a vertically expandable full-screen design

I am currently working on designing a full-screen layout where the content adjusts based on the size of the footer. body { margin: 0; padding: 0; } .layout { height: 100vh; display: flex; flex-direction: column; background-color: yell ...

Guide on setting a personalized color for progress bars in Bootstrap 4

I'm working on a progress bar: <div class="progress"><div class="progress-bar" style="width:{{a.49}}%">{{a.49}} %</div> </div> Is there a way to apply a custom color to the progress bar based on a condition in CSS? : If a.49 ...

What factors could potentially cause Internet Explorer to fail in processing conditional comments effectively?

I am currently developing JSP pages with Tomcat and I need to ensure compatibility with IE 7, as requested by the client, along with Firefox and Chrome. Despite including both sets of code in my program, it seems to work perfectly fine for browsers other ...

How can I reset a CSS position sticky element using JavaScript?

I have created a page where each section fills the entire screen and is styled using CSS position: sticky; to create a cool layered effect. Check it out here: https://codesandbox.io/s/ecstatic-khayyam-cgql1?fontsize=14&hidenavigation=1&theme=dark ...

Tips for shortening button text within a flex child element

I'm struggling to achieve a specific layout using flexbox. I require one child element that does not shrink, and two child elements that can shrink/grow and be truncated based on their content while considering the sizes of their content. My current ...

React Native buttons are displaying at a fixed width and not adjusting as expected

Within a row, I have two buttons with a padding of 20 between them, and they are only taking up the necessary width for the button text. The width remains constant! Here is the code for the buttons: <View style={styles.buttonContainer}> &l ...

What are the steps to increase the size of the v-stepper-step in Vuetify?

Is there a way to adjust the size of the icon/step circle in v-stepper? ...

Styling tip: Distance the tooltip from its parent element when scrolling through a list

I have a table inside li tag, and I want to display the description on :hover inside td. However, when scrolling through the list, the description content starts to appear with a distance from its parent. Despite trying various combinations of position se ...

Is less.js capable of compiling CSS code that is compatible with all browsers?

Is there a simple way to convert my Less code into browser-compatible CSS like the example below? #grad1 { background: -webkit-linear-gradient(red, blue); /* For Safari 5.1 to 6.0 */ background: -o-linear-gradient(red, blue); /* For Opera 11.1 to ...

Generate a fresh DOM element when a particular height threshold is achieved, utilizing a portion of the previous DOM element's content

Update: 27th December 2016 The heading has been modified because any DOM element can be the target, whether it is a <p> element or not. Additional information has been provided about the tools being used and the desired outcome. Are there nativ ...

Display just a fraction of a picture

Just recently, I had a surprising discovery when I right-clicked on the cross icon and noticed that the background image in the Tags section of the Ask Question page contained multiple icons beyond just the cross. Curious about how this was achieved, I sea ...

Managing Input Type Dropdown Selections Using Jquery

I am currently in the process of developing a website. On this website, there is a form that includes 3 dropdown menus as shown below. I would like to implement a feature where selecting the number 5 from the Adults menu will automatically display 5 in the ...

Learn how to incorporate a HTML page into a DIV by selecting an Li element within a menu using the command 'include('menu.html')'

I have a website with both 'guest' and 'user' content. To handle the different menus for logged-in and logged-out users, I created menuIn.html and menuOut.html files. These menus are included in my MainPage.php using PHP logic as sugges ...

Implementing dynamic display of div based on dropdown selection in typescript

A solution is needed to display or hide specific div elements based on a dropdown selection using Typescript. Sample HTML file: <select class="browser-default custom-select"> <option selected>single</option> <option value="1"> ...

Why is Google's No Captcha ReCaptcha failing to function properly

Seeking assistance with a PHP issue - I have implemented the no captcha reCAPTCHA widget, but I am struggling with a code snippet I found online. Whenever I try to submit an email, I receive a prompt to check the captcha, whether I click the box or not. F ...

Unable to change the variable for the quiz

Currently, I am in the process of developing a quiz app and I am facing an issue with my correct variable not updating. Whenever I trigger the function correctTest() by clicking on the radio button that corresponds to the correct answer, it does get execut ...