Background/element goes black when entering Fullscreen with HTML5

前端 未结 7 1582
旧时难觅i
旧时难觅i 2020-12-29 22:51

I\'m using the following script to make my web app go fullscreen...

function enterFullscreen(){
    var element = document.getElementById(\'container\');
            


        
相关标签:
7条回答
  • 2020-12-29 23:18

    None of the other answers is working for me (Chrome 70 or FF 63)

    Adding this to the CSS file does work

    ::backdrop
    {
        background-color: white;
    }
    
    0 讨论(0)
  • 2020-12-29 23:22

    The default background color of the browser's full-screen "visual environment" is black. Your content actually is there, but it's currently black text on black background, so you can't see it (try highlighting or pressing Ctrl+A to see for yourself).

    If you want to make the background a different color, you must specify a CSS rule to set the background-color property to something other than the default. So, in your case:

    #container:fullscreen {
        background-color: rgba(255,255,255,0);
    }
    #container:-webkit-full-screen {
        background-color: rgba(255,255,255,0);
    }
    #container:-moz-full-screen {
        background-color: rgba(255,255,255,0);
    }
    

    should do the trick. (Make sure you use the appropriate vendor version(s) -- :-webkit-full-screen and :-moz-full-screen -- until the spec finalizes; see MDN for more information.)

    In fact, maybe just

    *:fullscreen, *:-webkit-full-screen, *:-moz-full-screen {
        background-color: rgba(255,255,255,0);
    }
    

    EDIT by @DevilishDB: used rgba for a transparent BG and added the * selector to make the previous thing work

    0 讨论(0)
  • 2020-12-29 23:23

    I don't know the exact answer to your question, but this information might help:

    I had a similar black background problem with enterFullscreen(document.body);. The background color became normal after I changed the line to enterFullscreen(document.documentElement);. The css I used is body{background-color: #D7D7D7; margin: 0px;}.

    0 讨论(0)
  • 2020-12-29 23:23

    I spent hours to find a trick for this issue.

    I ended by doing that :

    • Fixing a white color to backdrop
    • And using z-index, to push it down

    Then :

    • Fixing a white color to the html page content
    • And using z-index, to push it up (above backdrop)

    It works for me on Firefox and Chrome

    ::backdrop {
        z-index:0;  
        background-color: white !important;
    }
    
    html, *:fullscreen, *:-webkit-full-screen, *:-moz-full-screen {
        background-color: white !important;
        z-index:1;
    }
    
    0 讨论(0)
  • 2020-12-29 23:31

    Don't know why, but it seem that the background of the body element is not displayed in fullscreen or become transparent...

    I fixed this by setting a background color to the html element, and it work just fine:

    html {
        background-color: #ffffff;
        /* Or any color / image you want */
    }
    
    0 讨论(0)
  • 2020-12-29 23:35

    the main solution didn't work to me :-( I found another solution, but yes, in the css:

    :-webkit-full-screen, :fullscreen, :-ms-fullscreen, :-moz-full-screen {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0; 
    background: none;}
    

    I understand this is for the position of my elements, but I no sure. Hope help to somebody. Bye and thanks.

    0 讨论(0)
提交回复
热议问题