I have a table, a few elements have input elements inside them. I have set the following properties for the input elements.
table input{
width:inherit;
margin:1px;
overflow:hidden;
}
Now i want the cell size to determine the input element size, hence the inherit property. But because i have a margin set on them, they were popping out of the cells a little. So i added the overflow:hidden property, but thats not helping.
What am i doing wrong?
Edit:Code Added
<div>
<form>
<table>
<tr>
<th class="tinycolumn">S.no</th>
<th>Part Name</th>
<th>Part number</th>
<th class="tinycolumn">Qty</th>
<th>New/Repair</th>
<th>MRP</th>
<th>Denting/Fitting</th>
<th>Painting</th>
<th></th>
</tr>
<tr>
<td>1.</td>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="number" min="0"></td>
<td><select><option value="new">New</option><option value="repair">Repair</option></select></td>
<td><input type="text"></td>
<td><input type="tel"></td>
<td><input type="tel"></td>
<td><button>Delete</button></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><button>Add</button></td>
</tr>
</table>
<input type="submit">
</form>
</div>
Supporting CSS
#estimatetable{
display:inline-block;
width:80%;
margin:1em auto 1em auto;
overflow:hidden;
}
#estimatetable form{
width:auto;
}
#estimatetable form table{
text-align:center;
width:100%;
}
#estimatetable tr{
min-height:3em;
}
#estimatetable form table tr td, #estimatetable form table tr th{
border:1px solid rgb(0,0,0);
max-width:2em;
padding:1px;
}
#estimatetable input, #estimatetable select{
width:inherit;
margin:1px;
overflow:hidden;
}
#estimatetable button{
width:100%;
}
#estimatetable .tinycolumn{
max-width:.5em;
}
Your CSS says : input inherits width of parent.
In regular box model, borders are added to width.
Using box-sizing:border-box; , border and padding will be included in total width of element.
Your CSS can be fixed this way :
table input{
width:inherit;
box-sizing:border-box; /* add vendor prefix or a script to do so if needed */
}
If you still wish to use the margin:1px; you should turn it into padding:1px; to parent element (td) and apply to it as well the box-sizing propertie.
DEMO
Related
I have a table within a table. I have set table background-color to white.
The inner table's background is to remain white while all other cells of the outer table are set to lightgrey.
However, the outer table's white background-color is showing up as a border around all its <td> cells which I cannot figure out how to get rid of - all grey cells should be borderless. I have tried setting the border property of all elements to none without success. Any help would be appreciated.
Here is a jsfiddle
<style>
body{
background-color: lightcyan;
}
.gems {
margin:0 8px;
padding:0;
}
.gems table{
width:100%;
background-color:white;
}
.gems td {
padding:0px 1px;
margin:0;
}
.gems tr.filelist {
margin:5px;
background-color: lightgrey;
}
.gems tr.tools {
background-color: lightgrey;
}
div.textarea {
background-color: white;
}
</style>
<body>
<div class="gems">
<table>
<tr class="filelist">
<td>filelist</td>
<td>filelist</td>
</tr>
<tr class="tools">
<td>tools</td>
<td>
<div class="textarea">
This is a table
<table>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</body>
<table cellspacing="0">
Add this property in your table tag.
Here I want to add background color to the column Sunday without adding css class to it. Can we achieve it without adding a css class and inline style? Here's a sample Fiddle
/------------------HTML----------------/
<table>
<tr>
<td>Sun</td>
<td>Mon</td>
<td>Tue</td>
<td>Wed</td>
<td>Thurs</td>
<td>Fri</td>
<td>Sat</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
</table>
/------------------CSS----------------/
table{
border:1px solid #ccc;
border-collapse:collapse;
padding:5px;
}
table td{
background:#f6f6f6;
padding:3px;
border:1px solid #ccc;
}
Yes you can:
td:first-of-type will select first td i.e. first cell of all rows.
table tr td:first-of-type{//your code}
Updated fiddle here.
http://jsfiddle.net/uQRA9/2/
Yes you can.
For example :
table td:first-child {
background: red;
}
table td:nth-child(4) {
background: blue;
}
Yes using :first-child pseudo class.
table tr:first-child > td:first-child{
background-color :red;
}
The above one is for older browsers. You can also use first-of-type as shown by Hiral.
Working Fiddle
use like this
tr>td:nth-child(1){
background-color:red;
}
you can style sun column and all under it with this
table td:first-child{
background-color :red;
}
demo
You can manage by css, :nth-child(0) property provides selector specified index (0,....., n)
table td:nth-child(0){
background:#f6f6f6;
padding:3px;
border:1px solid #ccc;
}
AND
table tr:nth-child(0){
background:#f6f6f6;
}
table tr:first-child td:first-child {
background:...;
...
}
Im creating a responsive table which contains a vertical divider. I want that divider to move along with the text according to all screen sizes. left and right td are responsive just the divider is creating problem.
The CSS is
.divider{
position: absolute;
left:30.5%;
top:6%;
bottom:25%;
border-left:2px solid #333;
overflow:hidden;
}
and the related html is
<table width="100%">
<tr>
<td>
this is test
</td>
<td><div class="divider"></div></td>
<td>
This is test2
</td>
</tr>
</table>
The problem is when I change the position from absolute to anything else in css it hides the divider.
In your case....its happening because i feel that your are giving position only to the div and not the containing <td>....give this parent td a position first
add height, width to html,body and your are good to go...
solution
CSS
html, body {
height:100%; /* added */
width:100%;/* added */
}
.divider {
position: relative; /* changed*/
left:30.5%;
top:6%;
bottom:25%;
border-left:2px solid #333;
overflow:hidden;
}
td.r {
position:absolute;/* added */
height:100%;/* added */
width:100%;/* added */
}
HTML
<table width="100%" border=1>
<tr>
<td>this is test</td>
<td class="r"> <!-- notice the added class-->
<div class="divider"></div>
</td>
<td>This is test2</td>
</tr>
</table>
EDIT
A much simpler and cleaner way to create divider is to use td only for divider, not the div....check this demo
Remove the div creating the divider and instead, add the divider class to td itself!
<table width="100%" border=0>
<tr>
<td>this is test</td>
<td class="divider"></td>
<td>This is test2</td>
</tr>
</table>
CSS
td {
text-align:center
}
td.divider {
position:absolute;
height:100%;
width:1px;
border:1px solid #000;
background:#000;
}
Just to frame you. Look at the following code.
Basically I have a table inside a div. When the table gets too big the overflow hidden triggers.
PROBLEM: in IE6 the "some text" gets hidden as expected but the floated span not.
Is there a way around of fix it?
#wrap{
overflow:hidden;
height:20px
}
span{
float:left;
height:10px;
width:10px;
background:url(image.jpg) no-repeat 0 0;
}
<div id="wrap">
<table>
<tr>
<td><span></span> some text</td>
</tr>
<tr>
<td><span></span> some text</td>
</tr>
<tr>
<td><span></span> some text</td>
</tr>
</table>
</div>
Try giving height:1%; for ie6 css. as below.
wrap{
overflow:hidden;
height:%;
}
Say for example I have:
<div id="container">
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
And
td { width:10px; height:10px; }
What I want to do is apply a style to the first td, of the first table.
I would have expected:
#container table:first-child td:first-child {
background: red;
}
However it does not work? Please advise!
#container table:first-child tr:first-child td:first-child { background: red; }
Seems to work.
Note that under IE, you will need to have a !DOCTYPE declaration in your html to get support for :first-child. http://www.w3schools.com/cssref/sel_firstchild.asp
To select only the first table within the div:
div#container table:nth-child(1) tr td {
color: #888;
}
To select only the first td of the first table within the div:
div#container table:nth-child(1) tr td:nth-child(1) {
color: #444;
}
For me this works easier if you want to change it to a second table or second tablecell
div#container table:nth-child(2) tr:nth-child(4) td:nth-child(1) {
color: #888;
}