How to create a table with fixed layout? - html

Hai ,
I am using a html table for my website layout .
when we press enter in one cell , the cell is resizing.
I used css for fixing the table layout. table layout is not changing .But cell is resizing.
.pageContent table
{
height:100%;
width:100%;
table-layout:fixed;
}
.pageContent table tr td
{
padding:5px 10px 5px 10px;
}
how to prevent this resizing of table cells ?

Your table is re-sizing because you are using proportional widths.
There are many ways you can control this. For example, by setting your or height in pixels:
CSS:
table td {height: 20px;}
Your cells will no longer re-size vertically.

Have you tried adding the following CSS
td { overflow:hidden;white-space:nowrap; }
tr { height:1em; } /* or set an appropriate height and width */
This will hide the overflow in the cells however, but they won't resize.
Your layout might be easier to do with semantically correct HTML, using <div> elements but would need to see the markup.

It's hard to be sure, but you haven't set a size on the td in question, only padding. So the td will be expanding to contain whatever is inside it. In some browsers this might change a wee bit with focus.
Could you try setting an explicit width and height (in ems or pixels) for the td?
.pageContent table tr td
{
padding: 5px 10px 5px 10px;
width:8em;
height:2em;
}
Could you post a bit of your markup, or let us know what the content in the cells is? (And which browsers you're seeing the problem in).

Related

CSS on table not loading until I refresh

I have a table with a padding of 25% on the th and td.
However; the padding does not apply unless I refresh the page with CTRL + SHIFT + R. How come?
Example CSS:
table.foo {
border: 0;
margin: auto;
color: #545454;
margin-top: 30px;
}
th, td {
text-align: left;
padding-right: 25%;
}
th:last-of-type, td:last-of-type {
padding-right: 0;
}
It's the padding-right: 25% that I use for getting some horizontal space between the cells.
Why is this happening? Is padding not the correct way of doing this?
UPDATE: After testing to keep refreshing the page, I noticed that the spacing changes each time..? Like it's setting itself on a spacing from 0 - 25%
Padding percentages "refer to the width of the containing block". As you cannot set the width of a tr, it doesn't work. Even if it seems to work it is not cross-browser solution. I suggest to set the cells padding in px or to use a div inside cells and set padding in percentages to it.
Just to be clear is your doubt based on the CTRL+SHIFT+R, or just simply refreshing?
For the latter, I believe to my knowledge, CSS will not produce its changes dynamically. That is, as mentioned in your problem, you will have to refresh the page every time you make a change in your CSS coding.
Hope this is the answer you are looking for.

how do I make button, input fill entire table cell? slight gaps are left

I am trying to fill an entire table cell with a button and another cell with a drop-down list.
If you have a look at my JSFiddle, I am having troubles with a slight gap between the cells and the table border.
I have tried several different approaches but I can't seem to figure out how to remove the gap.
Any help with this would be appreciated. Thank you!
input, select {
margin:0;
padding:0;
height:100%;
width:100%;
}
JSFiddle
If you mean the big spaces above and below the input and select box then you can solve this by adding height:auto to tr tag instead of height: 100px.
If you mean that you want the input and select to touch the border then you can add padding: 0px to td tag.
JSFiddle
Your padding:0 need to be on td, not tr, so
td {
padding: 0;
}
and with the button, the browser builds in a space for styling, so if you want it to be full you can do:
input[type=button]{
border: solid 1px #ccc;
}
you will lose the 3d effect on the button though

Table width 100% is off by a single pixel (depending on actual width)

I have a table in a div inside another div. The direct container has a width of 40%, and I want the table to be as wide as this div, by setting width: 100%.
Relevant Markup
This works most of the time, however depending on the width of the browser window, the width of the table is sometimes off by a single pixel:
As you can see to the right, the border is a pixel to the left of that of the sibling div .info. These borders should align.
Relevant CSS
#userListContainer{width: 40%; float: left; }
.info{display:block;line-height:22px; height:22px; padding-left:10px; }
#userListContainer .info {border-right: 1px solid #999999;}
.userList {
width: 100%;
border-right: 1px solid #999999;
word-break: break-all; border-spacing: 0;
border-collapse: separate;
}
Seems like a rendering bug to me. It occurs in Chrome 34.0.1847.131, not in IE10. I can't reproduce it in IE10 or the current version of FireFox.
The error replicates here for me on CHROME.
I inspected the element, and what I noticed is, the width of the table box was 217.443 px (obviously due to the % widths)
in the inspect element HTML section, it defines the width of the table as 218 px, and the containing div as 217px..
When I expand the broswer window slightly, thus making the table width increase past 217.443 px, to 217.680 px,
the HTML section displays BOTH the table width and the containing div as 218 px.
so im guessing the browser is rounding the pixels off to the nearest whole pixel.
could this be the right route to investigate?
edit: Try this and see if this works for you. I have fixed the problem (I think) in this jfiddle
http://jsfiddle.net/E2mUQ/3/
I simply removed the width on the .table class, and relaced it with DISPLAY:block
I had the same problem and managed to solve it by setting the width slightly higher:
width: 100.12%
I made an attempt to make the extra percentage small enough to solve most cases, but not create an overflow of 1 px.
It worked for me. This is somewhat of a dirty fix though.
I think it's to do with inset/outset borders - which are different between browsers. Try applying a border to the parent div instead of the table. This should sort it out.

How to change table width

I am trying to decrease a table width to 700px
the table is underneath < h2>Cart Totals< /h2> and no matter how I apply "width: 700px;" the table will not decrease in size.
http://clients.rocoru.com/trendyheadboards/?page_id=6
Your problem is the following rule in master.css, line 687:
#costing-container, .shipping {
width: 980px;
border-top: 1px dotted #ccc;
}
Your applied the shippingclass to a tr inside your table, thus stretching it to 980px. If your remove that class or change its width-rule to 700px your table will display like you want it to.
The answer provided by Johannes sounds correct, but if you do not want to modify the master.css file, try applying an id to the table in question and change the other css to
#table_id tr {
width: 700px !important;
}
This should ensure that your styling doesn't shrink other table elements.

Force TR height in HTML

I am trying to force a table row that only contains images to be the images' height, but the page always displays a few extra pixels tall.
See http://www.slamgmt.com/newsite/index.php
Also http://www.slamgmt.com/newsite/sla.css
The banner at the top uses CSS classes "banner" and "bannersidebar" all of which explicitly set the height, but the actual height is too large, as seen by the white space below the banner and above the black line.
Does anyone know a way to force it to trim that space?
add display:block to the header image, that should fix it...
img.topbanner
{
max-width:100%;
border:0px;
display: block;
}
I don't think I've ever given a height to a tr, it just becomes as tall as the td within.
Also, you're defining a tr height of 192, but the td is 194, taking into account for the 2px border.
tr.banner
{
height:192px;
max-height:192px;
}
td.banner
{
height:192px;
max-height:192px;
border-bottom:2px solid black;
}
I believe img tags add a slight margin around them. Try setting the margin:0px on the img and see if that gets rid of your issue.