Как сделать так, чтобы содержимое флекс-бокса не выходило за пределы исходной высоты страниц?

Ошибка: Произошла ошибка JNI, проверьте свою установку и повторите попытку в Eclipse Решение: Проверьте имя своего пакета, поскольку оно может сталкиваться с именем пакета в Ява. Просто измените имя пакета, чтобы решить проблему. :) [/ Д2]

2
задан dgknca 21 February 2019 в 18:58
поделиться

3 ответа

Я использовал offsetHeight

const textarea = document.querySelector("textarea");
const a = document.querySelector("#a");
const input = document.querySelector("input");
const h1 = document.querySelector("h1");

let a_h = a.offsetHeight;
let inp_h = input.offsetHeight;
let h1_h = h1.offsetHeight;

let total_height = a_h + inp_h + h1_h;

textarea.style.height = "calc(100% - " + total_height + "px)";
html, body {
    height: 100%;
    margin: 0;
    overflow:hidden;
}

input[type=text]{
    width: 100%;
    font-size: 32px;
    border: 3px solid #999;
    padding: 12px 20px;
    margin: 5px 10px;
    box-sizing: border-box;
    flex: 0 1 auto;
    outline: none;
}

div {
    display: flex;
}

.fillspace {
    display: flex;
    height: 100%;
}

input[type=text]:focus{
    border: 3px solid #555;
}

button {
    background-color: #0099cc;
    border: none;
    color: white;
    text-align: center;
    padding: 16px 32px;
    text-decoration: none;
    display: inline-block;
    font-size: 32px;
    margin: 5px 10px 5px 0;
}

button:hover{
    background-color: #007399;
    outline: none;
}

button:active{
    background-color: #007399;
}

textarea{
    outline: none;
    resize: none;
    font-size: 32px;
    border: 3px solid #999;
    padding: 12px 20px;
    margin: 5px 10px 10px 10px;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    flex: 1 1 auto;
}

textarea:focus{
    border: 3px solid #555;
}

h1{
    text-align: center;
    font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
}
<body>
    
    <h1>Command Queue</h1>

    <div id="a">
        <input placeholder="Type command here" type="text"/>
        <button>Run</button>
    </div>

    <div class="fillspace">
        <textarea id="commandOutput">{{.}}</textarea>
    </div>

</body>

0
ответ дан dgknca 21 February 2019 в 18:58
поделиться

Попробуйте это:

html, body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
}

body > * {
    flex: 0 0 auto;
}

input[type=text]{
    width: 100%;
    font-size: 32px;
    border: 3px solid #999;
    padding: 12px 20px;
    margin: 5px 10px;
    box-sizing: border-box;
    outline: none;
}

div {
    display: flex;
}

.fillspace {
    flex: 1 0 auto;
}

input[type=text]:focus{
    border: 3px solid #555;
}

button {
    background-color: #0099cc;
    border: none;
    color: white;
    text-align: center;
    padding: 16px 32px;
    text-decoration: none;
    display: inline-block;
    font-size: 32px;
    margin: 5px 10px 5px 0;
}

button:hover{
    background-color: #007399;
    outline: none;
}

button:active{
    background-color: #007399;
}

textarea{
    outline: none;
    resize: none;
    font-size: 32px;
    border: 3px solid #999;
    padding: 12px 20px;
    margin: 5px 10px 10px 10px;
    box-sizing: border-box;
    width: 100%;
}

textarea:focus{
    border: 3px solid #555;
}

h1{
    text-align: center;
    font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
}
<body>
    
    <h1>Command Queue</h1>

    <div class="cmd-group">
        <input placeholder="Type command here" type="text"/>
        <button>Run</button>
    </div>

    <div class="fillspace">
        <textarea id="commandOutput">{{.}}</textarea>
    </div>

</body>

0
ответ дан pinkhominid 21 February 2019 в 18:58
поделиться

Используя flex, вы можете решить эту проблему, изменив следующие правила CSS:

html, body {
    height: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
}
div {
    display: flex;
}

.fillspace {
    flex: 1
}

Обратите внимание, что вам нужен контейнер, отображаемый как flex, в данном случае с направлением столбца ( body ) и позже установите flex: 1 для контейнера, размер которого вы хотите увеличить.

Надеюсь, что это помогает,

С уважением

0
ответ дан lisdey89 21 February 2019 в 18:58
поделиться