Trim the data in the following table cell using CSS

I'm trying to create a list using a table structure:

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

However, the lengthy URL is causing the table to expand wider than desired. I have attempted solutions like:

table { table-layout: fixed; width: 100%; }

and

td.title { white-space:nowrap;overflow: hidden; width: 200px; }

Unfortunately, these approaches have not resolved the issue.

It's worth mentioning that the table is generated dynamically, although this should not affect the solution.

Any advice on how to address this problem?

Answer №1

Simply trim the text of the URL (excluding the href value) at a specific character. Using Javascript, you can achieve this by using str.substring(5, 0);, where 5 represents the desired number of characters to retain.

Answer №2

By default, a table cell will expand to accommodate the content within it. The `width` property on a table cell behaves more like `min-width`.

To address this issue, avoid styling the `td` directly and instead focus on styling its contents only.

You can try something along these lines:


td.title a {
    display: inline-block;
    white-space: nowrap;
    overflow: hidden;
    width: 200px;
}

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

A webpage featuring a 2-column layout with a footer, along with a right column that is absolutely positioned and

I'm currently working on a basic two-column layout: <div class = "parent"> <div class = "left-column"> </div> <div class = "right-column"> </div> </div> <div class = "footer"></div> The con ...

What is the best way to modify the appearance of the button?

I'm attempting to change the appearance of buttons at the top of a webpage to be square and blue. I have jQuery code for this purpose, but it doesn't seem to be functioning correctly. Here is the snippet of code I am using: $(document).ready(fu ...

Is it possible to maintain consistent numbering for ordered lists using only CSS, even when the lists are separate from each other?

Example: https://jsfiddle.net/jacobgoh101/uqrkaodc/3/ <ol> <li>a</li> </ol> <ul> <li>b</li> </ul> <ol> <li>c</li> <li>d</li> <li>e</li> </ol> ol li ...

Automatically scroll the chat box to the bottom

I came across a solution on Stackoverflow, but unfortunately, I am having trouble getting it to work properly. ... <div class="panel-body"> <ul id="mtchat" class="chat"> </ul> </div> ... The issue lies in the JavaScript t ...

Using Javascript to dynamically add variables to a form submission process

Looking to enhance my javascript skills, I've created a script that locates an existing id and exchanges it with a form. Inside this form, I'm aiming to incorporate javascript variables into the submit url. Unsure if this is feasible or if I&apo ...

Adjusting the size of <nav> element to accommodate its child elements

I've exhausted all possible CSS solutions today in an attempt to make my parent nav tag home-main-nav-menu resize based on its children and grandchildren, but it just won't cooperate. If anyone could provide a clear explanation on how to solve th ...

How can you apply color to {{expression}} text using AngularJS while also keeping all the text on a single line?

After writing the following code, I noticed that when I enter text into the input box, an output appears. However, I am now trying to find a way to color the output text while keeping it on the same line. <script src="https://ajax.googleapis.com/ajax ...

What is the most effective way to alter the text color using jQuery?

Whenever I want to create a text hover animation, jQuery is my go-to tool. Is there a snippet of code that can change the color or size of the text in this case? ...

Discover the Optimal Approach to Implementing Callback Function with JSON Using Javascript and Jquery

I have a function that looks like this : <script> function sticky(json){something here} </script> Now, I would like to utilize Jquery to invoke this function and display its output within a specific div element with the ID of "stickid". H ...

What might be the reason for the border not reaching the bottom of the popup in my chrome extension?

I am currently working on a Chrome extension and using Bootstrap 5 with Sass to style its popup. However, I have encountered an issue where the border of the popup does not extend to the bottom as expected. What could be causing this problem? popup.html & ...

What causes the form to vanish when using the ngFor directive?

Whenever I use the ngFor directive within a form tag, the entire form seems to disappear. Does anyone have any advice on how to resolve this issue? <form #myforms="ngForm" *ngFor="let i of editaddress"> <div class="p-3 p-lg-5 border"> < ...

Disregarding boundaries set by divisions

Trying to keep things concise here. I have a division called "the box" with a fixed width of 1200px that contains various other divisions. One of these divisions is a links bar, known as the "pink bar", which has a width of 100% and a height of 25px. My is ...

Animating an image with CSS steps to create a captivating shaking

My attempt at creating a basic animation is not producing the desired smoothness. .animate { animation: motion 1.5s steps(27) forwards; } @keyframes motion { 100% { background-position: -5778px; } } <div class="animate ...

Removing CSS from a button inside a jQuery Mobile popup: a step-by-step guide

Within a jQM dialog, I have a pair of buttons: <a href="#" data-role="button" data-inline="true">Yes</a><a href="#" data-role="button" data-inline="true" data-rel="back">No</a> These buttons are automatically styled by jQM, incorp ...

Retrieve the outcome from the PHP webpage

I have recently developed a contact page, but I am experiencing an issue with the submit button's functionality. When I click on the submit button, the form is supposed to send the information to a PHP file on the server-side. However, the button does ...

How can you convert an epoch datetime value from a textbox into a human-readable 24-hour date format

I have an initial textbox that displays an epoch datetime stamp. Since this format is not easily readable by humans, I made it hidden and readonly. Now, I want to take the epoch value from the first textbox and convert it into a 24-hour human-readable da ...

The hover effect on sibling elements is not functioning for the <img> tag

When you hover over the image displayed within the <div class="like absolute">, the image within the <div class="balloons absolute"> doesn't appear. <div id="container" class="relative"> <div class="like absolute"> ...

Controlling the Quantity of Selected Checkboxes with JavaScript

I am facing an issue with implementing multiple checkboxes with limits in JavaScript, as shown below. $(".checkbox-limit").on('change', function(evt) { var limit = parseInt($(this).parent().data("limit")); if($(this).siblings(':checked&ap ...

Display a table showcasing precise array data using Angular

In the app.component.ts file, I have created an array called "data" containing strings separated by commas. To format it in a way I desire, I parse it into JSON and use console.log to neatly display it as follows: const jsonData = Papa.parse(content, {ski ...

Export asp tables filled with dynamic data directly to Excel format

I've encountered an issue with exporting a dynamic ASP table to Excel. I created the table in the code behind and set up an export function, but when I export it, the Excel file comes out empty with no data. Interestingly, the export function works p ...