Skip to content

Commit fa1b8d7

Browse files
committed
Add option to stretch the body to the full height
Using CSS flexboxes, we can stretch the document body to the full height. For doing so, we will need to use a flexbox layout from some element of which we know the desired minimal height up to the element in the DOM tree which should stretch. We achieve the stretching by defining the minimum height of the body to be 100 viewport height units and adding the `flex-pass` class to all elements in between. The `flex-pass` class sets the display method of the element to be a flexbox to allow stretching of the children, and sets its own grow and shrink to 1. To counter some rounding error encountered in Gecko and derived (firefox) browsers, we subtract 1 pixel from the full viewport height to prevent a minimal 1 pixel scrollbar.
1 parent b922acf commit fa1b8d7

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

webapp/public/style_domjudge.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ body.static {
2929
padding-top: 1rem;
3030
}
3131

32+
/* Some browsers have a rounding error in flex, so waste 1px to prevent scrollbars. */
33+
.fill-height {
34+
box-sizing: border-box;
35+
display: flex;
36+
min-height: calc(100vh - 1px);
37+
}
38+
39+
.flex-pass {
40+
display: flex;
41+
flex-direction: column;
42+
flex: 1;
43+
}
44+
45+
/* Override the bootstrap active tab to be flex instead of block by a more specific selector. */
46+
.fill-height .flex-pass.tab-pane.active {
47+
display: flex;
48+
}
49+
3250
/* menu */
3351
#menuDefault ul li.nav-item {
3452
white-space: nowrap;

webapp/templates/base.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
<link rel="stylesheet" href="{{ asset('css/custom/' ~ file) }}">
2828
{% endfor %}
2929
</head>
30-
<body{% if static is defined and static %} class="static"{% endif %}>
30+
<body class="{% if fill_height is defined and fill_height %} fill-height{% endif %}{% if static is defined and static %} static{% endif %}">
3131
{% block menu %}{% endblock %}
3232
{% block body %}
33-
<div class="container-fluid">
34-
<div class="row">
35-
<div class="col-12">
33+
<div class="container-fluid{% if fill_height is defined and fill_height %} flex-pass{% endif %}">
34+
<div class="row{% if fill_height is defined and fill_height %} flex-pass{% endif %}">
35+
<div class="col-12{% if fill_height is defined and fill_height %} flex-pass{% endif %}">
3636
{% block messages %}
3737
{% include 'partials/messages.html.twig' %}
3838
{% endblock %}

0 commit comments

Comments
 (0)