Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Webkit Full Screen Detection Not Working

Tags:

html

css

webkit

I am having a really tuff time getting CSS3 to detect full screen. Right now, I have:

:-webkit-full-screen body {
    color: red;
    background: red;
}

When hitting F11 in my browser, nothing turns red.

For testing, I am trying to turn everything red but not having success. I am using Chromium 31.0.1650.57. Am I using :-webkit-full-screen incorrectly?

like image 422
dman Avatar asked Jan 24 '14 20:01

dman


People also ask

How do I make CSS full screen?

Fullscreen mode and the Fullscreen API If you switch to your browser's fullscreen mode ( ⌃ + CMD + F on MacOS, F11 on Windows) and you select an element using :fullscreen , it won't match that element. Instead, an element matches :fullscreen when it enters fullscreen mode using the Fullscreen API.

How do you make a background color full screen in CSS?

We can set a full-page background color by simply changing the screen height of an HTML body. In Tailwind CSS, we use an alternative of CSS background-color property which is represented as background-color-opacity ( eg: bg-blue-200 ) and it is used to specify the background color of an element.

How do I automatically open a web page in full screen mode in HTML?

The full screen can also be generated on most web browsers by pressing the F11 key.


2 Answers

I think this has something to do with you pressing F11 to get fullscreen. You need to trigger the fullscreen via webkitRequestFullscreen and the other cross-browser versions of this. Also, I think that the CSS doesn't apply to the body. Try to use a wrapper and apply it to that element:

document.getElementById('gofullscreen').addEventListener('click', function() {
  var elem = document.getElementsByTagName("body")[0];
  elem.webkitRequestFullscreen();
  if (elem.requestFullscreen) {
    elem.requestFullscreen();
  } else if (elem.msRequestFullscreen) {
    elem.msRequestFullscreen();
  } else if (elem.mozRequestFullScreen) {
    elem.mozRequestFullScreen();
  } else if (elem.webkitRequestFullscreen) {
    elem.webkitRequestFullscreen();
  }
});
html,
body {
  width: 100%;
  height: 100%;
}

#wrapper {
  height: 100%;
  width: 100%;
}

 :-webkit-full-screen #wrapper {
  color: red;
  background: red;
}
<div id="wrapper">
  <a href="#" id="gofullscreen">fullscreen</a>
</div>

See Fiddle and Fullscreen version (Use the Fiddle link to see the code and the Fullscreen version to see it working, Fiddle doesn't allow fullscreen I think).

But the :-webkit-full-screen and the like are experimental, so don't rely on it. https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode

like image 196
putvande Avatar answered Sep 20 '22 11:09

putvande


Making an element go full-screen

Like this on some browser it may work:

function gofullscreen() {
        var elem = document.getElementById("VideoWrapper");
        elem.webkitRequestFullscreen();
        if (elem.requestFullscreen) {
            elem.requestFullscreen();
        } else if (elem.msRequestFullscreen) {
            elem.msRequestFullscreen();
        } else if (elem.mozRequestFullScreen) {
            elem.mozRequestFullScreen();
        } else if (elem.webkitRequestFullscreen) {
            elem.webkitRequestFullscreen();
        }
    }
$("#buttonGo").click(function(){gofullscreen()});

**//CSS**   

:-webkit-full-screen #VideoWrapper {
    color: red;
    background: red;
  width: 100%;
  height: 100%;
}

:-moz-full-screen #VideoWrapper {
    color: red;
    background: red;
  width: 100%;
  height: 100%;
}

:-ms-fullscreen #VideoWrapper {
    color: red;
    background: red;
  width: 100%;
  height: 100%;
}

:full-screen #VideoWrapper {
    color: red;
    background: red;
  width: 100%;
  height: 100%;
}

:fullscreen #VideoWrapper {
    color: red;
    background: red;
  width: 100%;
  height: 100%;
}

On some browser it might not work

To make it work across regardless of standard Css

$("#buttonGo").click(function(){
$("#VideoWrapper").css({height: '100%',width:'100%',background:'red',color:'red'});
gofullscreen()});

This work well on chrome , ff , ms

like image 39
ShapCyber Avatar answered Sep 16 '22 11:09

ShapCyber