Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'hidden' property does not work with flex-box

Tags:

I have the following code using flex-box

  <!DOCTYPE html>    <polymer-element name='test-flex'>     <template>        <style>          .lab-flex-col-container {            display: flex;            flex-flow: column;            align-content: center;            background-color: gold;            border-radius:5px;            margin: 5px;         }          .lab-flex-col {           display:flex;           flex-flow:column;           align-self:center;           margin:5px;         }          .margin2 { margin: 2px; }         </style>        <form id='form'         class='form'>          <div class='lab-flex-col-container'>            <div class='lab-flex-col' id='hidden-does-not-work' hidden>               <input id='hidden-works' type='text'>            </div>             <div id='hidden-works' hidden>               <textarea></textarea>            </div>            <div id='hidden-does-not-work-here-either' class='lab-flex-col' hidden>               <button>Save</button>            </div>          </div>       </form>      </template>      <script type="application/dart;component=1">        import 'package:polymer/polymer.dart';       import 'dart:html';         @CustomTag( 'test-flex' )       class TestFlex extends PolymerElement       {          TestFlex.created() : super.created();          ready()         {           $['hidden-does-not-work'].hidden = true;         }          void syncDb ( Event e, var detail, var target )         {          }          @override         void enteredView()         {            super.enteredView();             $['hidden-does-not-work-here-either'].hidden = true;          }       }      </script>   </polymer-element> 

Why does the presence of the lab-flex-col class prevents the hiding of the text input? I have tried hidden='hidden' and this does not work either.

When hidden is present as in the textarea element, it works as expected, but once the flex-box class is added, it ceases to work and the element remains visible.

like image 362
st_clair_clarke Avatar asked May 21 '14 01:05

st_clair_clarke


People also ask

Why is my flexbox not wrapping?

If you are using flexbox and want the content to wrap, you must specify flex-wrap: wrap . By default flex items don't wrap. To have the images be three-across, you should specify flex-basis: 33.33333% .

How do I turn off the overflow on my flexbox?

Simply add min-height: 0; to the flex child that has our overflow container. Boom!

Which property is used to align Flex items?

The align-content property is used to align the flex lines.

How do I fix the footer at the bottom of my flex?

Just add margin-top: auto; to the footer. That will cause it to stick to the bottom of its container.


2 Answers

The easiest fix is to override the entire behavior with an attribute selector. No document changes needed:

[hidden]{   display:none; } 

http://jsfiddle.net/mjxcrrve/

I am guessing the logic behind the default behavior is to allow overriding the "hidden" html attribute with CSS. "hidden" is more or less an implicit "display: none", so overriding the "display" style is a a natural candidate. But I agree it seems ill-thought-out that modifying pure layout should affect visibility.

like image 118
Joachim Lous Avatar answered Oct 04 '22 04:10

Joachim Lous


This gets the job done:

[hidden] {     display: none !important; } 

Note that the !important part is important to prevent the display: none declaration from being overridden by your other CSS code.

More info: https://meowni.ca/hidden.is.a.lie.html

like image 45
Šime Vidas Avatar answered Oct 04 '22 02:10

Šime Vidas