Div height:0px does not work?

后端 未结 10 1274
既然无缘
既然无缘 2020-12-05 04:42

Setting a div height to 0px does not seem to work.

The div expands to show it

相关标签:
10条回答
  • 2020-12-05 04:43

    You could try adding "overflow:hidden" to the style

    0 讨论(0)
  • 2020-12-05 04:44

    Set overflow:hidden. Otherwise the content will expand the wrapping element.

    0 讨论(0)
  • 2020-12-05 04:51

    For me, on Windows 10, Firefox 58.0.1, it wouldn't hide completely unless using this:

    display: block !important;
    line-height: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    zoom: 1 !important;
    padding: 0 !important;
    margin-bottom: 0;
    border: none;
    
    0 讨论(0)
  • 2020-12-05 04:51
    #yiv1734505183 .yiv1734505183portrait{
        display:none;
        font-size:0;
        max-height:0;
        line-height:0;
        padding:0;
        overflow:hidden;
    }
    
    @media (min-width:481px){
        #yiv1734505183 .yiv1734505183mobile-hide{
            display:block;
            overflow:visible;
            width:auto !important;
            max-height:inherit !important;
            min-height:auto !important;
        }
    }
    @media (min-width:481px){
        #yiv1734505183 .yiv1734505183portrait{
            display:none;
            font-size:0;
            line-height:0;
            min-height:0;
            overflow
    
    0 讨论(0)
  • 2020-12-05 04:52

    If you really want to be sure it's gonna be have no height you could use something like this:

    display: block;
    line-height:0;
    height: 0;
    overflow: hidden;
    

    If you're still having problems on IE, you could also add

    zoom: 1;
    

    to it in a stylesheet targeted at IE with a conditional comment. That'll trigger the hasLayout property in IE.

    And display:none isn't the same as setting it to zero height. Just look at the various clearfix solutions for a case where not removing it from the flow is crucial.

    0 讨论(0)
  • 2020-12-05 04:55

    Not quite sure what you're trying to do, out of context, but try this:

    display:none;
    overflow:hidden:
    height:0;
    line-height:0;
    border:0;
    margin:0;
    
    0 讨论(0)
提交回复
热议问题