两个div元素,一个在中心,另一个在右边 [英] two div elements with one in center and another one in right

查看:1218
本文介绍了两个div元素,一个在中心,另一个在右边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个div元素放在一个宽度约为1000px的页面中央,另一个在右侧覆盖整个右侧,可以根据窗口大小进行调整。
实际上,我有一个正确的浮动元素在中心的div。所以
绝对定位工作,但它的缺陷是可见的,而在页面中动物园...

I want to position a div element centered in a page with width about 1000px and another one on its right that covers the whole right side that can adjust depending on the window size. Actually I have a right floated element on the centered div. So absolute positioning does the job but the flaw in it is visible while zooing in the page...

我想知道是否可能使用纯html,css而不是javascript。

I want to know if it is possible using pure html, css and not javascript.

此外,我使用了背景属性,绝对定位来实现上述,但寻找一个更好的解决方案。

Also I have used background property, absolute positioning to achieve the above but looking for a better solution.

推荐答案

这是我的目标:

HTML b
$ b

HTML

​<div id="container">
    <div id="right">
        <div id="right_content">sdfdsfdfg</div>        
    </div>
    <div id="main">sdfdsfdzgf</div>
</div>

CSS

html,body { height: 100% }
#container { height: 100%; background: #ccc; }

#right {
    position:absolute;
    left: 50%;
    right: 0;
    height: 100%;
    background: #f00;
    z-index: 0;
}

#right-content {
    position: absolute;
    left: 150px; /* half the width of #main */
}

#main {
    position: relative;
    margin: 0 auto;
    width: 300px;
    height: 100%;
    background: #00f; 
    z-index: 1;    
}

http://jsfiddle.net/XPE3w/3/

这篇关于两个div元素,一个在中心,另一个在右边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆