RTKHOT
asked on
resizing fonts
I have a table with 3 columns. the table has width 100%, and the three columns have width of 15%, 15%, and 70%
When my screen width reduces, then automatically the table widths increase/decrease.
But, how do I make the font size also change? The problem is that if the width reduces too much, the font wraps to the next line. I want the font to also have some percentage size so that it reduces with the width automatically
When my screen width reduces, then automatically the table widths increase/decrease.
But, how do I make the font size also change? The problem is that if the width reduces too much, the font wraps to the next line. I want the font to also have some percentage size so that it reduces with the width automatically
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a quick sample I made using jquery. You can do the same with pure javascript too.
The code sample is below and working sample http://jsbin.com/ibeciz/2/ edit
The code sample is below and working sample http://jsbin.com/ibeciz/2/
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function(){
var tblId = $("#tblId").width();
$("#showwidth").html(tblId);
if (tblId > 400) {
$("td").css("font-size", "100%");
}
else if (tblId > 300) {
$("td").css("font-size", "60%");
}
else {
$("td").css("font-size", "60%");
}
$(window).resize(function() {
var tblId = $("#tblId").width();
$("#showwidth").html(tblId);
if (tblId > 400) {
$("td").css("font-size", "100%");
}
else if (tblId > 300) {
$("td").css("font-size", "60%");
}
else {
$("td").css("font-size", "60%");
}
});
});
</script>
<style>
td {
border: medium solid #333;
}
</style>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<table id="tblId" width="80%" cellpadding="5">
<tr>
<td>r1:c1</td>
<td>r1:c2</td>
<td>r1:c2</td>
<td>r1:c3</td>
<td>r1:c4</td>
</tr>
<tr>
<td>r2:c1</td>
<td>r2:c2</td>
<td>r2:c2</td>
<td>r2:c3</td>
<td>r2:c4</td>
</tr>
<tr>
<td>r3:c1</td>
<td>r3:c2</td>
<td>r3:c2</td>
<td>r3:c3</td>
<td>r3:c4</td>
</tr>
</table>
<div id="showwidth"></div>
<div id="showmessg"></div>
</body>
</html>
One caveat. This will not work in IE's earlier than 9, you'll need a little js to fix that.
Open in new window