Orientation of vertical text with unknown data at all



  • Good day! I am interested in the possibility of centralizing a building block within an unknown height that is inside an unknown height. I mean, I've been reviewing a lot of resources and questions here, everyone's suggesting that if there's a parent's height or at least a parent's block, everything works. That's right. What if I have a CSS code like this:

    #preloader {
        position:fixed;
        top:0;
        left:0;
        right:0;
        bottom:0;
        z-index: 9999;
    }
    .loader {
        position: absolute;
    }
    

    And this HTML:

    <div id="preloader">
        <div class="loader">  
            <span id="loader_txt">Здесь текст</span>
        </div>
    </div>
    

    I didn't leave it on purpose in the code of implantation on the construction elements because it's obvious. I'm asking a little philosophical. If the heights are unknown, do you have to use JS? Thank you.



  • You can centralize content in "unknown" with help. https://developer.mozilla.org/ru/docs/Web/CSS/CSS_Flexible_Box_Layout ♪

    In your case, it will be like this:

    #preloader {
        position: fixed;
        top:0;
        left:0;
        right:0;
        bottom:0;
        z-index: 9999;
        background: rgba(0, 0, 0, .7);
    
    display: flex; /* Магия */
    align-items: center; /* Центрируем по вертикали */
    justify-content: center; /* Центрируем по горизонтали */
    

    }

    Demo: http://jsfiddle.net/42f10edL/1/

    Several interesting resources for flexbox:

    1. http://habrahabr.ru/post/242545/
    2. http://caniuse.com/#feat=flexbox
    3. https://css-tricks.com/snippets/css/a-guide-to-flexbox/




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2