我正在创建一个包含 3 列的网页。中间一栏是所有内容的所在。我要输入的内容必须是左对齐图像的格式,然后是图像旁边的一些文本。这在整个专栏中流动,带有不同的图像和相应的文本。由于我的布局是基于 div 的布局,因此我为该列放置了一个主 div (page_content)。然后标题(h4)和标题下面我输入了另一个div。这个 div 又包含单独的 div,这些 div 嵌套在图像的 div(照片类)和文本的 div(lat_art 类)中。下面给出了 HTML 代码和 CSS 代码。我的问题是第一个图像和文本出现了,但随后在第一个文本下方垂直排列,即仅占据 div 的 50% 并向右浮动,将其对应的文本推到其下方相同的 50% 空间中。我是否应该为单个 div 指定高度,可能图像比文本大。但如果我这样做,我的代码不会变成静态的。我希望它是动态的。请帮忙。
HTML 代码
<div id="page_content">
<h4 class="center_cap">LATEST ARTISTS</h4>
<!--Div for the content begins here-->
<div>
<!--Individual div begins here-->
<div >
<div class="photo">
<img src="Images/guitar.jpg" alt="guitar"/>
</div>
<div class="lat_art">
<span class="artist">ROCK ON</span>
<p>
Good news to all the fans of 'Rock On'. Concerts all around the world.
</p>
</div>
</div>
<!--Individual div ends here-->
<!--Individual div begins here-->
<div >
<div class="photo">
<img src="Images/guitar.jpg" alt="guitar"/>
</div>
<div class="lat_art">
<span class="artist">ROCK ON</span>
<p>
Good news to all the fans of 'Rock On'. Concerts all around the world.
</p>
</div>
</div>
</div>
<!--Div for the content ends here-->
</div>
来自外部样式表的代码
.photo{
width:48%;
float:left;
padding-left:2px;
}
.lat_art{
width:50%;
float:right;
}