Web browser displaying vertical scroll bars centered on the page

I'm new to HTML and have been experimenting with this CSS file to center my form. I've managed to get it working, but the issue now is that it's causing scroll bars to appear on the web browser. How can I resolve this without them?

@import url(https://fonts.googleapis.com/css?family=Roboto:300);
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.inner {
background: #FFFFFF;
width: 400px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.inner input[type=text],
.inner input[type=password] {
font-family: "Roboto", sans-serif;
outline: 0;
background: #f2f2f2;
width: 100%;
border: 0;
margin: 0 0 15px;
padding: 15px;
box-sizing: border-box;
font-size: 14px;
}
.inner .RememberMe input,
.inner .RememberMe label {
float: right;
color: #b3b3b3;
font-size: 12px;
margin-bottom: 15px;
margin-top: -8px;
}
.inner button {
font-family: "Roboto", sans-serif;
text-transform: uppercase;
outline: 0;
background: #4CAF50;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
}
.inner button:hover,
.inner button:active,
.inner button:focus {
background: #43A047;
}
.inner .message {
margin: 15px 0 0;
color: #b3b3b3;
font-size: 12px;
}
.inner .message a {
color: #4CAF50;
text-decoration: none;
}
.inner .checkbox {
margin: 15px 0 0;
color: #b3b3b3;
font-size: 15px;
}
.inner .register-form {
display: none;
}
body {
/* fallback for old browsers */
font-family: "Roboto", sans-serif;
-webkit-font-smoothing: antialiased;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="outer">
<div class="middle">
<div class="inner">

<form class="register-form">
<input type="text" placeholder="Username" id="register_username" />
<input type="password" placeholder="Password" id="register_password" />
<input type="text" placeholder="Email address" id="register_email" />
<button id="register_button">create</button>
<p class="message">Already registered? <a href="#">Sign In</a>
</p>
</form>

<form class="login-form">
<input type="text" placeholder="Username" id="login_username" />
<input type="password" placeholder="Password" id="login_password" />
<div class="RememberMe">
<input type="checkbox" id="remember_me">
<label>Remember me</label>
</div>
<button id="login_button">login</button>
<p class="message">Not registered? <a href="#">Create an account</a>
</p>
</form>

</div>
</div>
</div>

Answer №1

The issue arises from having a div set to 100% width/height while there is a margin present in the body.

To resolve this, simply update the body section of your CSS code to:

body {
  padding: 0;
  margin: 0;
  /* fallback for older browsers */
  font-family: "Roboto", sans-serif;
  -webkit-font-smoothing: antialiased;
}

Answer №2

Make sure to add overflow:hiddento the body or any parent container.

@import url(https://fonts.googleapis.com/css?family=Roboto:300);
body{
  overflow:hidden;
}
.outer {
  display: table;
  position: absolute;
  height: 100%;
  width: 100%;
}

.middle {
  display: table-cell;
  vertical-align: middle;

}

.inner {
  background: #FFFFFF;
  width: 400px;
  margin: 0 auto 100px;
  padding: 45px;
  text-align: center;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}

.inner input[type=text],
.inner input[type=password] {
  font-family: "Roboto", sans-serif;
  outline: 0;
  background: #f2f2f2;
  width: 100%;
  border: 0;
  margin: 0 0 15px;
  padding: 15px;
  box-sizing: border-box;
  font-size: 14px;
}

.inner .RememberMe input,
.inner .RememberMe label {
  float: right;
  color: #b3b3b3;
  font-size: 12px;
  margin-bottom: 15px;
  margin-top: -8px;
}

.inner button {
  font-family: "Roboto", sans-serif;
  text-transform: uppercase;
  outline: 0;
  background: #4CAF50;
  width: 100%;
  border: 0;
  padding: 15px;
  color: #FFFFFF;
  font-size: 14px;
  -webkit-transition: all 0.3 ease;
  transition: all 0.3 ease;
  cursor: pointer;
}

.inner button:hover,
.inner button:active,
.inner button:focus {
  background: #43A047;
}

.inner .message {
  margin: 15px 0 0;
  color: #b3b3b3;
  font-size: 12px;
}

.inner .message a {
  color: #4CAF50;
  text-decoration: none;
}

.inner .checkbox {
  margin: 15px 0 0;
  color: #b3b3b3;
  font-size: 15px;
}

.inner .register-form {
  display: none;
}

body {
  /* fallback for old browsers */
  font-family: "Roboto", sans-serif;
  -webkit-font-smoothing: antialiased;
}
<!DOCTYPE html>
<html>

<head>
    <title>Login Form</title>
    <link rel="stylesheet" href="css/style.css">
</head>

<body>
    <div class="outer">
        <div class="middle">
            <div class="inner">

                <form class="register-form">
                    <input type="text" placeholder="Username" id="register_username" />
                    <input type="password" placeholder="Password" id="register_password" />
                    <input type="text" placeholder="Email address" id="register_email" />
                    <button id="register_button">create</button>
                    <p class="message">Already registered? <a href="#">Sign In</a></p>
                </form>

                <form class="login-form">
                    <input type="text" placeholder="Username" id="login_username" />
                    <input type="password" placeholder="Password" id="login_password" />
                    <div class="RememberMe">
                        <input type="checkbox" id="remember_me">
                        <label>Remember me</label>
                    </div>
                    <button id="login_button">login</button>
                    <p class="message">Not registered? <a href="#">Create an account</a></p>
                </form>

            </div>
        </div>
    </div>

    <script src='js/jquery-3.1.1.min.js'></script>
    <script src="js/index.js"></script>

</body>

</html>

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

Blog HTML Editing Tool

Apologies for the simple question. I'm struggling to find the right plugin for blog writing that allows users to edit fonts and add images. I also need the ability to submit the generated HTML code into MySQL. Can anyone offer assistance with this pro ...

What is the user-agent string for the Safari home screen?

Is there a unique user-agent string specifically for Safari on IOS that identifies it as being in "Home screen" or "app mode"? I've observed a bug on IOS8 where the browser window appears incorrectly, with the time and battery information overlapping ...

Using HTML, jQuery, and JSON with an AJAX call to populate two web tables stacked on top of each other

I am encountering an issue with populating two tables using two searches based on user input in mySQL-JSON-AJAX. When the user enters a search term and clicks the corresponding button, data should populate the respective table. The problem arises when clic ...

Error: Unexpected syntax error occurred due to the use of '===' operator

Click here for image descriptionError: There is a syntax error in line 7 of the file add.php Code: <?php require_once('db.php'); if ( !empty($_POST['name']) &&!empty($_POST['alias']) &&!empty($_POST[&apo ...

Creating a responsive grid division

.subcategory-main-wrapper { display: grid; grid-template-columns: repeat(4, max-content); position: absolute; width: 100%; column-gap: 4%; justify-content: center; height: 360px; @media @tabletScreens { height: 280px; } @media @ ...

Is it possible to represent a recursive variable using CSS?

When it comes to the html structure: <body> <div> <div> <div> ... </div> </div> </div> </body> Is there a method to create recursive variables that utilize their parent's value: body ...

What is the best way to implement a required input field in Vue.js?

I need some assistance with my chat functionality. I want to prevent users from sending empty messages, so I want to make the input field required. Can you please help me with this? I have already tried adding "required='required'" to the input ...

Effortlessly lower several elements simultaneously with SlideDown

My form div contains multiple inner divs: <div class="form" style="display:none"> For example: <div class="row"> <?php echo $form->labelEx($model,'comment'); ?> <?php echo $form->textField($model,'commen ...

Deactivate the Submit button when the database field has been populated

My form includes a submit button. The Submit button should be disabled if the "price" for a specific product is already filled: PHP Code <?php $host="localhost"; $username="root"; $password=""; $db_name="ge"; $con=mysqli_connect("$h ...

Update a particular class following an AJAX POST request in JavaScript

After conducting extensive research, I have come here seeking your assistance with a particular issue: I am using a comment system with multiple forms on the same page (utilizing FOSCommentBundle in Symfony). My goal is to be able to post comments via Aja ...

Adjust the position of a child element to be just outside the boundaries of its parent element using CSS

I am facing an issue with 2 nested divs in my HTML code. The design requires the inner div to appear "on top of" the outer div, like this: (source: examplewebsite.com) Although I have applied CSS to both elements, including a negative top margin on t ...

Clicking to enter fullscreen mode on a website will result in the Fullscreen API automatically closing

For my current project, I am creating an offline website and would like it to display in full screen when opened. I have been using the Fullscreen API, but it exits fullscreen mode when a user navigates to another page. After researching the issue, it seem ...

Creating AngularJS variables with dependencies on integer values

Hello, I am a brand new developer and I am currently working on creating an expenses calculator. The goal is to have the sum of inputted integers from a table, each with a default value, become the integer value of another variable. However, I seem to be m ...

Guide to implementing a slider in HTML to adjust the size of my canvas brush

Hey there, I'm looking to implement a slider functionality under my canvas that would allow users to change the brush size. Unfortunately, all my attempts so far have been unsuccessful. Can anyone lend a hand? Much appreciated! <canvas i ...

Utilizing jQuery Methods within Node.js

Recently delved into the world of node.js and created multiple pages (such as login, signup, blog, etc). If I desire an effect in which: 1. Hovering over the "News" button triggers a slider to appear downwards, To make adjustments to an image within ...

Adaptive design that uses identical HTML for both desktop and mobile versions

I'm currently working on a project using Bootstrap 4 to create a responsive design, but I'm facing some challenges. I managed to achieve the desired layout on CodePen, but I'm struggling to find a way to avoid repeating the code for both de ...

Python Ordering menu items for the Pelican restaurant

In response to jcollado's advice on this thread, I have set up my menu as per his instructions. However, I am facing difficulty adding the active CSS to the active item. DISPLAY_PAGES_ON_MENU = False DISPLAY_CATEGORIES_ON_MENU = False MENUITEMS = ( ( ...

Seeking a material design template for mandatory form patterns

I'm struggling with getting my required field patterns to work using regular expressions. Additionally, I'd like to center my 'onboard' button on the page. You can find my code at this StackBlitz link: https://stackblitz.com/edit/angula ...

Ways to ensure that an svg image is perfectly sized to its parent container

I'm exploring the svg <image> tag for the first time. I've decided to use this tag to apply a gray filter on an image (thanks, IE). Check out my HTML code below: <div class="container"> <div class="item"> <svg version ...

Steps to launching a URL in a new window on Internet Explorer

I want it so that when button1 is clicked, the URL opens in a new window using Internet Explorer. ...