简体   繁体   English

将div并排放置在固定宽度和高度的绝对div内

[英]keep div's side by side inside absolute div of fixed width & height

I am facing problem while centering a div of fixed width & height and placing two divs side by side inside it. 我将固定宽度和高度的div居中并在其中并排放置两个div时遇到问题。 What i want to achieve, at later point of time, is the slide to left effect on the second div (on top of first div) based on some event. 在稍后的某个时间点,我想实现的是基于某个事件在第二个div(在第一个div的顶部)向左滑动效果。 Below is what i tried: 以下是我尝试过的方法:

HTML: HTML:

<div id="center">
    <div id="firstel"></div>
    <div id="secondel"></div> 
</div>

CSS: CSS:

#center{
    position:absolute;
    border:1px solid black;
    width:200px;
    height:100px;
    overflow:hidden;
    top:50%;
    left:50%;
}
#firstel{
    background-color:red;
}
#secondel{
    background-color:blue;
}

#firstel,#secondel{
    position:relative;
    width:200px;
    height:100px;
    display:inline-block;
    float:left;
}

JSFIDDLE: link JSFIDDLE: 链接

Any help is appreciated! 任何帮助表示赞赏!

#center{
    position:absolute;
    border:1px solid black;
    width:100%; //change this
    overflow:hidden;
    top:50%;
    left:50%;
}

Demo here 在这里演示

#center and #firstel,#secondel ID's were of same width(200px), If you need to show side by side eitherof the ids values have to be changed #center#firstel,#secondel ID的宽度相同( #firstel,#secondel ),如果您需要并排显示两个ID值,都必须更改

You can try like this: Demo 您可以这样尝试: 演示

#firstel,#secondel{    
    width:50%; /* changed value in % or you can use 100px too as per your need */
    height:100px;
    display:inline-block;
    float:left;
}

if u want the two divs side by side change the widths of the divs change the divs width that shoild be less than the parent div width 如果您希望两个div并排更改div的宽度,请更改收缩的div宽度小于父div的宽度

#firstel,#secondel{
position:relative;
width:100px;
height:100px;
display:inline-block;
float:left;

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM