获取显示的网页的大小没有浏览器应用程序栏与CSS

时间:2016-11-10 18:02:59

标签: html css

我正在创建一个简单的网页,显示来自文本输入的文本,我想让文本输入占用整个显示的网页(没有浏览器栏),100vh技术包括浏览器栏和我不想猜测顶部的大小

这是我的代码:



function focus() { // to easily focus an element
	document.getElementById("title").focus();
}

document.addEventListener('click', function (event) { // make sure the user's focus is stuck to the text input 
	if (event.target !== document.getElementById("title")) {
		document.getElementById("title").focus();
	}
}, false);
window.onload = function () {document.getElementById("title").focus();};

function apply() { // applies title
	setTimeout(function () {
		var str = document.getElementById("title").value;
		if (!str.replace(/\s/g, '').length) {
			document.title = "title-text";
		} else {
			document.title = str;
		}
	},1);
}

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>title-text</title>
	</head>
	<body>
		<input type="text" id="title" onkeypress="apply()" autocomplete="off">
	</body>
</html>
&#13;
&#13;
&#13; (JS将焦点绑定到文本框)

1 个答案:

答案 0 :(得分:0)

使用以下css类来实现此目的。

body{
  margin:0;
  overflow:hidden;
}

#title{
  height: 100vh;
  width:100vw;
}