Aligning the content vertically in the second row of a two-row layout

Check out this jsfiddle example

I'm trying to achieve a layout with two rows, one for the header and one for the content. The header has a fixed height, and I want the content to be centered vertically in the second row.

I attempted using position: absolute and margin: auto to center the content, but it ended up sliding behind the header when the browser was resized too small.

I thought about using a div to cover the entire second row with the content, but I couldn't make it work. I'd like to avoid using table tags if possible.

Answer №1

CSS Only Solution Using calc

Check out the Live Demo

HTML:

<div class="Site">
    <header class="Header">
        <!-- content -->
    </header>
    <div class="ContentContainer">
        <span class="Centerer"></span>
        <div class="Content">
            <ul style="list-style: none; margin: 0; padding: 0">
                <li>
                    Text
                </li>
                <li>
                    Text
                </li>
                <li>
                    Text
                </li>
            </ul>
        </div>
    </div>
</div>

CSS:

*
{
    margin: 0;
    padding: 0;
}
html, body
{
    height: 100%;
}
.Site
{
    height: 100%;
}
.Header
{
    height: 120px;
    background-color: darkblue;
}
.ContentContainer
{
    background-color: azure;
    height: calc(100% - 120px);
}
.Centerer
{
    height: 100%;
    display: inline-block;
    vertical-align: middle;
}
.Content
{
    display: inline-block;
    vertical-align: middle;
}

Cleaner Version with Pseudo Elements

View the cleaner version with pseudo elements in this Working Fiddle

<div class="Site">
    <header class="Header">
        <!-- content -->
    </header>
    <div class="ContentContainer">
        <div class="Content">
            <ul style="list-style: none; margin: 0; padding: 0">
                <li>
                    Text
                </li>
                <li>
                    Text
                </li>
                <li>
                    Text
                </li>
            </ul>
        </div>
    </div>
</div>

*
{
    margin: 0;
    padding: 0;
}
html, body
{
    height: 100%;
}
.Site
{
    height: 100%;
}
.Header
{
    height: 120px;
    background-color: darkblue;
}
.ContentContainer
{
    background-color: azure;
    height: calc(100% - 120px);
}
.ContentContainer:after
{
    content: '';
    height: 100%;
    display: inline-block;
    vertical-align: middle;
}
.Content
{
    display: inline-block;
    vertical-align: middle;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtaining values from a table using jQuery

The code snippet below is used to create a table: <table class="table table-bordered table-striped" id="assignedvs"> <thead> <tr> <th>VlId</th> <th>Name</th> ...

Achieving a perfect curve with a specific circle radius using CSS

I came across a design tutorial on magic indicators from YouTube and created the following design: https://i.sstatic.net/IJjdCGWk.png However, I am looking to achieve a smoother curve as a continuation of the circle when selected, instead of using element ...

An intriguing inquiry regarding HTML form intricacies

Looking to enhance the source code by adding a new column to display Client Mobile, Client Office Telephone, and Client E-mail in a separate popup PHP page. My attempt involved adding a form and submit button to generate the new column. However, pressing ...

Displaying an image based on the selected dropdown using PHP, AJAX, and JQuery

This requires knowledge of PHP, AJAX, and JQuery. Hopefully, this question is straightforward. I have a dynamic dropdown menu that shows content when an option is selected. The content I want to display is an image. To achieve this, I am working with two ...

Issues with Skrollr JS on mobile device causing scrolling problem

Currently facing an issue with Skrollr js. It is functioning perfectly in web browsers and mobile devices. However, there seems to be a problem when tapping on a menu or scrolling down arrow as it does not initiate scrolling. Assistance would be greatly ...

Tips for concealing the header menu when scrolling on a Drupal website

Hey there, I need some help with hiding the header div while scrolling in Drupal. <header class="header<?php print theme_get_setting('header_top_menu') && !$one_page ? '' : ' header-two'; ?>"> <div clas ...

Is there any practical reason to choose tables over CSS for controlling layouts?

As I dive into updating a large amount of code for a web application, I've noticed that tables are heavily used throughout to manage layout. Being relatively new to HTML programming, I find myself questioning the necessity of using tables when CSS co ...

Is it possible to achieve efficient Autocompletion features within VS Code?

Just had my first experience with PhpStorm and I must say, I'm impressed, especially with the completion feature. Pressing Ctrl + Space on my Mac gives me relevant suggestions, like when I'm in a JS file and my project includes jQuery, I get Ele ...

Using JavaScript to toggle the visibility of grids depending on the radio button choice and then triggering this action by clicking on the search button

As a newcomer to AngularJS development, I am encountering some challenges while attempting to implement the following scenario. Any suggestions or guidance would be greatly appreciated. I aim to showcase either one or two Angular UI grids based on the rad ...

Is it possible to modify the button icon on hover by utilizing chakra-ui and vanilla-extract?

My stack includes nextjs13, chakra-ui, and vanilla-extract Seeking guidance on how to update both icon and text within a button upon hover, utilizing chakra-ui and vanilla-extract. The current setup of my button is as follows: <Button > <svg wi ...

Creating a Dual Linear Gradient Background with Tailwind: Step-by-Step Guide

Can you use two linear backgrounds on a single element in Tailwind CSS? I found this CSS code that seems to achieve it: background-image: linear-gradient(to right, #f8fafb 50%, #161616 50%), linear-gradient(to right, #161616 50%, #f8fafb 50%); I att ...

The footer is being obscured by the sidebar

#contents { width: 1100px; margin-left: auto; margin-right: auto; } #sidebar { padding: 10px; position: sticky; top: 20px; left: 10px; width: 150px; border-right: 1px solid black; float: left; } #main { padding: 15px; margin-left: ...

The problem of SVG rendering order requires a solution that does not rely on javascript

I am new to experimenting with inline svg, and I wanted to share my code: <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="350" height="350"> <defs> <style> .ring { transform-origin: 175px 175px; } ...

How can I incorporate a personalized SVG path to serve as a cursor on a webpage?

Is there a way to enhance the functionality of binding the 'mousemove' event to a div and moving it around the page while hiding the real cursor? Specifically, can we change the shape of the circle to an SVG path and drag the SVG path around the ...

Inquire about Javascript appendChild Function

As I dive into learning JavaScript, I encountered an issue with my code. I have created a button that, when clicked, should append some text to all paragraphs on my page. However, for some reason, it's not working as expected. Here's my code: &l ...

Ways to increase the size of a div to match the maximum height of its parent container

My current project involves using an angular dialog layout where the API to open and manage the dialog comes from a separate library. The dialog's parent container has a max-height attribute, meaning the dialog's height is determined by its conte ...

Enhancing the Appearance of WooCommerce Product Descriptions

Having some trouble with my website . There are two descriptions on the "Product" page - one above the tabs and one inside the tabs. Trying to change the text color in the tab section to black, but when I adjust the body text color it affects both areas. I ...

Tips for adjusting an @media css for a material-ui react component

After posting this inquiry about overriding a CSS property in a material-ui component, I received a helpful example. However, I encountered difficulty when attempting to set the height of the Toolbar component due to an overarching @media specification. My ...

Apply pointer style to the CSS only when a division contains text

If there is plain text inside a div with class="x95qze", how can we add cursor:pointer only to the second div that contains the text Cursor pointer required here. The div with class="x95qze" will not change. The content of the div may ...

Unable to retrieve DOM value due to Vue.js template being inaccessible in Chromium, including from both DevTools and extensions

Currently, I’m developing a Chrome extension that needs to retrieve specific values from a webpage such as the item title. However, instead of fetching the actual title, it is reading a Vue.js template variable. Even when I use DevTools to inspect the p ...