When adjusting the size of the browser window, the div on my web page shifts to the bottom, creating a large empty space at

I have encountered an issue where, when I resize the browser window, my div moves to the bottom and leaves a large space at the top. I would like the div to remain in the center of the page, even if I resize the window to be smaller than the size of the div. Unfortunately, this was not covered in my school curriculum, but I am determined to align this div in the center of the page.

    <!DOCTYPE html>
<html>
<head>
<title>CSS Centering Made Easy.</title>

<style>

* {
    margin: 0;
    padding: 0;
}
html, body, .m {
    height: 100%;
    width: 100%;
}
.m {
    opacity:1;
    font-size: 0;
    overflow: auto;
    text-align: center;
    /*styles>>*/
    background-color: #8F1C10;
}
.m::before {
    content:'';
    display: inline-block;
    height: 100%;
    vertical-align: middle;
}
.m>div {
    display: inline-block;
    font-size: 19px;
    margin: 20px;
    max-width: 320px;
    min-height: 20px;
    min-width: 300px;
    padding: 14px;
    vertical-align: middle;
    /*styles*/
    color:white;
    background-color: #140A08;
    outline:none;
}

</style>

</head>
<body>

<title>CSS Centering Made Easy.</title>
<div class="m">
    <div contenteditable="true">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corporis, enim, possimus, voluptates, quia voluptatibus voluptas eum quaerat iure aperiam asperiores debitis fuga itaque quibusdam a ad odio assumenda iusto voluptatem.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quidem, ex quia consequatur quae quasi amet veniam est quas error quos perferendis ducimus non similique in soluta magnam dolore molestias veritatis.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptate, doloremque iste magni in eveniet ipsa odio mollitia eligendi magnam placeat aliquam hic reprehenderit reiciendis itaque assumenda ratione delectus. Alias, quis.</div>
</div>

</body>
</html>

Answer №1

margin: auto; is the key. Give this a shot:

<style>

* {
    margin: 0;
    padding: 0;
}
/*html, body, .m {
    height: 100%;
    width: 100%;
}*/
.m {
    opacity:1;
    font-size: 0;
    overflow: auto;
    text-align: center;
    margin: auto;
    /*styling>>*/
    background-color: #8F1C10;
}
.m::before {
    content:'';
    display: inline-block;
    height: 100%;
    vertical-align: middle;
}
.m>div {
    display: inline-block;
    font-size: 19px;
    margin: 20px;
    max-width: 320px;
    min-height: 20px;
    min-width: 300px;
    padding: 14px;
    vertical-align: middle;
    /*styling*/
    color:white;
    background-color: #140A08;
    outline:none;
}

</style>

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

Guide on intercepting errors and sending the corresponding error message back to the client side using Node.js

Attempting to capture errors after utilizing Node.js to search for data in the database. However, whenever there is an error, the server consistently sends {errormsg: null} to the client side. I anticipate a more detailed explanation within the errormsg ...

"Click to view the latest data visualization using the Chart.js

I am exploring ways to enhance the animations in Chart.js for a new web project. The content is organized in tabs, with the chart displayed on the third tab out of four. Currently, the chart animates upon loading. How can I make it so that when #chartTrig ...

Modify the navbar background color in bootstrap-vuejs

As per the information provided in the documentation, the instructions for setting styles for the navigation bar are as follows: <b-navbar toggleable="lg" type="dark" variant="info"> <!-- Or --> <b-navbar toggleable="lg" type="dark" variant ...

Retrieving data via AJAX from an SD card

I am using the Atmel SAM4E-EK microcontroller as a server to host a webpage and send data over HTTP protocol. I am currently facing an issue with the download function while trying to download a file from my sd_card, which will not be larger than 512MB. s ...

Do you believe that using bower to install HTML5Boilerplate is a beneficial decision?

Is it recommended to use HTML5 Boilerplate with Bower for installation? What steps should one take afterwards, considering that it has its own directory structure for CSS and JavaScript, leading everything to be contained under bower_components/html5boil ...

Enhancing Images with Dynamic Captions Using JQuery

I have created a code to add image captions to different div blocks, and it works as intended. However, I am looking for ways to optimize the code and make it shorter. If you have any advice on how to improve it, please let me know! Thank you in advance. ...

Issues arising with the functionality of CSS media queries when used in conjunction with the

I created a webpage that is functioning well and responsive on its own. However, when I integrate the same files with the Spring framework, the responsiveness of the webpage seems to be lost. To ensure the responsiveness of the Spring webpage, I tested it ...

Guide on adding a line break between two inline-block elements

Struggling to find a way to add a line break between two div elements in this fiddle here. The issue is that I want the elements centered and also have control over line breaks. Using float allows for line breaks with: .article:after { content: ' ...

Migrating WordPress Gutenberg to a Separate React Component: Troubleshooting Missing CSS Styles

I am in the process of developing a standalone version of the Gutenberg block editor from Wordpress that can function independently outside of the Wordpress environment. My goal is to integrate the Gutenberg editor as a React component within an existing R ...

Are there any ways to bring visual attention to a GoDaddy template's SEND button using HTML or JS when the original code is unavailable?

I'm currently working on a GoDaddy website using a template that doesn't clearly highlight the SEND button in a Contact Us form. In order to comply with WCAG accessibility standards, active elements must have visible focus indicators. However, si ...

Using AJAX to showcase data from a table in a database using the <select> tag but with an unfinished submit process

I am encountering an issue with my code. When I submit the value in getinv.php, it only returns a partial value. For example, when I click '2016-08-27', it only retrieves '2016'... My question is, how can I ensure that the exact value ...

Tips for creating a fixed footer that adjusts with a flexible wrapper

Feeling incredibly stressed, I embarked on a quest to find the perfect sticky footer. After searching Google for what seemed like an eternity, I came across multiple tutorials recommending the use of min-height:100%. However, this approach caused the wrap ...

In landscape mode on Safari for iOS, the final item in a vertical flexbox may be cut off

Describing my app: It is structured as a 3-row flexbox column. <div class="app" style="display: -webkit-flex; -webkit-flex-direction: column; -webkit-justify-content: space-around;"> <div class="question-header" style="-webkit-flex: 0 0 0;"&g ...

Designing Interactive Interfaces using React Components for Dynamic Forms

Is there a way to implement dynamic forms using React Components? For instance, I have a form displayed in the image below: How do I structure this as a React component? How can I incorporate interactivity into this component? For example, when the "+ A ...

Exploring the art of div transitions and animations using React and Tailwind CSS

I successfully implemented the sidebar to appear upon clicking the hamburger icon with a transition. However, I am now facing the challenge of triggering the transition when the close button is clicked instead. I have attempted using conditional operations ...

Creating artwork: How to resize images without losing clarity

Struggling to display an image in a canvas element that needs to be a certain percentage of its parent container's width. Despite my efforts, the image seems to blur once added to the canvas, which is not the desired effect. I attempted to disable th ...

Adding margin padding to a Material UI Navbar: Step-by-step guide

Hey there, I've added buttons to my Navbar from Mui. However, I'm running into an issue where the margin and padding won't change no matter what I do. I'm trying to create some space between them. Please see the code below: import { use ...

Issues with styled-components media queries not functioning as expected

While working on my React project with styled components, I have encountered an issue where media queries are not being applied. Interestingly, the snippet below works perfectly when using regular CSS: import styled from 'styled-components'; exp ...

Overlap of Navigation Bar and Carousel

Encountering an issue. I recently made a modification to my website in hopes of integrating a full-width carousel instead of a jumbotron. However, there seems to be a problem as my navbar is overlapping the jumbotron section along with the caption and oth ...

Issue with the app not redirecting properly at launch

Upon starting the app, I'm attempting to redirect the page if the user is already logged in. if (!isLoggedIn()) { mainView.router.loadPage({ url: 'index.html', ignoreCache: true, reload: false }); } else { $('#txtUserName').html(l ...