2012-09-01 117 views
0

我是JavaScript中的新手。我有一个功能,应该循环26次相同的图像和文字。并将它们显示为多个图像和文本段落。然而,我的循环重叠了文本和图像,如下所示。 format I do not want循环重叠图像

我想让我的代码显示如下图所示的图像。 format I want to display.

我该如何解决这个问题?我的JavaScript代码如下所示

function getData() { 
    var stringData = ''; 

    for (i = 0; i < 26; i++) { 
    stringData = stringData + '<div><image src="img/sample-image.png" width="10% "height="10%" align="left" border="0"/>' + 'In this example a sample of the album photo on the site shall appear alongside a simple description of the album. To view the album select the album.</div><br/>'; 
    } 

    document.getElementById("list-menu").innerHTML = '' + stringData + ''; 
} 

回答

2

two <br />s should do the trick.简单地增加,除此之外,尝试clear: both in your div CSS

+0

明确:两者都正常工作。谢谢。 – sammyukavi

+1

发生这种情况是因为您的图像正在“向左对齐”。 'align =“left”''属性在CSS中被当作'float:left;'语句处理。每当孩子在父母身上浮动时,父母就会崩溃 - 几乎将其从文档中取出。这就是所有浮动图像互相交互的原因。 (1)使用'clear:both;'作为代达罗斯状态*(这会清除父代中的任何浮动影响)*或(2)'overflow:hidden;'*(其中强制父母正确计算它的高度并包装它的孩子。)* – Pebbl