javascript - 如何根据屏幕尺寸使左右各有 2 个 div 的 div 响应并带有图像

标签 javascript html css

假设我有一个包含 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 列图像在下方且不在左列的同一级别...

最佳答案

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

LeftDiv(padding:1% + margin:1% + width:44%) + RightDiv(padding:1% + margin:1% + width:44%) = 100%

padding 和 margin 是 top,bottom,left, right 1%,1%,1%,1%...

CSS:-

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

如果您希望图像也具有响应性,请使其 width:100%;

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

关于javascript - 如何根据屏幕尺寸使左右各有 2 个 div 的 div 响应并带有图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15847994/

相关文章:

javascript - font Awesome 无法在 ie9 和 ie11 兼容模式下工作

javascript - 同一组件渲染两次

javascript - 使用 javascript 仅更改一个输入字段

javascript - 努力从单击的 div 中获取值

javascript - 如何滚动到 jQuery Mobile 中的页面元素?

javascript - 我想滚动放大和缩小图像,但该图像上的图钉也保持正确定位。查询

html - 在 HTML 和 CSS 中只获取 border-bottom

javascript - Jquery Mobile - 从其他按钮单击更改标题中的图标颜色

javascript - 突出显示 div onclick 并取消突出显示第二次单击

html - 将输入字段与长输入名称对齐