简体   繁体   English

隐藏另一个动态扩展div

[英]Dynamically expand div upon hiding another

I am new to posting on this site, so please excuse any errors I may make. 我是本网站的新手,所以请原谅我可能犯的任何错误。

So as my question states, I'm essentially looking for a way to dynamically expand divs. 因此,正如我的问题所述,我实质上是在寻找一种动态扩展div的方法。 So far I have a container div with three columns inside it. 到目前为止,我有一个容器div,其中有三列。 Each of the columns have a link to some javascript that sets it to disply:none. 每个列都有指向一些javascript的链接,这些链接将其设置为disply:none。 What I'm looking for a way to do is, for example, if I was to click the hide button in the center column, I want the two outer columns to expand to take up the space left behind. 例如,如果要单击中间列中的“隐藏”按钮,我想要的是一种方法,我希望两个外部列都可以扩展以占用剩余的空间。 Perhaps a way to increase the width of the two from 33% each to 50% upon hiding the middle one. 可能是在隐藏中间一个时将两者的宽度从33%增加到50%的一种方法。

So that the two other divs essentially share the newly created space between them. 这样,其他两个div就可以在它们之间共享新创建的空间。

Here is my html and css as it is just now: 这是我的html和CSS,就像现在一样:

HTML: HTML:

<div id="col2outer">

        <div id="col1">
            <p>test</p>
            <a href="javascript:hideshow(document.getElementById('col1'))">Hide</a>
        </div>

        <div id="col2mid">
            <p>test</p>
            <a href="javascript:hideshow(document.getElementById('col2mid'))">Hide</a>
        </div>


        <div id="col2side">
            <p>test</p>
            <a href="javascript:hideshow(document.getElementById('col2side'))">Hide</a>
        </div>

    </div>

CSS: CSS:

 #container #col2outer {
 height:200px;
 width: 870px;
 float: left;
 margin: 0;
 padding: 0;
 }

 #container #col1 {
 height:200px;
 width: 33%;
 float: left;
 border-width: 0.5mm; border-style: groove;
 -moz-border-radius: 15px;
 border-radius: 15px;
 }


 #col2outer #col2mid {
 height:200px;
 width: 33%;
 float: left;
 border-width: 0.5mm; border-style: groove;
 -moz-border-radius: 15px;
 border-radius: 15px;
 }

 #col2outer #col2side {
 height:200px;
 width: 33%;
 float: left;
 border-width: 0.5mm; border-style: groove;
 -moz-border-radius: 15px;
 border-radius: 15px;
 }

Thank you in advance for any help, and apologies if this question has already been asked 预先感谢您的任何帮助,如果已经提出此问题,我们深表歉意

Hy!

You can try something like: 您可以尝试如下操作:

Click on hide button: 单击隐藏按钮:

$(document).ready(function(){
  $('button').click(function(){
    $('#col1').css("display","none");
    $('#col2mid').css("width","49%");
    $('#col2side').css("width","49%");
  })
});

This is very simple way for resizing divs... 这是调整div大小的非常简单的方法。

if you want to click on coloumn and then hide/show and resize you will need to rename your columns, or your code will be long... 如果要单击列,然后隐藏/显示并调整大小,则需要重命名列,否则代码很长...

EDIT: 编辑:

Something like this: 像这样:

http://jsfiddle.net/pbnkH/ http://jsfiddle.net/pbnkH/

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

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