How to change table width using css - css

Html
<table style='width: 150px; border: 1px solid black;'>
<tr>
<td>blablabla</td>
<td>blablabla</td>
</tr>
<tr>
<td>abcd</td>
<td>abcd</td>
</tr>
</table>
I want to change the table width to 600px. I couldnt figure out the selector for changing width.
Please help , i am learning css.

Just do like this
HTML
<table style='width: 150px; border: 1px solid black;'>
<tr>
<td>blablabla</td>
<td>blablabla</td>
</tr>
<tr>
<td>abcd</td>
<td>abcd</td>
</tr>
</table>
CSS
table {
width:600px!important;
border:1px solid black;
}

Change the width value in the style attribute.
<table style="width: 600px;">
yields a table that is 600px wide.

You should use like this -
table [style]{width:600px !important}

It is specified inline right there in your code.
<table style='width: 150px; border: 1px solid black;'>
change this
<table style='width: 600px; border: 1px solid black;'>
Alternatively
Use a class in your table and use the selector in your css file.
<table class="tbl" style='width: 150px; border: 1px solid black;'>
CSS
.tbl{width:600px!important} /*!important override inline css 150px*/
If you can remove the inline css used in table, you need not to use !important like this-
<table class='tbl'>
CSS
.tbl{width:600px}

To those who width !important didnt work, try also changing min-width and setting it to !important.
.myCssTable {
width: 80% !important;
min-width: 80% !important;
}

Related

How to add margins between rows of gridview

I have a gridview and I'm trying to add empty space between each row using CSS.
This doesn't work:
#gridview tr{
margin-bottom: 10px;
}
Neither does this:
#gridview td{
margin-bottom: 10px;
}
Messing with "border-collapse" does nothing as well.
Anyone know how to add spacing?
Margin will not work in table elements you should use border or padding like the following snippet
table.grid
{
border-collapse: collapse;
}
table.grid tr
{
border: 0px solid white;
border-width: 20px 0;
}
<table class="grid ">
<tr>
<td>
Row 1
</td>
</tr>
<tr>
<td>
Row 2
</td>
</tr>
</table>
You can use it in GridView like this:
<asp:GridView ID="PetGrid" runat="server" CssClass="grid">
use padding:
#gridview td{
padding-bottom: 10px;
}
Use padding in th and td,
th, td {
padding: 15px;
}
Try this
table td {
border-bottom: solid 20px transparent;
}
<table>
<tr>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
</tr>
</table>
Which gridview are you using? try "inspect element" on the grid row and check from which .css class the style is getting inherited. try changing some parameters like padding/row height and observe if that works and make the change in the grid's library css or ovverride it with custom class.
#gridview tr{
{
height: 18px;text-align: left;font-weight: bold;color:white;padding: 5px 6px 2px;border-bottom: 2px solid #666666;white-space: nowrap;
}
In specifications margin are ignored for table cells: Link
Try to use padding
#gridview td{
padding-bottom: 10px;
}

CSS Table Formatting Problems

I'm having some trouble formatting a table! I want to make a table in which all the cells stay at an equal width and height. In other words, so they don't overflow.
I can make it so that the cells don't overflow in the x-axis, by using table-layout:fixed, but I'm having some trouble preventing the cells overflowing in the y-axis. I want this to be hidden as well, but for some reason the CSS isn't co-operating with me!
I won't go into detail, as this isn't related to the problem I'm having, but I'm not looking for an absolute solution such as having a height:50px style. I would like a general solution to prevent this overflow, please!
I've provided some sample CSS and HTML below. Please let me know if you need any clarifications! http://jsfiddle.net/pdtua295/1/
CSS
table.pztable {
border-collapse:separate;
table-layout:fixed;
overflow:hidden;
margin:0px;
width:100px;
height:100px;
}
td.pzcol {
border:1px dotted #2F2F2F;
padding: 0px 2px 5px 2px;
text-align:center;
vertical-align:middle;
}
span.pztext {
font-family:Tahoma;
}
HTML
...
<table class="pztable">
<tbody>
<tr>
<td class="pzcol">
<span class="pztext">Alice</span>
</td>
<td class="pzcol">
<span class="pztext">Bob</span>
</td>
</tr>
<tr>
<td class="pzcol">
<span class="pztext">S<br>T<br>R<br>E<br>T<br>C<br>H</span>
</td>
<td class="pzcol">
<span class="pztext">This won't stretch horizontally.</span>
</td>
</tr>
</tbody>
</table>
...
try this
word-wrap: break-word;
this will break even word
[I edited your code][1]
[1]: http://jsfiddle.net/pdtua295/1/
This isn't tested, but in the CSS for the td your should add height: 50px; white-space: nowrap; overflow: ellipsis; that should do it.
Replace your css with
give min width and max-width to table td like
`table.pztable{
border-collapse:separate;
table-layout:fixed;
overflow:hidden;
margin:0px;
}
td.pzcol{
border:1px dotted #2F2F2F;
padding: 0px 2px 5px 2px;
text-align:center;
min-width:150px;
max-width:150px;
}`

Alignment for 2nd row data

<table>
<tr><td>test</td></tr>
<tr>
<td>
<div style= height:200px;">
<div style="border:1px solid yellow; display: inline-block; width:100px">
<img src="orderedList4.png">
</div>
<div align="center" style="border:1px solid green; display: inline-block; width:650px;height:100px;">
<div>center Test Header1</div>
<div>center Test Header2</div>
</div>
<div align="right" style="border:1px solid red;display: inline-block; width:100px">REL 1.0</div>
</div>
</td>
</tr>
</table>
In the above code, the image size is 75*75 pixels.
I want to have all the three cells to have a height of 100 pixels.
I want the image to be centered and left aligned.
The middle text to centered.
Third text to centered and right aligned.
I could not make it working.
Inline styles are a nightmare to maintain, and you should generally be trying to keep presentation separate from the content. I've moved all the styles out of the actual tags, and since you're using a table and refer to each div as a cell, I'm guessing you meant to have each one an actual cell.
<style>
.product_table {
width: 850px;
}
.product_table td {
height: 100px;
border: solid 1px #000;
vertical-align: middle;
}
.product_table .image {
width: 100px;
border-color: yellow;
text-align: left;
}
.product_table .title {
/* Automatically sizes its width */
border-color: green;
text-align: center;
}
.product_table .release {
width: 100px;
border-color: red;
text-align: right;
}
</style>
<table class="product_table">
<tr>
<th colspan="3">test</th>
</tr>
<tr>
<td class="image">
<img src="orderedList4.png" />
</td>
<td class="title">
<div>center Test Header1</div>
<div>center Test Header2</div>
</td>
<td class="release">
REL 1.0
</td>
</tr>
</table>
The top row is probably a table heading though, so you should consider moving that out of the table as a h2 or whatever level it'll be used in. And make sure a table is the most appropriate element here – unless you're going to have multiple rows of whatever this item is, you might be better off just using divs without tables.

Adding a wide enough textarea in a `tr` affects the calculation of `td` width?

I have a DOM structure like the following:
<table class="playlist">
<thead>
<tr>
<th>TH1</th>
<th width="53">TH2</th>
<th width="53">TH3</th>
<th width="53">TH4</th>
<th width="53">TH5</th>
<th width="53">TH6</th>
</tr>
</thead>
<tbody>
<tr>
<td>TD1</td>
<td>TD2</td>
<td>TD3</td>
<td>TD4</td>
<td>TD5</td>
<td>TD6</td>
</tr>
<tr class="expansion">
<td class="expansion" colspan="6">
<div class="comment_wrapper">
<form>
<textarea style="width=482px" class="mini">x</textarea>
</form>
</div>
</td>
</tr>
</tbody>
</table>
Related style rules are like:
table {
width: 580px;
border-bottom: 1px solid #EEE;
}
.comment_wrapper {
height: 270px;
border: 1px red solid;
overflow-x: hidden;
overflow-y: auto;
}
.comment_wrapper form textarea {
height: 70px;
width: 482px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
border: 1px red solid;
}
My problem is that whenever I added the second tr, width of table columns changed into a mess like the following in IE6/7.
When I comment out this tr, the column width restore.
Why does adding a tr affects column width? How can I avoid this effect?
PS
I've reproduced this problem on JSFiddle, and this is the link: http://jsfiddle.net/7mYY8/1/
Well, you have 6 columns 5 of which have a defined width.
The 1st column doesn't. This means it has to be computed. Sure you have the table width defined in CSS, but IE 6 isn't exactly the best thing.
Your best bet is going to be to explicitly define the width of all of your header columns. Then give the table the css attribute of "table-layout: fixed". This is going to enforce your widths for the entire rendering of the table.

CSS three column layout, liquid center, no left-margin!

I am all in favor of CSS based layouts, but this one I just can't figure out. With a table it is oh-so-easy:
<html>
<head><title>Three Column</title></head>
<body>
<p>Test</p>
<table style="width: 100%; border: 1px solid black; min-height: 300px;">
<tr>
<td style="border: 1px solid green;" colspan="3">Header</td>
</tr>
<tr>
<td style="border: 1px solid green; width: 150px;" rowspan="2">Left</td>
<td style="border: 1px solid yellow;">Content</td>
<td style="border: 1px solid blue; width: 200px;" rowspan="2">Right</td>
</tr>
<tr>
<td style="border: 1px solid fuchsia;">Additional stuff</td>
</tr>
<tr><td style="border: 1px solid green;" colspan="3">Footer</td></tr>
</body>
<html>
Left is fixed width
Right is fixed width
Content is liquid
Additional stuff sits beneath content
Now here is the important part: "Left" may not exist. Again this is easy with the table. Delete the column and "Content" expands. Beautiful.
I have looked through many examples (and "holy grails") of liquid and table less three-column CSS based layouts, but I have not found one which is not using some kind of margin-left for the middle column ("Content"). Any margin-left will suck once "Left" is gone as "Content" will just stay at it's place.
I'm just about to switch to old school table based layout for this problem, so I'm hoping someone has some idea - I don't care about excess markup, wrappers and the like, I would just like to know how to solve this with plain CSS. Btw: look at how easy equal height columns are...
Cheers
PS: No CSS3 please
body {
width: 600px;
}
.left {
float: left;
width: 200px;
}
.center {
float: right;
width: 100%;
}
.right {
float: right;
width: 200px;
}
this should let the .center expand to the full width when left is removed

Resources