div보다 넓은 테이블을 가진 고정 폭 div가 있습니다. 내가하고 싶은 것은 div 안에 들어갈 수 있도록 테이블 텍스트를 줄이는 것이다.테이블의 글꼴 크기를 줄이면 div 내에 테이블이 나타납니다.
너비를 백분율로 설정하십시오. This Page 테이블 너비를 100 %로 설정하면 작동하지 않습니다.
다음 코드는 작동하지만 어떻게 자동 화합니까? 즉 FontSize를 계산합니까?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href=/themes/base/jquery.ui.all.css">
<script src="/jquery-1.7.1.js"></script>
<script src="/ui/jquery.ui.core.js"></script>
<script src="/ui/jquery.ui.widget.js"></script>
<script src="/ui/jquery.ui.mouse.js"></script>
<script src="/ui/jquery.ui.resizable.js"></script>
<style>
#narrorColumn{
width: 250px;
}
</style>
<script type="text/javascript">
function ShrinkTable(){
var FontSize = 6;
function ShrinkTable(){
var TabWidth = $("#tbl").width();
var DivWidth= $("#narrowColumn");
if (DivWidth <= TabWidth)
{
$("#tbl").css('font-size', FontSize);
}
}
</script>
</head>
<body onLoad="ShrinkTable()" >
<div id = "narrorColumn" >
<table id="tbl" border="10">
<thead>
<tr>
<th>First Column</th>
<th>Second Column</th>
<th>Third Column</th>
<th>Forth Column</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some Random text here</td>
<td>Some Random text here</td>
<td>Some Random text here</td>
<td>Some Random text here</td>
</tr>
<tr>
<td>Mary Had a little lamb</td>
<td>Mary Had a little lamb</td>
<td>Mary Had a little lamb</td>
<td>Mary Had a little lamb</td>
</tr>
<tr>
<td>Humpty Dumpty sat on a wall</td>
<td>Humpty Dumpty sat on a wall</td>
<td>Humpty Dumpty sat on a wall</td>
<td>Humpty Dumpty sat on a wall</td>
</tr>
<tr>
<td>Hay diddle diddle the kat and the fiddle</td>
<td>Hay diddle diddle the kat and the fiddle</td>
<td>Hay diddle diddle the kat and the fiddle</td>
<td>Hay diddle diddle the kat and the fiddle</td>
</tr>
</tbody>
</table>
</div>
<div> <input type=button value="Make Big" onClick="$('#tbl').makeBig()">
</div>
</body>
</html>
음 ... 글꼴 크기는 6 무엇입니까? 6px, 6pt, 6em? 당신이 단위를 추가 할 필요가 있다고 생각 – Rodolfo