CSS: white-space: nowrap does not seems to work in IE - html

Here is the jsfiddle of the below code. http://jsfiddle.net/ux4DD/. What I want is the name Harry Pham to be in one line, so I make the width very small and do white-space:nowrap. It work on Firefox, but not IE. Help please
<table cellpadding="0" cellspacing="0" style="width: 450px;">
<tr>
<td>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="width:20px;border-top:1px solid gray;white-space: nowrap;"><span class="linkColor">Harry Pham</span>
</td>
<td style="height:15px;background:url('images/line.png') no-repeat;width:28px;" width="35px"></td>
<td style="border-bottom:1px solid gray;" width="auto"></td>
</tr>
</table>
</td>
</tr>
</table>

For IE 6 and 7 you need to wrap your text with a <span> tag and give it a white-space property. Since you already have a <span> tag wrapped around your text and you have a class for it, just add the white-space property to your <span> class .linkColor.
.linkColor{
white-space:nowrap;
}
Check working example at http://jsfiddle.net/ux4DD/1/

Hope this will be helpful:
var buttons = document.getElementsByTagName('button');
for(var j=0; j < buttons.length; j++) {
var button = buttons[j];
var textNode = button;
while(textNode.children[0]) {
textNode = textNode.children[0];
}
var text, words, numSplits;
var spacing = 0;
while(button.scrollWidth !== 0 && button.clientWidth !== 0 &&
button.scrollWidth > button.clientWidth) {
if(!spacing) {
text = textNode.innerHTML;
words = text.split(' ');
numSplits = Math.ceil(button.scrollWidth / button.clientWidth);
spacing = Math.round((words.length)/numSplits);
}
for(var i = spacing; i < words.length; i+=spacing+1) {
words.splice(i , 0, '<br />');
}
textNode.innerHTML = words.join(' ');
spacing--;
words = text.split(' ');
}
}
Ref: Word wrapping for button with specified width in ie7?

Related

HTML table: rescaling browser page and NOT show scrollbars

I've this code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>testPage</title>
<style>
table td {
width: 50%;
}
</style>
</head>
<body>
<div id="titlebar">
<center>
Select option:
<select onchange="onSelect.call(this, event)">
<option value="one">One</option>
<option value="two">Two</option>
</select>
<script>
function onSelect(event) {
switch (this.options[this.selectedIndex].text) {
case "One":
var td = document.getElementById("one");
td.style.borderColor = "red";
td.style.borderWidth = "5px";
td.style.borderStyle = "solid";
td.style.width = "99%";
var td = document.getElementById("two");
td.style.borderColor = "black";
td.style.borderWidth = "1px";
td.style.borderStyle = "solid";
td.style.width = "100%";
break;
case "Two":
var td = document.getElementById("two");
td.style.borderColor = "red";
td.style.borderWidth = "5px";
td.style.borderStyle = "solid";
td.style.width = "99%";
var td = document.getElementById("one");
td.style.borderColor = "black";
td.style.borderWidth = "1px";
td.style.borderStyle = "solid";
td.style.width = "100%";
break;
}
}
</script>
</center>
</div>
<div id="images">
<table width="100%" height="100%" border=1 cellpadding=1>
<!-- first row -->
<tr id="row1">
<td id="xxx">
<div id="xxx_div" style="width:100%;height:370px"></div>
</td>
<td id="yyy">
<div id="one" style="width:100%;height:370px"></div>
</td>
</tr>
<!-- second row -->
<tr id="row2">
<td id="zzz">
<div id="zzz_div" style="width:100%;height:370px"></div>
</td>
<td id="kkk">
<div id="two" style="width:100%;height:370px"></div>
</td>
</tr>
</table>
</div>
<div id="bottom">
Bottom ...
</div>
</body>
</html>
that works fine, but if I rescale my browser page you can see that scrollbars appears (I know, I'm using absolute values for div height and the problem probably is about this, but it's only to show the problem ... ).
I'd like to obtain the same behaviour at this site
http://tools.geofabrik.de/mc/
where you can see that if you rescale the browser scale, no scrollbars appears and the maps (so the tables and its contents ... ), rescale ...
Suggestions / examples?
This is what you're looking for:
html, body {
min-height: 100%;
min-width: 100%;
margin: 0;
padding: 0;
}
table {
width: 100vw;
height: 100vh;
}
td {
width: 50%;
height: 50%;
background: red;
}
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
Of course, you might adapt your table size if you need to add inputs or text outside.
Just consider always occupying a total 100% of the visible area.

Footer not on first page

I have a footer file which is rendered on every page (with the numerotation).
I'd like it not to be rendered on the first page. Do you have an idea ?
This is my code:
<html><head><script>
function subst() {
var vars={};
var x=document.location.search.substring(1).split('&');
for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
for(var i in x) {
var y = document.getElementsByClassName(x[i]);
for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
}
}
</script></head><body style="border:0; margin: 0;" onload="subst()">
<table style="border-bottom: 1px solid black; width: 100%">
<tr>
<td style="text-align:left"><font face="Century Gothic">
Page <span class="page"></span> sur <span class="topage"></span>
</font> </td>
</tr>
</table>
use this js in your script....first store page value in var and then use it to remove the footer.
your html code..set the page value either by ruby/js(any way you prefer)
<p id="page_value" data-value="<%= #page.value %>"></p>
after setting ,use it to remove the footer
<script type="text/javascript">
window.onload = function () {
var value= $("#page_value").data("value");
if (value==1){
$('#footer').remove()
}
}//if ends
</script>
..hope it helps...

Title and Universal Selector (*) in Javascript CSS/HTML5

How do I add a title to the following div?
document.write('<div style="width:auto; margin:10px;"><table style="background-color:purple;"
border="1" cellspacing="1" cellpadding="35">')
Below is the complete script:
<html>
<body>
<script Language="JavaScript">
rows = 6;
cols = 6;
document.write('<div style="width:auto; margin:10px;"><table style="background-color:purple;"
border="1" cellspacing="1" cellpadding="35">')
/* Not apart of the Table */
//document.write('<h3> <center>Table </center> </h3>')
for (i = 0; i < rows; i++) {
document.write('<tr>')
for (j = 0; j < cols; j++)
{
document.write('<td style="color:orange;">' + (i*j) + '</td>')
}
document.write('</tr>')
}
document.write('</table></div>')
</script>
</body>
</html>
How do I also use a Universal Selector (*) to make all the font size the same?
Just add a <caption> element inside the table:
document.write('<div style="width:auto; margin:10px;"><table style="background-
color:purple;" border="1" cellspacing="1" cellpadding="35"><caption>Title</caption>')
for the * universal selector I believe you want css:
<style type="text/css">
*{
font-size: 12px;
}
</style>
Try this:
var elements = document.getElementsByTagName("*");
for (var i = 0, len = elements.length; i < len; i++) {
var element = elements[i];
element.style.fontSize = "20px"
}

Generate dynamic html table in Javascript not works in IE

I have created a table in div element in Javascript with some rows and columns
var parentElement = document.getElementById('divExcelData');
var tableElement = document.createElement('table');
tableElement.border = "1";
for (var r = 1; r <= 3; r++) {
var rowElement = document.createElement('tr');
for (var c = 1; c <= 2; c++) {
var colElement = document.createElement('td');
colElement.setAttribute("style", "width:80px; height:20px; border:1px solid Black;");
var divElement = document.createElement('div');
divElement.id = r + '_' + c;
divElement.contentEditable = "true";
divElement.style.width = "100%";
divElement.style.height = "100%";
colElement.appendChild(divElement);
rowElement.appendChild(colElement);
}
parentElement.appendChild(tableElement);
}
but problem is when I debug the page from Internet Explorer(9) developer tools it shows inner html of table element as...
<TABLE border=1>
<TR>\r\n
<TD>\r\n
<DIV style=\"WIDTH: 100%; HEIGHT: 100%\" id=1_1 contentEditable=true></DIV>
</TD>\r\n
<TD>\r\n
<DIV style=\"WIDTH: 100%; HEIGHT: 100%\" id=1_2 contentEditable=true></DIV></TD>
</TR>
\r\n
<TR>\r\n
<TD>\r\n
<DIV style=\"WIDTH: 100%; HEIGHT: 100%\" id=2_1 contentEditable=true></DIV>
</TD>
\r\n
<TD>
\r\n
<DIV style=\"WIDTH: 100%; HEIGHT: 100%\" id=2_2 contentEditable=true></DIV>
</TD>
</TR>
\r\n
<TR>
\r\n
<TD>
\r\n
<DIV style=\"WIDTH: 100%; HEIGHT: 100%\" id=3_1 contentEditable=true></DIV>
</TD>
\r\n
<TD>
\r\n
<DIV style=\"WIDTH: 100%; HEIGHT: 100%\" id=3_2 contentEditable=true>
</DIV>
</TD>
</TR>
</TABLE>
I don't know why \r\n is added in HTML and also style element contains (\") instead of ("). That's why the page shows nothing. This code works well in Chrome and Firefox.

Center a table in the page

I wrote this HTML/JavaScript code but I can't center the table in the page. I've tried both with align=center and with margin in style. But nothing seems to work. Even putting the table into a div.
Edit: Better description: I'm trying to take four picture from IP cameras (small pictures) and make them appear into a fullscreen browser centered and maximized on the page.
This is the code:
<body style="margin:0; background-color:black;">
<table style="height:100%; background-color:black; position:fixed;">
<tr>
<img height="50%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURQAAAP///6XZn90AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAKSURBVBjTY2AAAAACAAGYY2zXAAAAAElFTkSuQmCC" name="Camera1"/>
<img height="50%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURQAAAP///6XZn90AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAKSURBVBjTY2AAAAACAAGYY2zXAAAAAElFTkSuQmCC" name="Camera2"/>
</tr>
<tr>
<img height="50%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURQAAAP///6XZn90AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAKSURBVBjTY2AAAAACAAGYY2zXAAAAAElFTkSuQmCC" name="Camera3"/>
<img height="50%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURQAAAP///6XZn90AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAKSURBVBjTY2AAAAACAAGYY2zXAAAAAElFTkSuQmCC" name="Camera4"/>
</tr>
</table>
</body>
<script language="JavaScript">
//<!--
function reloadImage()
{
var now = new Date();
var Camera = new Array()
var Camera1 = 'http://192.168.10.219/cgi-bin/wappaint?camera_no=0&animation=0&name=aa&password=11&time=1346851800&pic_size=2'
var Camera2 = 'http://192.168.10.219/cgi-bin/wappaint?camera_no=1&animation=0&name=aa&password=11&time=1346851800&pic_size=2?1346851972719.719'
var Camera3 = 'http://192.168.10.219/cgi-bin/wappaint?camera_no=2&animation=0&name=aa&password=11&time=1346851800&pic_size=2?1346851974247.247'
var Camera4 = 'http://192.168.10.219/cgi-bin/wappaint?camera_no=3&animation=0&name=aa&password=11&time=1346851800&pic_size=2?1346851975678.678'
if (document.images)
{
var image1 = new Image;
var image2 = new Image;
var image3 = new Image;
var image4 = new Image;
image1.onload = function () { document.images.Camera1.src = image1.src; }
image2.onload = function () { document.images.Camera2.src = image2.src; }
image3.onload = function () { document.images.Camera3.src = image3.src; }
image4.onload = function () { document.images.Camera4.src = image4.src; }
image1.src = Camera1 + '?' + now.getTime();
image2.src = Camera2 + '?' + now.getTime();
image3.src = Camera3 + '?' + now.getTime();
image4.src = Camera4 + '?' + now.getTime();
}
setTimeout('reloadImage()',1000);
}
setTimeout('reloadImage()',1000);
//-->
</script>
You should learn to write HTML first. Markup for Table goes -
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td>You img tag</td>
<td>You img tag</td>
</tr>
<tr>
<td>You img tag</td>
<td>You img tag</td>
</tr> <!-- And so on -->
</table>
You completely missed TD in your code
Here is the answer to your question
Edit:
When you are adding img tag in TD use width and height attributes, it will solve the resizing issue -
<img src="img/imageName.jpg" width="400" height="400" alt="" title="" />
And hey, I used the learning thing because you posted the question here so I assumed you are already working on HTML. Never mind! Why don't you try with HTML Fundamentals
This will help you understand HTML very well! :)
There is no td specified. Add td after the tr and give align="center" to the table tag".
And remove the position:fixed if it is really not necessary
Check the demo here http://jsfiddle.net/2QnE9/2/
You need to give it a fixed width and set margin-left and margin-right to auto and remove the fixed position from your table
EXAMPLE
width:500px;
margin-left:auto;
margin-right:auto;
Try this
<table align="center" style="height:100%;background-color:black; position:relative;">
<tr><td>
<img height="50%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURQAAAP///6XZn90AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAKSURBVBjTY2AAAAACAAGYY2zXAAAAAElFTkSuQmCC" name="Camera1"/>
<img height="50%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURQAAAP///6XZn90AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAKSURBVBjTY2AAAAACAAGYY2zXAAAAAElFTkSuQmCC" name="Camera2"/>
</td></tr>
<tr><td>
<img height="50%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURQAAAP///6XZn90AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAKSURBVBjTY2AAAAACAAGYY2zXAAAAAElFTkSuQmCC" name="Camera3"/>
<img height="50%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURQAAAP///6XZn90AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAKSURBVBjTY2AAAAACAAGYY2zXAAAAAElFTkSuQmCC" name="Camera4"/>
</td></tr>
</table>
See Demo
Here is the CSS:
#mytable
{
position:fixed;
left:50%;
top:50%;
//set margin-left and margin-top to get it to center.
}