html元素全屏

html-css014

html元素全屏,第1张

html实现元素全屏的时候,会在该元素上加上如下css,该css无法被覆盖和修改。

我们可以通过对元素通过调用requestFullscreen来开启全屏

通过调用document.exitFullscreen来退出全屏

用js来控制就行了

先获取屏幕的宽 然后减去页面宽 然后再除以二就行

屏幕宽度:screen.width

用一个div来演示了:

<div id="div"></div>

<script>

function centers(){

var divs = document.getElementById("div")

document.getElementById("div").style.marginLeft = (screen.width -divs.offsetWidth)/2+"px"

}

</script>