How do I go about making the 'description' column responsive? As you can see the bootstrap description is pushing my site. I would like the description go for a specific width, and the text to go behind the 'language' and have just one horizontal scroll bar for all of the description column.
I'm using bootstrap btw so the code doesn't contain a css but maybe it helps you anyway :)
<div className="table-responsive-lg">
<table className="table table-hover text-nowrap">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Language</th>
<th scope="col">Date Created</th>
<th scope="col">File Size (kb)</th>
<th scope="col">Open Issues</th>
</tr>
</thead>
<tbody>{data.map(item => (
<tr key={item.id}>
<td><a href={item.html_url}>{item.name}</a></td>
<td>{item.description}</td>
<td>{item.language}</td>
<td>{item.created_at.slice(0,10)}</td>
<td>{item.size}</td>
<td>{item.open_issues}</td>
</tr>
))}</tbody>
</table>
</div>
You can define a class with some CSS as below:
.fixed-width {
width: 400px;
display: block;
overflow-x: auto;
}
then add class fixed-width to all <th> and <td> tags in your "description" column.
Use this CSS.
.table {border-collapse:collapse; table-layout:fixed; width:310px;}
.table td {width:100px; /*add as per your requirements*/ word-wrap:break-word;}
Using Child Pseudo Or Unique Id OR Class.
Set as per screen required. Using #media.
I modified the previous answer a bit and add the .fixed-width class only on the column containing the description
.fixed-width {
max-width: 400px;
display: block;
overflow-x: scroll;
}
<div className="table-responsive-lg">
<table className="table table-hover text-nowrap">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Language</th>
<th scope="col">Date Created</th>
<th scope="col">File Size (kb)</th>
<th scope="col">Open Issues</th>
</tr>
</thead>
<tbody>
<tr key="1">
<td>Google</td>
<td class="fixed-width">some looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong description here</td>
<td>English</td>
<td>19/01/2021</td>
<td>38</td>
<td>5</td>
</tr>
</tbody>
</table>
</div>
You can define your css Like this:
tbody tr td:nth-child(2) {
width: 245px;
overflow-x: scroll;
max-width: 245px;
}
Related
I only know the basics of CSS so not sure how to go about this. I have a table with mostly 1-line data, but the last cell, called "Other", in my first row has multiple lines
Is there a way to make the height small for every cell in the table except that one cell? Right now, because the column with multiple lines is so large, it's making the rest of the cells have extra white space above and below the data (see first screenshot). When I change line-height of the td it makes the whole table look nice except for that one cell with multiple lines (see second screenshot)
without line-height:
with line-height added:
html (i've left out some td's to make it look cleaner):
<table class="table">
<thead>
<tr>
<th scope="col">Something</th>
<th scope="col">Code Version</th>
<th scope="col">Region</th>
<th scope="col">Something</th>
<th scope="col">Something</th>
<th scope="col">Something->Membership</th>
<th scope="col">SBMO</th>
<th scope="col">Something</th>
<th scope="col">IVR</th>
<th scope="col">CPM Something</th>
<th scope="col">Other</th>
</tr>
</thead>
<tbody>
<!-- start loop for mongodb collection: environments-->
<% environments.forEach(function(environment){ %>
<tr>
<td>
<%= environment.something %>
</td>
<td>
<%= environment.codeVersion %>
</td>
<td>
<%= environment.region %>
</td>
<!-- other td's go here --->
<!-- CELL WITH MULTIPLE LINES: -->
<td class="other">
<%= environment.other %>
</td>
<%}); %> <!-- end loop for environments -->
</tr>
</tbody>
</table>
css:
.table td {
padding: 0 !important;
margin: 0 !important;
vertical-align: middle;
border-right: 1px solid #d4d4d4;
}
other {
white-space: pre-wrap;
}
Rowspan probably won't do what you want either. However, there is an alternative but it isn't pretty.
Wrap the content in a div, set its height and set overflow:scroll. This will give the content a scroll bar that the user can scroll up and down.
Below is just an example, so you would want to play with the height to display how you want it to.
<style>
.other{
height:50px;
overflow:scroll
}
</style>
<td>
<div class="other">
content goes here.
</div>
You can also truncate the text (and add an ellipsis) to show that there is more content that what it is shown.
Added simple bonus is that if you add a title attribute to the cell, the full contents of the cell can be shown as kind of like a tooltip
See demo below:
table {
box-sizing: border-box;
border-collapse: collapse;
max-width: 800px;
}
table td,
table th {
vertical-align: middle;
border: 1px solid #d4d4d4;
width: 100px;
max-width: 300px;
}
td.other {
overflow: hidden;
max-width: 300px;
text-overflow: ellipsis;
white-space: nowrap;
}
<h2>sample</h2>
<table class="table">
<thead>
<tr>
<th scope="col">Something</th>
<th scope="col">Code Version</th>
<th scope="col">Region</th>
<!--
<th scope="col">Something</th>
<th scope="col">Something</th>
<th scope="col">Something->Membership</th>
<th scope="col">SBMO</th>
<th scope="col">Something</th>
<th scope="col">IVR</th>
<th scope="col">CPM Something</th>
-->
<th scope="col">Other</th>
</tr>
</thead>
<tbody>
<!-- start loop for mongodb collection: environments-->
<tr>
<td>
something
</td>
<td>
version
</td>
<td>
region
</td>
<!-- other td's go here --->
<!-- CELL WITH MULTIPLE LINES: -->
<td class="other" title="other (multi-line) - this is a very long line that should not wrap around the td">
other (multi-line) - this is a very long line that should not wrap around the td
</td>
<!-- end loop for environments -->
</tr>
</tbody>
</table>
I am trying to implement cellpadding and cellspacing in my forum, but I just can't get the width="100%" to work with it.
Is it possible to set a width while using cellpadding or cellspacing in my CSS?
.categories div.category td tr{
padding: 80px;
width: 500px;
}
echo '
<table class="categories">
<caption>Category: ', $row2['category'], '</caption>
<thead>
<tr>
<td colspan="3">
<th colspan="3"><a href="create_music_sub.php?cat='.$row2['id'].'&admin='.$row2['admin'].'">
Click here to Create Sub Category
</a></th>
</td>
</tr><tr>
<div class="category"><th scope="col">Category</th></div>
<th scope="col">Creator</th>
<th scope="col">Date Created</th>
</tr>
</thead><tbody>';
If what you meant is to set the table's width to 100%, this works.
And as for the code you provided there were mistakes:
When you want to use a th you don't use a td with it.
The div.category should be inside the tr > th not wrapping it.
When you're posting a question please remove the php fragments and provide a working fiddle for us to be able to help you faster.
Please look at the code to see what I did differently. I think the problem was in your html
table{
border:1px solid black;
width: 100%;
}
tr, th, td{
border:1px solid black;
}
td,th{
padding: 10px;
}
/*If you want the last column to be smaller you can change one of them to a certain width*/
.creator{
width:20%;
}
<table class="categories">
<caption>Category: 1</caption>
<thead>
<tr>
<th colspan="3">
Click here to Create Sub Category
</th>
</tr>
<tr>
<th scope="col">
<div class="category">Category</div>
</th>
<th scope="col">Creator</th>
<th scope="col">Date Created</th>
</tr>
<tr>
<th colspan="2" scope="col">
<div class="category">Category</div>
</th>
<th scope="col">Creator</th>
</tr>
</thead>
</table>
<table class="categories">
<caption>Category: 1</caption>
<thead>
<tr>
<th colspan="3">
Click here to Create Sub Category
</th>
</tr>
<tr>
<th scope="col">
<div class="category">Category</div>
</th>
<th scope="col">Creator</th>
<th scope="col">Date Created</th>
</tr>
<tr>
<th colspan="2" scope="col">
<div class="category">Category</div>
</th>
<th scope="col" class="creator">Creator</th>
</tr>
</thead>
</table>
I was trying to set up a table with a fixed header which works fine on all tables except the admin table.
showntable:
<div class="table-responsive">
<table class="table table-bordered" id="showntable">
<thead>
<tr>
<th> Business Unit</th>
<th> Product Group</th>
<th> Device</th>
<th> Serial number</th>
<th> Location</th>
<th> Available?</th>
<th> Condition</th>
<th> Calibration Date</th>
<th> Info</th>
<th> Book</th>
</tr>
</thead>
<tbody id="contents">
<?php echo fill_table($connect); ?>
</tbody>
</table>
</div>
bookedtable:
<div class="table-responsive">
<table class="table table-bordered" id="bookedtable">
<thead>
<tr>
<th>Type</th>
<th>Serial Number</th>
<th>From</th>
<th>Until</th>
<th>Edit Comment</th>
<th>Edit Booking</th>
</tr>
</thead>
<tbody>
<?php echo fill_book($connect); ?>
</tbody>
</table>
</div>
admintable:
<div class="table-responsive">
<table class="table table-bordered" id="admintable">
<thead>
<tr>
<th>Business Unit</th>
<th>Product Group</th>
<th>Device</th>
<th>Serial Number</th>
<th>Condition</th>
<th>Calibration Date</th>
<th>Comment</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php echo fill_admin($connect); ?>
</tbody>
</table>
</div>
CSS:
thead {
display: table;
width: calc(100% - 17px); /* -17px because of the scrollbar width */
}
tbody {
display: block;
max-height: 55vh;
overflow-y: scroll;
}
#showntable th, #showntable td {
width: 10%;
overflow-x:scroll;
}
#bookedtable th, #bookedtable td {
width: 10%;
overflow-x:scroll;
}
#admintable th, #admintable td {
width:10%;
overflow-x:scroll;
}
th {
text-align: center;
}
td {
text-align: center;
}
The #showntable consists of 10 columns, the #bookedtable of 6 and the #admintable of 8 columns. Somehow the width of 10%
for the th and td of the former two seem to work and take up the entire width but the admin table only seems to broaden
when I put the width as 1% for some reason. The thead is correct but the td seems to make problems.
How can I make the admin table the same size?
Also when I resize the browser window to be smaller the columns don't stay the same size. Do you know how to fix these issues?
Cheers
Edit:
Js Fiddle: http://jsfiddle.net/d7crasvh/23/
Its looks fine in Firefox but in IE and Edge it has some issues... :(
Instead of the admin table being wonky as described in the problem it's now the shown table that looks wrong. also the tables are all not aligned, the header and the body i mean
I have a screenshot as show below which I have replicated in Bootstrap 4.
In the screenshot, on row hover the background-color: #EDEDED; shows up.
Here is the fiddle for the above screenshot.
The HTML code which I have used in order to create the table is :
<div class="body-manage-attendees">
<table class="table">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Number</th>
<th scope="col">Table</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Amanda Doe</th>
<td>250</td>
<td>2</td>
<td>Bill</td>
</tr>
<tr>
<th scope="row">Andy Doe</th>
<td>14</td>
<td>1</td>
<td>Bill</td>
</tr>
<tr>
<th scope="row">Cameron Doe</th>
<td>250</td>
<td>4</td>
<td>No Bill</td>
</tr>
<tr>
<th scope="row">Dana Doe</th>
<td>53</td>
<td>5</td>
<td>Bill</td>
</tr>
<tr>
<th scope="row">Fred Doe</th>
<td>250</td>
<td>2</td>
<td>Bill</td>
</tr>
</tbody>
</table>
</div>
Problem Statement:
I am wondering what I need to add in the CSS so that on row hover, the background-color: #EDEDED; appears.
The bootstrap 3 class appears to still work. Try adding the hover class to your table.
<table class="table table-hover">
By doing so, this CSS class from bootstrap is applied:
.table-hover tbody tr:hover {
background-color: rgba(0,0,0,.075);
}
Feel free to override that class and change the color to whatever you wish!
Add .table-hover class to your table:
<table class="table table-hover">
Alterinatively you an also use CSS:
table.table tr:hover td, table.table tr:hover th {
background-color: #EDEDED;
}
Edit: updated JSFiddle
I have a table with this
<table class="table table-striped table-bordered table-hover ">
<thead>
<tr>
<th>
Network Name
</th>
<th>
Abbreviated
</th>
<th>
Description
</th>
<th>
Has Channel
</th>
<th>
IsActive
</th>
<th>Action</th>
</tr>
</thead>
</table>
The output I am getting is like this
I want each of them to be alligned left.
How to do it?
In your browser, right-click one of the table header texts (i.e. “Network name“), click "Inspect element". In the newly opened Developer Tools, click the “Styles“ window.
In the "Styles" tab you can find all rules that are applied to the selected element. One of these rules will contain said text-align: right;. That's the rule that you want to overwrite, i.e. by being more specific than the mentioned rule.
Example
you have a general rule for the table header as in your mentioned case.
table {
width: 300px;
border: 1px solid black;
}
table tr th {
text-align: right;
}
<table>
<tr>
<th>Row header</th>
</tr>
<tr>
<td>Row data</td>
<tr>
</table>
Being more specific can be achieved by using an ID or class, I'll use a class in my example:
table {
width: 300px;
border: 1px solid black;
}
/* existing rule just for illustration */
table tr th {
text-align: right;
}
/* more specific than above rule */
table.left-header tr th {
text-align: left;
}
<table class="left-header">
<tr>
<th>Row header</th>
</tr>
<tr>
<td>Row data</td>
<tr>
</table>
Lets assume your code is working and your bootstrap css is working.. then it should be in one line aligned left but in your case if not Bootstrap has a class that could do it : class="text-left"
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<table class="table table-striped table-bordered table-hover pull-left">
<thead>
<tr>
<th class="text-left">
Network Name
</th>
<th class="text-left">
Abbreviated
</th>
<th class="text-right">
Description
</th>
<th class="text-left">
Has Channel
</th>
<th class="text-left">
IsActive
</th>
<th class="text-left">Action</th>
</tr>
</thead>
</table>
i would not prefer adding the class to each th but its a solution since you dont really provide code to work with.
Description is aligned right just to give you an idea of whats happening. just by adding classes using bootstrap.
text-align: left;
This property is used for aligning text left. Kindly inspect and find the class which has text-align: right; and change it.
You can add a class to th element then style the class:
<th class="align-to-left">
.align-to-left{
text-align:left;
}