我正在尝试使用CSS和HTML在线创建一个小型记事本应用程序。出于某种原因,我的应用程序会创建一个奇怪的故障,您可以在文本区域向下滚动得足够远,然后向上滚动以查找缺少的标题。
https://jsfiddle.net/2v7ptadh/
我该如何解决这个问题?
这是创建错误的CSS代码。如果要查看完整代码,请单击上面的JS Fiddle链接。
html,
body {
display: block;
box-sizing: border-box;
padding: 0;
margin: 0;
background-color: #888;
height: 100%;
width: 100%;
overflow-y: hidden;
}
div#header {
display: block;
width: 100%;
height: 40px;
border-left: 2px solid rgb(100, 125, 130);
border-top: 2px solid rgb(150, 175, 140);
border-bottom: 2px solid rgb(60, 48, 75);
border-right: 2px solid rgb(80, 84, 90);
background: #bbb;
box-sizing: border-box;
line-height: 40px;
text-align: center;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
font-weight: 900;
z-index: 4
}
div#app {
z-index: 2;
display: block;
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 0;
margin: 0;
}
textarea#app-input {
display: block;
box-sizing: border-box;
padding: 4px;
margin: 0;
border: none;
outline: none;
width: 100%;
height: 100%;
line-height: 23px;
font-size: 20px;
resize: none;
}
textarea::selection {
background: #000;
color: #fff;
}
答案 0 :(得分:1)
如果您要将html/body
设置为height: 100%; overflow-y: hidden;
,则#app
不应为height: 100%
- 将其更改为height: calc(100% - 40px)
40px
是标题高度。这会将所有内容保留在视口中。
@import url('https://fonts.googleapis.com/css?family=Open+Sans');
html,
body {
display: block;
box-sizing: border-box;
padding: 0;
margin: 0;
background-color: #888;
height: 100%;
width: 100%;
overflow-y: hidden;
}
div#header {
display: block;
width: 100%;
height: 40px;
border-left: 2px solid rgb(100, 125, 130);
border-top: 2px solid rgb(150, 175, 140);
border-bottom: 2px solid rgb(60, 48, 75);
border-right: 2px solid rgb(80, 84, 90);
background: #bbb;
box-sizing: border-box;
line-height: 40px;
text-align: center;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
font-weight: 900;
z-index: 4
}
div#app {
z-index: 2;
display: block;
width: 100%;
height: calc(100% - 40px);
box-sizing: border-box;
padding: 0;
margin: 0;
}
textarea#app-input {
display: block;
box-sizing: border-box;
padding: 4px;
margin: 0;
border: none;
outline: none;
width: 100%;
height: 100%;
line-height: 23px;
font-size: 20px;
resize: none;
}
textarea::selection {
background: #000;
color: #fff;
}
<div id="header">ONLINE NOTEPAD</div>
<div id="app">
<textarea id="app-input"></textarea>
</div>
答案 1 :(得分:0)
尝试删除overflow-y:隐藏自html和body
html,
body {
display: block;
box-sizing: border-box;
padding: 0;
margin: 0;
background-color: #888;
height: 100%;
width: 100%;
}