JavaScript Auto adjust width of divs on show/hide of one div in bootstrap html auto adjust width excel,auto adjust width css,auto adjust

I am trying make a responsive page with three div(each div is a column), where one column is sometimes hidden.What I aim to implement is:

1.When three divs are shown, width should be 100%.

  1. When one div is hidden, the others needs to adjust the width and fit the external div(that is, 2 divs total width 100%) automatically.

I tried do it like this, but the width is fixed as I have given col-lg so. It is not auto adjusting:

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" target='_blank' href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<body>
  <div class="row col-lg-12">
    <div class="col-lg-4">
      <h3>Column 1</h3>
    </div>
    <div class="col-lg-4">
      <h3>Column 2</h3>
    </div>
    <div class="col-lg-4" hidden>
      <h3>Column 3</h3>        
    </div>
  </div>
</div>

</body>
</html>
Answer:1

With bootstrap you can tell to hide a div when the window is in a special size.

You have 4 size : extra small (xs), small (sm), medium (md) and large (lg)

My example show how to hide one div when the page is medium or xs, that mean the column 2 will be show only when the page is large.

So you can write :

.border{
  border : 1px solid green;
 }
<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" target='_blank' href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<body>
  <div class="row col-lg-12">
    <div class="col-lg-4 col-xs-6 border">
      <h3>Column 1</h3>
    </div>
    <div class="col-lg-4 hidden-md hidden-sm hidden-xs border">
      <h3>Column 2</h3>
    </div>
    <div class="col-lg-4 col-xs-6 border">
      <h3>Column 3</h3>        
    </div>
  </div>
</div>

</body>
</html>
Answer:2

here is a jQuery solution... kindly check http://www.bootply.com/Swb3i8Henf

HTML

<button class="btnShowHide">Show</button> 
<div class="row col-lg-12">
    <div class="col-lg-6">
      <h3>Column 1</h3>
    </div>
    <div class="col-lg-6">
      <h3>Column 2</h3>
    </div>
    <div class="col-lg-6 hidden">
      <h3>Column 3</h3>        
    </div>
  </div>

CSS

.hidden{
  display:none;
  }

 .row div{
  border:1px red solid;
    }

jQuery

$(document).ready(function(){
  $('.btnShowHide').on('click', function(){
    $('.row div').toggleClass('col-lg-4').toggleClass('col-lg-6');
    $('.row div:last-child').toggleClass('hidden');
  });
});
Answer:3

Use Bootstrap's hidden class to hide any element. Further you can use different media specific utilities like hidden-xs, hidden-sm as per your need.

#whole {
  width:100%;
}

.myfix {
    table-layout: fixed;
    display:table;
    width: 100%;    
}

.myfix > .myfix1 {
    display:table-cell;  
    border: 1px solid black;
}
<!DOCTYPE html>
<head>
  <link rel="stylesheet" target='_blank' href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <div class="row col-lg-12  myfix" id="whole">
    <div class="myfix1">
        <h3>Column 1</h3>
    </div>
    <div class="myfix1">
        <h3>Column 2</h3>
    </div>
    <div class="myfix1 hidden">
        <h3>Column 3</h3>
    </div>
</div>

</body>
</html>
Answer:4

I have a task to create a node.js script that listens in a directory for new archive files to arrive and process them. I see that I can do this with fs.watch. The files are tar.gz archives, that ...

I have a task to create a node.js script that listens in a directory for new archive files to arrive and process them. I see that I can do this with fs.watch. The files are tar.gz archives, that ...

  1. node watch directory for changes
  2. node watch directory
  3. node-sass watch directory
  4. node.js watch directory for new files
  5. node fs watch directory
  6. node js watch directory
  7. node red watch directory
  8. node.js watch directory for changes
  9. node forever watch directory
  10. node.js fs.watch directory

I have a form with two select html tags and an input submit. To populate the value of option tags and to display the equivalent values of selected option tag, I use PHP, please see snippet below. Now,...

I have a form with two select html tags and an input submit. To populate the value of option tags and to display the equivalent values of selected option tag, I use PHP, please see snippet below. Now,...

  1. ajax foreach data
  2. ajax foreach json data
  3. ajax foreach loop json
  4. ajax foreach php
  5. ajax foreach result
  6. ajax foreach response
  7. ajax foreach table
  8. ajax foreach html
  9. ajax foreach jquery
  10. ajax foreach append
  11. ajax foreach object
  12. ajax foreach function
  13. ajax foreach id
  14. ajax foreach request
  15. ajax foreach error
  16. foreach ajax call
  17. foreach ajax success
  18. foreach ajax laravel
  19. foreach ajax javascript
  20. foreach ajax return

I would like to count values inserted into a form without refreshing the page. The below code works well if all of the inputs have "name='test'" set the same but I need name to be unique to process ...

I would like to count values inserted into a form without refreshing the page. The below code works well if all of the inputs have "name='test'" set the same but I need name to be unique to process ...

  1. jquery count input values
  2. how to count input values in javascript

In Aurelia application I have a "Rename" form with a single input <input ... value.bind="something.name" /> and two buttons: Save and Cancel. The same something object is already used in ...

In Aurelia application I have a "Rename" form with a single input <input ... value.bind="something.name" /> and two buttons: Save and Cancel. The same something object is already used in ...