What are the steps to adjust my table width without allowing horizontal scrolling?

1- I need help fixing the width of my table so that it stays within the screen. 2- Is there a way to display only the first 100 characters of table data and show the rest when clicked?

Any assistance would be greatly appreciated.

Here is a snippet from my HTML file:

<div class="row">
<div class="col-md-12 col-lg-12 col-sm-12">
    <div class="white-box">
        <h3 class="box-title">Business Opportunities</h3>
        <a href="/update" class="btn btn-info" style="float: right; margin-top: -45px; margin-right: 100px;">Update</a>
        <a href="/logout" class="btn btn-warning" style="float: right; margin-top: -45px" onclick="return confirm('Are you sure you want to logout?')">Logout</a>
         
        <div class="table-responsive">
            <table   class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Website</th>
                        <th></th>
                        <th>Title</th>
                        <th>Description</th>
                        <th>Organization</th>
                        <th>Close Date</th>
                        <th>Weeks Left</th>
                        <th>Downloads</th>
                        <th>Import Date</th>
                        <th>Operation</th>
                    </tr>
                </thead>
                <tbody>
                    {% for row in output %}
                        <tr>
                            <td>{{ loop.index }}</td>
                            <td>{{ row.website }}</td>
                            <td><a href="{{row.op_link}}" target="blank"><i class="fa fa-link"></i></a></td>
                            <td>{{ row.title }}</td>
                            <td>{{ row.description }}</td>
                            <td>{{ row.organization }}</td>
                            <td>{{ row.close_date }}</td>
                            <td>{{ row.weeks_left }}</td>
                            <td>
                                {% for link in row.downloads %}
                                    {% if link != '' %}
                                        <a href="{{ link }}">[{{ loop.index }}]</a>
                                    {% else %} 
                                        <p>N/A</p>     
                                    {% endif %}
                                    
                                {% endfor %}
                            </td>
                            <td>{{ row.created_at }}</td>
                            <td>
                                # some other codes
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

https://i.sstatic.net/NM4xa.jpg

Answer №1

Here's a helpful tip for your table-responsive class.

.table-responsive {
  /* Your custom styles */
  max-width: 100% !important;   /* Specify the necessary width */
  overflow-x: auto; 
}

Please keep in mind that by implementing this code, the parent div of the table will be constrained to a maximum width. If the content exceeds this width, a scrollbar will appear to allow smooth navigation within the confines of the set max-width.

Answer №2

Bootstrap 4 is being used, right?

Your code has been copied and pasted into the snippet below, and everything seems to be working fine.

If you could provide me with the full code, I can help resolve any issues more easily.

Please let me know if you require any assistance.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-12 col-lg-12 col-sm-12">
    <div class="white-box">
        <h3 class="box-title">Business Opportunities</h3>
        <a href="/update" class="btn btn-info" style="float: right; margin-top: -45px; margin-right: 100px;">Update</a>
        <a href="/logout" class="btn btn-warning" style="float: right; margin-top: -45px" onclick="return confirm('Are you sure you want to logout?')">Logout</a>
         
        <div class="table-responsive">
            <table   class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Website</th>
                        <th></th>
                        <th>Title</th>
                        <th>Description</th>
                        <th>Organization</th>
                        <th>Close Date</th>
                        <th>Weeks Left</th>
                        <th>Downloads</th>
                        <th>Import Date</th>
                        <th>Operation</th>
                    </tr>
                </thead>
                <tbody>
                    {% for row in output %}
                        <tr>
                            <td>{{ loop.index }}</td>
                            <td>Sed ut perspiciatis </td>
                            <td><a href="{{row.op_link}}" target="blank"><i class="fa fa-link"></i></a></td>
                            <td>Sed ut perspiciatis</td>
                            <td>{{ row.description }}</td>
                            <td>{{ row.organization }}</td>
                            <td>{{ row.close_date }}</td>
                            <td>Sed ut perspiciatis </td>
                            <td>
                                
                                        <p>Sed ut</p>     
                                    {% endif %}
                                    
                                {% endfor %}
                            </td>
                            <td>{{ row.created_at }}</td>
                            <td>
                                # some other codes
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
  </div>

Answer №3

Implementing a fixed table layout along with the width property allows you to limit the width of the table. By using the text-overflow property, you can add an ellipsis to any words that are too lengthy to display fully.

    table {
      width: 100%;
      table-layout: fixed;
    }
    td {
      max-width: 50px;
      white-space:nowrap;
      overflow:hidden;
      text-overflow:ellipsis;
    }

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

Inline Align Left and Right Text (Using iText7.Html2pdf)

I have encountered an issue with my HTML code where I have two spans aligned left and right, which displays correctly in the browser. However, when I convert it to PDF using iText7, the left-aligned text disappears and is replaced by the right-aligned text ...

Missing sidebar display

Hi there! I am having an issue with my sidebar not appearing correctly when I click on the toggle button. It seems to be moving to the side, but the sidebar itself is blank or transparent. I suspect that the problem lies within my JavaScript file. As a beg ...

IonTabButton not responding to onClick events

Currently, I am utilizing the Ionic 5 CSS library in combination with React. I found that IonTabButtons have a more appealing style compared to IonButtons because IonTabButton allows for text below the Icon. In the screenshot provided, all icons are displ ...

Steps to insert one object into another object in Angular/JavaScript

Currently building an app, and encountering a challenge while attempting to push an array into another array. The error message displayed is "Cannot read property 'push' of undefined." Provided object: export var CARDS: any[] = [ { ...

The Angular 5 keyup event is being triggered twice

My app is incredibly simple, just a basic hello world. To enhance its appearance, I incorporated bootstrap for the design and ng-bootstrap for the components. Within one of my TS files, you will find the following code: showMeTheKey(event: KeyboardEvent) ...

inconsistency in button heights

I am currently working on a website project for one of my college courses and I have encountered an issue with the button heights in my slide show not matching up. I'm seeking advice or tips on how to align both buttons to have the same height. Can an ...

NextJS hot reload with Docker is a powerful combination for seamless development environments

I've encountered issues trying to configure hot reload with Docker and NextJS. When I make changes and save a file, the server does not reload. Below is the contents of the docker-compose.yml: version: '3' services: mainapp: build: ./ ...

How to rotate text direction using JavaScript and CSS

Despite my extensive efforts, I have been unable to find a solution to a seemingly simple problem. In JavaScript, I have generated dynamic text using the following code: context.fillText('name', 10, 10, 20); Now, I need this text to be ori ...

Angular: The function t(...) does not support success - TypeError

My code is generating the error TypeError: t(...).success is not a function. I have tried searching for a solution but haven't been able to figure out why this error is happening in my specific case. Here is a snippet of my JS code. Can anyone point ...

What is the best method for converting a variable with HTML content into a printable string?

In an attempt to display user-entered data from a text box to an HTML div, there seems to be an issue when the data contains HTML content. Instead of displaying the content as a string, it shows it as HTML elements. For example: let text = "<h1>Worl ...

Issue with displaying sidebar using blockquote in Bootstrap 4.1.3

After implementing the blockquote class in Bootstrap 4.1.3, all the effects were successfully applied, except for the sidebar. Here's a comparison of how it appears in tutorials: https://i.sstatic.net/qNXrV.png And here is how it appears in my Chrom ...

Eliminate the space between the navigation bar and carousel when using Materialize with Vue.js and Laravel

I am facing an issue with the gap between the navbar and carousel in my materialize design. I have implemented Vue components for each div and Laravel as the backend. Using Sass for CSS preprocessing, I attempted to adjust the margins for the body, navbar, ...

Issue with PageSpeed and Lighthouse showing NOT_HTML error post recent update

Our team decided to utilize the tool at for assessing the speed of our website. This tool has been effective in analyzing our site's URLs for some time now. However, recently we have encountered an issue where we receive the following error message: ...

Is the syntax incorrect or is there another reason for the empty array being passed, as the "resolve" callback is running before the completion of the for loop?

The for loop will iterate over the length of req.body, executing a Customer.find operation in each iteration. The resolve function will then be called with an array containing the results of all the find operations. let promise = new Promise(function(res ...

Tips for ensuring that the click event function properly for numerous elements sharing the same class

I'm currently working on adding a flip effect to multiple tiles whenever a user clicks on them as part of building a dashboard-style webpage. I am having trouble making the click event work for all tiles with the same class name. Even though all the ...

What is the best way to share a variable from a component in Vue.js?

As I develop a validation component for publication, my goal is to leverage a variable similar to this.$validate.bla(), with "bla" representing a function within my component. ...

Verify whether the div already includes a particular item

I am currently working on an angular project where I need a button to add a blockquote within a div, but only if the blockquote is not already present in the HTML structure. My initial approach was to search for the specific string <blockquote id=&apos ...

Guide to implementing validation on submit in Angular 7 reactive forms

Code Snippet: handleFormSubmission(){ if(this.Registration.invalid){ return; } alert('Thank you for submitting! Data:' + JSON.stringify(this.Registration.value)); } Form Markup: <form class="admin-form" [formGroup]="Registration" (ng ...

Is it possible to add a class to a child element deep within the component hierarchy while using TransitionGroup/CSSTransition in React?

I currently have a setup like this: Parent Component: <TransitionGroup> { items.map((child, index) => { // do something return ( <CSSTransition key={index} nodeRef={items.nodeRef} timeout={1000} classNames={'item ...

Innovative Tools for Interactive Sites and Dynamic Animations

I'm interested in developing interactive websites soon and I'm curious about the various technologies I can use to create an engaging web page. I know that HTML5 now supports drawing on a Canvas, even in 3D. Can you recommend any helpful tutoria ...