如何响应一个div,左右两个div,图像取决于屏幕大小

时间:2013-04-06 06:51:20

标签: javascript html css3

假设我有一个包含2个div的div,

有没有办法根据屏幕尺寸使其响应? 我想将它应用于移动版本,但我搞得一团糟......

<div id="primary">
<div id="left"><div id="object1" align='justify'>
<br/><br/>
<p>
If you told me this was a computer generated image of a mothership hovering over a planet's surface, I would have believed you. Instead, I had to look up desmids, which turned out to be a form of green algae. I would have guessed this is a cell in the process of dividing, but it turns out that one of the characteristic features of desmids is that they're a single cell divided into two compartments. (See, even I'm learning something from this.) Desmids are so tiny that this image was taken at 100x power. The green backdrop? It's a moss.
</p>
</div></div>

<div id="right"><div id="object3">
<b><h2>title</h2></b>
<img class="align-right" alt="" src="http://cdn.arstechnica.net/wp-content/uploads/2012/10/09_Place_22047_3_Drange.jpg"  style="width:200px" /></div></div></div>   

图像和div我不知道如何根据屏幕尺寸减少它...

请查看at a jsfiddle 事实上,我不能让div保持图像所在的2列而不是左列的同一级别...

1 个答案:

答案 0 :(得分:1)

为此你还有百分比填充和边距,只需应用一些数学......

LeftDiv(填充:1%+边距:1%+宽度:44%)+ RightDiv(填充:1%+边距:1%+宽度:44%)= 100%

填充和边距为上,下,左,右1%,1%,1%,1%......

<强> CSS: -

#left, #right {
    margin: 1%;
    padding: 2%;
    width: 43%;
}

如果您希望图片具有响应性,请制作其width:100%;

http://jsfiddle.net/FgnpL/5/