CSS Table formatting with multiple items in one td - html

So I am working on a form. And part of how I want the form to function requires a select box and an input(text) box in the same tr. The other items in that tr are just text boxes. I am having a problem getting the text box that shares a tr with the select to go to where the solo text box goes. Therefore, the right edges do not line up.
What I am looking for...
1) I want the text boxes that are solo to fill the box, ideally without adding width. I am fine with a min width of 550px, but not necessary.
2) I want the text boxes that are with the select to fill the rest of the box, meeting the same edge as the solo boxes. Satisfying OCD...
CSS for the table:
table, th, td {
border: 1px solid var(--main-color);
padding: 6px 8px;
white-space: nowrap;
}
table {
border-collapse: collapse;
table-layout: fixed;
}
thead {
background-color: #333;
border-bottom: 3px solid var(--main-color);
}
thead th, thead a, thead a:visited {
color: white;
}
th.active {
background: var(--main-color);
}
table > :not(thead) tr th {
background-color: #333;
border-right: 3px solid var(--main-color);
color: white;
text-align: right;
}
tr {
height: auto;
}
td {
color: black;
}
table input {
width:100%; /* simply scale inputs to table cell size */
}
td.input-group input {
width:auto; /* but not for radios or checks */
}
HTML (shortened, just one solo text box and one that is sharing with the select):
<table>
<tr>
<td>Serial Number: </td>
<td><input type="text" name="device-serial-number" maxlength="8" required></td>
</tr>
<tr>
<td>MAC Address NIC: </td>
<td>
<select name="media-nic">
<option value="">Media</option>
<option value="eth">Ethernet</option>
<option value="inf">Infiniband</option>
<option value="fib">Fiber</option>
</select>
<input type="text" name="mac-nic" maxlength="17">
</td>
</tr>
</table>
Fiddle with more CSS and such: https://jsfiddle.net/2o0sn4ep/

You could use the trick marked as correct answer in this question
Using this nice "trick" I modified a bit your css and html (I added a div container to wrap your second input).
It's responsive as well, your inputs will always fill whatever width remaining in the container
:root {
--main-color: rgb(46, 58, 150);
}
* {
box-sizing: border-box;
}
table,
th,
td {
border: 1px solid var(--main-color);
padding: 6px 8px;
white-space: nowrap;
}
table {
border-collapse: collapse;
table-layout: fixed;
}
thead {
background-color: #333;
border-bottom: 3px solid var(--main-color);
}
thead th,
thead a,
thead a:visited {
color: white;
}
th.active {
background: var(--main-color);
}
table >:not(thead) tr th {
background-color: #333;
border-right: 3px solid var(--main-color);
color: white;
text-align: right;
}
tr {
height: auto;
}
td:first-child {
text-align: right;
}
td {
color: black;
}
input[type=text] {
padding: 9px 10px;
font-size: 16px;
width: 100%;
}
select {
padding: 9px 10px;
font-size: 16px;
height: 41px;
float: left;
margin-right: 5px;
}
option {
padding-top: 2px;
padding-bottom: 2px;
}
div {
width: auto;
overflow: hidden;
}
<table>
<tr>
<td>Serial Number: </td>
<td>
<input type="text" maxlength="8" required>
</td>
</tr>
<tr>
<td>MAC Address NIC: </td>
<td>
<select>
<option value="">Media</option>
<option value="eth">Ethernet</option>
<option value="inf">Infiniband</option>
<option value="fib">Fiber</option>
</select>
<div>
<input type="text" maxlength="17">
</div>
</td>
</tr>
</table>

Related

Table CSS styling | Borders

I really need some help with CSS.
I'm trying to style a table and I'm having difficulties adding borders.
Here's the table style I'm going for (Photoshopped): https://ibb.co/hFkCkDg
Adding a border around the table is simple:
.table-class {
border: 1px solid #dddddd !important;
padding: 20px !important;
border-radius: 5px;
}
Screenshot: https://ibb.co/Fs6qsNv
To add the separating lines inside the table I need to add a top or bottom border to the rows in the table. Rows are tr elements. By default a tr element of a table does not accept borders. So in order to overcome this I added {border-collapse: collapse !important;} to the whole table which allowed me to add borders to rows, but it messed up the border around the whole table. Screenshot: https://ibb.co/Vgfq9jp
Because of {border-collapse: collapse !important;}, the properties border, padding, border-radius don't work for the table.
Which means I can either add a border around the whole table or add the separating lines, but not both.
How can I achieve the look I'm going for?
I'd go using flexbox, and setting flex: 1 or flex-grow: 1 to the first child of each "row":
* {margin:0; box-sizing: border-box;}
body {font: 16px/1.4 'Varela Round', sans-serif; padding: 20px;} /* DEMO ONLY */
/*
Order
*/
.Order {
border-radius: 5px;
border: 1px solid #ddd;
padding: 10px 25px
}
.Order-price {
display: flex;
border-bottom: 1px solid #ddd;
}
.Order-price > * {
padding: 10px 0;
}
.Order-price > *:first-child{
flex: 1;
}
.Order-price:last-child {
border-bottom: none;
}
.Order-price--sub {
font-size: 1.2em;
font-weight: 500;
}
.Order-price--tot {
font-size: 1.4em;
font-weight: 700;
}
/*
Colors
*/
.color-lighter {
color: #999;
}
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Varela+Round&display=swap" rel="stylesheet">
<div class="Order">
<div class="Order-price">
<span class="color-lighter">Custom Tatoo Design - Small × 1</span>
<span><s class="color-lighter">$99.00</s> <b>$80.00</b></span>
</div>
<div class="Order-price Order-price--sub">
<span>Subtotal</span>
<span>$80.00</span>
</div>
<div class="Order-price Order-price--tot">
<span>Total</span>
<span><small>USD</small> $80.00</span>
</div>
</div>
working with table border is boring, my suggestion is to use the border in td/th elements.
I created this table without style, only solving the problem of borders
.table-class {
border: 1px solid #dddddd;
border-radius: 6px;
padding: 30px;
border-spacing: unset;
font-family: sans-serif;
font-size: 1.5em;
}
.table-class thead th {
border-bottom: 1px solid #dddddd;
text-align: left;
}
.table-class tbody td {
border-bottom: 1px solid #dddddd;
}
.table-class td:last-child, .table-class th:last-child {
text-align: right;
}
.table-class th, .table-class td{
padding: 10px;
}
<table class="table-class">
<thead>
<tr>
<th>Custom Tattoo Desing - Small x 1</th>
<th>
<span><s>$99.00</s></span>
<span>$80.00</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Subtotal</td>
<td>$80.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>USD $80.00</td>
</tr>
</tfoot>
</table>

Highlight a row on Click not working. CSS precedence

Here's the table in my html file. I have to highlight a row on click.
<tbody>
<!--display none-->
<!--onclick-->
<tr ng-repeat="case in lastten" ng-click="setSelected(case.Name)" ng-class="{selected: case.Name === idSelected}">
<td colspan="1">{{case.Name}}</td>
<td colspan="1">{{case.total}}</td>
<td colspan="1">{{case.passed}}</td>
<td colspan="1">{{case.failed}}</td>
</tr>
</tbody>
css- initialTable is the class for the above table
table.InitialTable {
table-layout: fixed;
width: 100%;
font-family: Helvetica, Arial, sans-serif;
margin-top: 20px;
margin-bottom: 20px;
border-collapse: collapse;
border-spacing: 0;
}
table.InitialTable td,
th {
border: 1px solid transparent;
height: 40px;
transition: all 0.3s;
overflow: hidden;
}
table.InitialTable th {
font-weight: bold;
text-align: center;
vertical-align: middle;
}
table.InitialTable td {
text-align: center;
vertical-align: middle;
}
table.InitialTable tr:nth-child(even) {
background: #f3f7fb;
}
table.InitialTable tr:nth-child(odd) {
background: #ffffff;
}
.InitialTable tr:hover td {
background: #eee;
}
.selected {
background: red;
}
Here's the angular code-
$scope.idSelected = null;
$scope.setSelected = function(idSelected) {
$scope.idSelected = idSelected;
};
So basically whenever a row is selected it gets the class selected and it should be highlighted. But the css is not working. So is the precedence of .selected below the hover ? I also tried a lot of other combinations , but it didn't work. Even important isn't working . I've been stuck at this for quite a while now .

Enforce CSS class to all elements in a table

I have a css which works perfectly:
.border
{
border: 1px solid black;
font-size: 12px;
padding: 2px;
vertical-align: top;
text-align: left;
}
.clean
{
border: none;
font-size: 14px;
}
No problem. But to create a table with border I will have to do:
<table class="border">
<tr>
<td class="border"></td>
<td class="border"></td>
</tr>
I find this brutally tedious. Isn't there a way to go:
<table class="border">
<tr><td></td><td></td></tr>
with the same result as the above?
I want an "excel-like" square grid, not only a border around the table (second example).
Pls help.
Yes there is:
.border { /* matches all element with that class */
border-collapse: collapse; /* excel like (collapse cells border together) */
border:1px solid black;
font-size: 12px;
padding: 2px;
vertical-align: top;
text-align: left;
}
.border td { /* matches all td which have "border" in a parent class element */
border:1px solid black;
font-size: 12px;
padding: 2px;
vertical-align: top;
text-align: left;
}
`
You don't need to apply the class inside all your tds. Just use like this:
table.border,table.border td{//Applying border in table html
border: 1px solid black;
}

How do I select the “last child” of tr in my class should have no background styles

Here is the Working code, I just want to have the last child for tr should be clean without any css.
Here is my working FIDDLE
Html
<form id="frmAdmin" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Create Heading Details</legend>
<table class="admin-table">
<tbody><tr>
<td>Title</td>
<td><input id="Footer" name="Footer" type="text" value="">
<tr>
<td>Priority</td>
<td><input data-val="true" data-val-number="The field Priority must be a number." id="Priority" name="Priority" type="text" value="">
<tr>
<td></td>
<td><input type="submit" value="Save">
CSS
form {
height: 100%;
margin: 0px;
}
fieldset {
width: 79%;
border: 1px solid lightgrey;
border-radius: 10px;
margin-top: 20px;
}
.admin-table {
width: 100%;
}
.admin-table td {
background-color: grey;
border-bottom: 1px solid lightgrey;
height: 60px;
}
.admin-table tr:last-child {
text-decoration: none;
}
My output comes likes this:
But my expected output is as like this image:
Apply the changes to td:
.admin-table tr:last-child td {
text-decoration: none;
background:#ffffff;
border:0;
}
fiddle
Try this code
.admin-table tr:last-child td{
background: none;
border-color:transparent;
}
Check this Demo
use below css
.admin-table tr:last-child td {
background: none;
}
fiddle http://jsfiddle.net/S5tB7/3/
See this Fiddle.
You need to apply the background-color change to the td elements of the last row -- since that is where you apply the yellow color in the first place.
.admin-table tr:last-child td {
text-decoration: none;
background-color: initial;
border:none;
}
Note that if you want the background color not just to be white, but to actually be "start" color, then set it to initial (documentation).
.admin-table tr:last-child td
{
background:none;
}
you didnt set up any background color
body {background-color:white;}
h1 {background-color:#00ff00;}
p {background-color:rgb(255,0,255);}

Internet Explorer background-color hover problem

I have a strange Problem with table formating using IE 7.
My table looks like this:
In IE, when using border-collapse, the borders don't get displayed correctly. That's why I used this fix:
.table-vmlist td { border-top: 1px solid black; }
td.col-vm-status, tr.row-details td { border-left: 1px solid black; }
td.col-vm-rdp, tr.row-details td { border-right: 1px solid black; }
.table-vmlist { border-bottom: 1px solid black;}
When hovering over the row, it gets highlighted with CSS:
.table-vmlist tr.row-vm { background-color: #A4C3EF; }
.table-vmlist tr.row-vm:hover { background-color: #91BAEF; }
Now, in IE 7, when moving the mouse from the top to the bottom of the list, every row gets highlighted correctly and no problems happen. But if I move my mouse pointer from the bottom of the list to the top, every second row seems to loose the border.
Can someone explain what the problem is, and how to solve it?
This is my markup:
<tr class="row-vm">
<td class="col-vm-status status-1"><img title="Host Down" alt="Down" src="/Technik/vm-management/img/hoststatus_1.png"></td>
<td class="col-vm-name">V1-VM-1</td>
<td class="col-vm-stati">
<img title="Ping" alt="Ping status" src="/Technik/vm-management/img/servicestatus_3.png">
<img title="CPU" alt="CPU status" src="/Technik/vm-management/img/servicestatus_3.png">
<img title="RAM" alt="RAM status" src="/Technik/vm-management/img/servicestatus_3.png">
<img title="C:\ Diskspace" alt="Disk space status" src="/Technik/vm-management/img/servicestatus_3.png">
</td>
<td class="col-vm-owner">kus</td>
<td class="col-vm-purpose">Citrix Testserver</td>
<td class="col-vm-ip">-</td>
<td class="col-vm-uptime">-</td>
<td class="col-vm-rdp"> </td>
</tr>
And the CSS:
/* VM-Tabelle formatieren */
.table-vmlist { border-collapse: collapse; }
.table-vmlist tr { border: 1px solid black; }
.table-vmlist tr.row-header { border: none; }
.table-vmlist tr.row-vm { background-color: #A4C3EF; }
.table-vmlist tr.row-vm:hover { background-color: #91BAEF; }
.table-vmlist th { text-align: left; }
.table-vmlist td { }
.table-vmlist th, table td { padding: 2px 0px; }
/* Spaltenbreite der VM-Tabelle festlegen */
.table-vmlist #col-status { width: 25px; }
.table-vmlist #col-stati { width: 90px; }
.table-vmlist #col-owner { width: 90px; }
.table-vmlist #col-ip { width: 100px; }
.table-vmlist #col-uptime { width: 70px; }
.table-vmlist #col-rdp { width: 25px; }
.table-vmlist tr.row-details td { padding: 0px 10px; }
/* Kein Rahmen um verlinkte Bilder */
a img { border-width: 0px; }
/* Für Einschaltknopf Hand-Cursor anstatt normalen Pfeil anzeigen */
td.status-1 img { cursor: pointer; }
img.ajax-loader { margin-left: 2px; }
IE fix:
.table-vmlist td { border-top: 1px solid black; }
td.col-vm-status, tr.row-details td { border-left: 1px solid black; }
td.col-vm-rdp, tr.row-details td { border-right: 1px solid black; }
.table-vmlist { border-bottom: 1px solid black;}
Just a thought, but the :hover selector may not be working on ie7 depending on your DOCTYPE. More info here:
http://social.msdn.microsoft.com/forums/en-US/iewebdevelopment/thread/619c4492-ab7b-4a8e-b911-5fed8aa49457/