I have a div inside a td element. The div is resizable and it has overflow scroll. The problem is that the div resizes when I use JQuery to change the contents of the div. What I want is for the div to stay the same size when its contents change. Can someone tell me how to do this?
<table>
<tr>
<td style="text-align: right">Date: 8-29-2013</td>
<td></td>
</tr>
<tr>
<td><div id="mydiv" style="border: 1px solid black; overflow:scroll; resize: both; min-height:300px;min-width: 300px;"></div></td>
<td style="vertical-align: top"><button id="edit">Edit</button></td>
</tr>
</table>
<script>
$('#edit').click(function(){
$('#mydiv').html('A lot of text to demonstrate how the div resizes when I don\'t want it to.');
});
</script>
You need to set width to either Parent Element i.e., table or child element which you don't want to increase width. i.e, div.
I added width to parent element so that all child elements can control with that.
CODE:
#table{
width:165px;
}
<table id="table">
<tr>
<td style="text-align: right">Date: 8-29-2013</td>
<td></td>
</tr>
<tr>
<td><div id="mydiv" style="border: 1px solid black; overflow:scroll; resize: both;min-height: 300px;"></div></td>
<td style="vertical-align: top"><button id="edit">Edit</button></td>
</tr>
</table>
$('#edit').click(function(){
$('#mydiv').html('A lot of text to demonstrate how the div resizes when I don\'t want it to.');
});
JSFIDDLE
NOTE: change width according to your requirement.
You need add the width to the div
<div id="mydiv" style="border: 1px solid black; overflow:scroll;
resize: both; width:300px min-height:300px;"></div>
Perhaps it is because you have 2 min-heights. You need a max-height
Related
Can I make two line of a table not align, one tr is left, another is right, using position:relative or position:absolute and margin? But it also align.
How can I make two tr not align?
I want this:
What I want this is:
I have a html:
<table>
<tr colspan="2"><td>top</td><tr>
<tr><td>left 1 2 3</td><td>right</td></tr>
</table>
I want hide the 'left 1 2 3' slowly as a animate, then the width of 'right' becomes 100%
but the effect I need is when left td hide, the whole td move left, first text 'left' disappear, then 1, then 2,3, then the whole td hide.
I have tried this:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
<style>
body{margin:0px}
</style>
<script>
function hid() {
$("#d1").animate({ "margin-left": "-102px" });
}
</script>
<table id="d1" cellpadding="0" cellspacing="0">
<tr >
<td style="position: relative; width: 100px; height:100px;border: 1px solid #0050D0;background: #96E555; cursor: pointer">
123
</td>
<td>
abc
</td>
</tr>
</table>
<input type="button" onClick="hid()">
This looks like what I want, but there is only one tr and it is move the whole table but not the tr.
You mean like this JSFiddle?
<table style='width:100%;'>
<tr>
<td style='text-align:right;'>RIGHT</td>
</tr>
<tr>
<td style='text-align:left;'>LEFT</td>
</tr>
</table>
Alternatively, the best way to do this is with two floated elements, as in this fiddle
<div style='border:1px solid black;width:100%;height:44px;'>
<div style='float:right;width:80px;border:1px solid black;height:20px;'></div>
<div style='clear:both;'></div>
<div style='float:left;width:80px;border:1px solid black;height:20px;'></div>
</div>
I have a table within a table cell. The child table height must be aligned to parent cell height. I set height="100%" to the child table, but it's not working.
CSS
.outer{
border:1px solid black;
border-collapse:collapse;
}
.inner{
border:1px solid red;
height:100%;
width:auto;
}
HTML
<table class="outer">
<tr>
<td>
<!-- Content Here -->
</td>
<td>
<table class="inner">
<tr>
<td>
<!-- Content Here -->
</td>
</tr>
</table>
</td>
</tr>
</table>
Browser doesn't calculate height for table cells. At least there is no good cross-browser CSS solution for that. Relative and absolute positioning of parent TD will cause the table collapsing.
The solution might be to set the height fixed in pixels or calculate offsetHeight using JavaScript. Set style="height:100%;" to parent TD and id="inner" to child table.
Run the following JavaScript on page load:
<!DOCTYPE HTML PUBLIC>
<html>
<head>
<style>
.outer{
border:1px solid black;
border-collapse:collapse;
}
.inner{
border:1px solid red;
height:100%;
width:auto;
}
</style>
</head>
<body>
<table class="outer">
<tr>
<td> asdf alsdf asldf<br/>asdf alsdf asldf<br/> asdf alsdf asldf<br/>
asdf alsdf asldf<br/>asdf alsdf asldf<br/>
</td>
<td style="height:100%;">
<table class="inner" id="inner">
<tr><td>inner content</td></tr>
</table>
</td>
</tr>
</table>
<script type="text/javascript">
var el = document.getElementById('inner');
el.style.height = el.parentNode.offsetHeight + 'px';
</script>
</body>
</html>
You can also bind this to window onresize event if needed.
My solution was to give the inner table a fixed height of 1px and set the height of the td in the inner table to 100%. Against all odds, it works fine, tested in IE, Chrome and FF!
Assign some width to the parent td with inner table. say width="100". Also add following CSS:
for outer class add position : relative;
for inner class add position:absolute; bottom:0; right:0; top:0;
also add display: block property to inner class
I have the following simplified layout:
jsfiddle: http://jsfiddle.net/rersW/
<table>
<tr>
<td style="border:1px solid black;height:300px;width:100px">A</td>
<td style="border:1px solid black;height:100%">
<div style="border:1px solid blue;height:100%;width:100px">B</div>
</td>
</tr>
</table>
I need the blue outlined div to fill its cell. I've tried box-sizing on the div and the cell as well as changing the display of both (inline-block, etc.). Nothing I try is working.
The contents of cell "A" determine the height of the table.
The contents of cell "B" determine the width of its cell.
It must work identically in Chrome, Firefox, Safari, Opera & IE 8+
TIA
Height:100% requires that the parent has an explicit height. Set the same height in cell b as you do in cell a, which is determining the table height, in this case 300px and the child div will expland.
EDIT
If you can't explicitly define any of the parent heights you will need to use JS/Jquery. See here http://jsfiddle.net/rersW/3/
Try this and post comments if it is not quite right :|
http://jsfiddle.net/rersW/1/
The reason is height: 100%; needs to be have a parent with height defined , or else you have to
either fix the height.
or Chain height: 100% all the up to body, if no height is fixed anywhere
TO illustrate my point upgrade your markup to this
<td valign="top" style="border:1px solid black; height: 300px;">
<div style="border:1px solid blue;height:100%; display: block;width:100px">B</div>
</td>
Demo
UPDATE:
I've come up with something that works w/o JS:
<table>
<tr>
<td>
<div style="position:relative">
<table>
<tr>
<td style="border:1px solid black;height:300px;width:100px">A</td>
<td style="border:1px solid black;height:100%">
<div style="border:1px solid blue;box-sizing:border-box;height:100%;width:100px"> </div>
</td>
</tr>
</table>
<div style="border:1px solid red;height:100%;position:absolute;right:0;top:0;width:100px">B</div>
</div>
</td>
</tr>
</table>
Doesn't look pretty when rendered but the production structure doesn't have borders or padding.
Any simpler solutions would be preferred.
How do you make individual table columns fixed for a certain width so no matter how much text is in that column, the width of the column stays the same?
<col> tag is only good for firefox
table-layout:fixed is for whole table really
Just setting a width does not do it
what is the best css property to use for this
Below is code:
.video{
overflow:hidden;
table-layout:fixed;
max-width:146px;
}
.audio{
overflow:hidden;
table-layout:fixed;
max-width:146px;
}
.image{
overflow:hidden;
table-layout:fixed;
max-width:146px;
}
.qid2{
overflow:hidden;
table-layout:fixed;
max-width:92px;
}
<table border=1 id="vidtbl">
<tr>
<th>Question No</th>
<th>Video</th>
<th>Audio</th>
<th>Image</th>
</tr>
<tr>
<td class="qid2"></td>
<td class="video">images/dolphinvideo.png//////////////////////////////////////</td>
<td class="audio">hello</td>
<td class="image"></td>
</tr>
</table>
You can wrap the contents of the <td> in another tag with width and overflow:hidden. For example:
<table>
<tr>
<td class="fifty">
<p>Lorem ipsum dolor</p>
</td>
</td>
</table>
And the CSS:
.fifty p { overflow:hidden; width:50px; }
You can use width attribute in td tag
<td width="100px">
or you can use style attribute
<td style="width:100px">
or you can define it in css file
.tdstyle{
width:100px;
}
and specify the class in td tag
<td class="tdstyle">
If setting td's width to a fix value does not work for you:
<td width="100">..</td> or <td style="width:100px">...</td>
Wrapped the content to a div and set the overflow as hidden:
<td><div style="width:100px;overflow:hidden;">...</div></td>
Css class will be much efficient and easy to maintain though:
.col120 { width:120px; overflow:hidden;}
<td><div class="col120">content...</div></td>
try using
max-width:100px;
or
max-height:100px;
This will let your column expand maximum upto the width you set.
Can #parent div resize by #child div (*when #child div use position:absolute;)
just like #t_parent table is resize by #t_child table
<div id="parent" style="position:relative; width:500px; height:500px; border:#F00 3px solid;">
<div id="child" style="position:absolute; left:20px; width:800px; height:500px; border:#06F 3px solid;"></div>
</div>
<table id="t_parent" width="500" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>
<table id="t_child" width="800" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>TEXT</td>
</tr>
</table>
</td>
</tr>
</table>
If there is fixed width/height - no, you cant resize.
position absolute inside of position relative make the div detached from parent so you cant re-size.
But try remove position:absolute and give parent div display:table then you can re-size it.
Check this
http://jsfiddle.net/9gxyH/
First thing if you want the child div resize its parent div so there no need for position:absolute because we use position:absolute when we want that the element not effect other elements.
but if you want this functionality so you need to do a little bit of js.
check http://jsfiddle.net/sandeep/CLb5r/13/