Issue with wrapper not aligning correctly at the top of the screen

I keep noticing a gap between my wrapper and the top of the page. Despite trying multiple solutions, none seem to work for me. The background image covers the entire background and is aligned at the top perfectly, but the wrapper with its own background appears to have an unwanted margin.

body {
  height: 100vh;
  background: url("https://i.imgur.com/HgflTDf.jpg") 50% fixed;
  background-size: cover;
}

.wrap {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  min-height: 100%;
  padding: 20px;
  background: rgba(17, 71, 114, 0.85);
  top: 0;
}

.login {
  border-radius: 2px 2px 5px 5px;
  padding: 10px 20px 20px 20px;
  width: 90%;
  max-width: 320px;
  background: #ffffff;
  position: relative;
  padding-bottom: 80px;
}

input {
  display: block;
  padding: 15px 10px;
  margin-bottom: 10px;
  width: 100%;
  border: 1px solid #ddd;
  transition: border-width 0.2s ease;
  border-radius: 2px;
}

input:focus {
  outline: none;
  color: #444;
  border-color: 2196F3;
  border-left-width: 35px;
}

.fa {
  color: #fff;
  font-size: 1em;
  position: absolute;
  margin-top: -47px;
  opacity: 0;
  left: 0;
  transition: all 0.1s ease-in;
}

.fa:focus {
  opacity: 1;
  left: 30px;
  transition: all 0.25s ease-out;
}

.tittel {
  color: #444;
  font-size: 1.2em;
  font-weight: bold;
  margin: 10px 0 30px 0;
  border-bottom: 1px solid #eee;
  padding-bottom: 20px;
}

.sub {
  width: 100%;
  height: 100%;
  padding: 10px 10px;
  background: #2196F3;
  color: #444;
  display: block;
  border: none;
  margin-top: 20px;
  margin-bottom: 0px;
  position: absolute;
  left: 0;
  bottom: 0;
  max-height: 60px;
  border: 0px solid rgba(0, 0, 0, 0.1);
  border-radius: 0 0 2px 2px;
  transform: rotateZ(0deg);
  transition: all 0.1s ease-out;
  border-bottom-width: 7px;
}

footer {
  display: block;
  padding-top: 50px;
  text-align: center;
  color: #fff;
  font-weight: normal;
  text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.2);
  font-size: 0.8em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">

<div class="wrap">
  <form action="" method="post" class="login needs-validation" novalidate>
    <h4 class="tittel">Login</h4>
    <input type="text" name="username" value="" placeholder="Username" required autofocus/>
    <i class="fa fa-user"></i>
    <input type="password" name="password" placeholder="Password" required>
    <i class="fa fa-key"></i>
    <input type="submit" class="sub" value="Login">
  </form>
  <footer>Company name</footer>
</div>

UPDATE: The wrapper appears to be situated around 30-40px below the top. This specific length allows for scrolling down the page. I've attempted various adjustments such as removing padding from the .wrap class, disabling the body background, and experimenting in Chrome's site inspector by toggling CSS properties on and off. Unfortunately, none of these actions have made a noticeable difference.

Answer №1

Typically, most popular web browsers have a default margin of 8px on all sides. This measurement is specified in pixels within the user-agent-stylesheet that your specific browser utilizes.

While some browsers offer the option to customize and utilize your own user-agent-stylesheet, it is generally recommended not to alter this setting when developing a website. Making changes could result in inconsistencies for users who do not have a customized stylesheet, leading to varying display appearances.

If you do wish to adjust the default margin, a simple method would be:

body {
  margin: 0;
  padding: 0;
  ...
}

For larger projects seeking comprehensive standardization across browsers, consider using normalize.css. This resource resets numerous default values to promote consistency.

Special thanks to Jon Egeland

Answer №2

By removing the 20px padding in your wrap class, you may be able to resolve the issue at hand - https://i.sstatic.net/jQjUG.png

I trust this is the solution you were seeking!

Answer №3

For my needs, this solution is perfect without the use of any padding:

.content {
    max-width: 1000px;
    display: flex;
    flex-direction: column-reverse;
    justify-content: center;
    overflow: hidden;
    margin: 0 auto;
}

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

Struggling to center a div within another div using margin auto

Hey there, I'm looking for some help with my code. Here's what I have: .center{ width: 100%; margin: 0 auto; border: 1px solid red; } .nav{ background: #606060; width: 90%; } HTML <!DOCTYPE html> <html> < ...

How can I extract and display chosen values from multiple dropdown menus in designated text boxes based on their unique identifiers?

A website for evaluating car values is in the works, using a combination of PHP, MYSQL, JQUERY, and JavaScript. The database includes 3 tables: Table "car_make": id make 1 BMW Table "model": model_id model_name make_id 1 M3 1 Table "ca ...

Ensure that the floating div is positioned along the right side and adjusts to accommodate the

I've been searching for a solution to this issue, but it seems like I might not be articulating it correctly because I haven't been able to find an answer yet. On my page, there is a 'quick links' button that is supposed to stay fixed ...

Setting Image Height with CSS

I have a div with a height of 105px. The image inside the div is 359px tall. How can I adjust the div's size to prevent cutting off the image and ensure it displays in full height? Thank you for your help! ...

Tab panels are shown by Bootstrap 5 tabs

I am using Bootstrap 5 to design a layout that changes based on the width of the screen. When the screen width is greater than or equal to 992 pixels, a table is displayed in the sidebar and some text is shown in the main content area. However, if the scre ...

What is the best way to upload multiple files in Laravel using Guzzle?

Currently, I am facing an issue while trying to upload files to an external server using JWT for authentication. Here is a snippet of my form: <form action="{{ route('operations.photos-for-families.upload', [$operation, $current->index ...

When the width of the element is set to 100vw, it disrupts the

I'm attempting to expand a sticky element to fit the size of the screen. Here is the HTML code I am using: .large { height: 200vw; width: 200vw; } .header { left: 0; top: 0; color:white; position: sticky; width: 100px; height: 10 ...

Using data binding in VueJS to construct a dynamic URL

Exploring VueJS for the first time and it's been a great experience so far. However, I'm facing a couple of challenges with data binding. The requirement is for the customer to input an image URL, and no image should be displayed until a valid ...

Ways to insert a hyperlink within a div element

Consider the following HTML structure: <article id="1919"> <div class="entry-content clearfix"> <div></div> <div></div> </div> </article> &l ...

D3 not distinguishing between bars with identical data even when a key function is implemented

When attempting to create a Bar chart with mouseover and mouseout events on the bars using scaleBand(), I encountered an issue. After reviewing the solution here, which explains how ordinal scale treats repeated values as the same, I added a key to the dat ...

Arrange images in a stack format, scaling them based on their percentage

I'm curious about how to overlap images that are sized using a percentage value (in this case, 100%). If the images had a fixed width/height in pixels, I could easily adjust their positions with position:relative to stack them on top of each other. Ho ...

Conceal an absolutely positioned element outside its relatively positioned parent

I have a relative position parent element, <div style="position:relative" id="a"> and within that div, I'm creating some absolute positioned elements using jQuery, <div style="position:absolute;right:0" id="b"> These elements are anima ...

Everything seems to be functioning properly on the local server, but once the media files or players (mp3 and mp4) are uploaded, the background fails to work entirely

function playMusic() { var songs = [ "pump.mp3", "ybwm.mp3", "bb.mp3", ]; var randomIndex = Math.floor(Math.random() * songs.length); var selectedSong = songs[randomIndex]; var audio = new Audio(selecte ...

Switching the cursor to the following input after a paste event using JQuery

I am currently working on an HTML form that consists of multiple input boxes. I'm looking to focus on the next input box after pasting content into one of them. Below is the code snippet I have been using: $("input").bind('paste', function( ...

Solving the problem of Hover Effects in CSS

I am struggling to get the nav-link to be blue in color with a dark-blue hover effect. I managed to set the color correctly, but for some reason, the hover effect is not working. Can anyone help me figure out what the issue might be? Additionally, does any ...

What causes jQuery's .width() method to switch from returning the CSS-set percentage to the pixel width after a window resize?

After exhaustively console logging my code, I have finally identified the issue: I am attempting to determine the pixel width of some nested divs, and everywhere I look suggests that jQuery's .width() method should solve the problem. The complication ...

The style from 'http://localhost:2000/cssFile/style.css' was rejected because its MIME type was 'text/html'

Currently, I am attempting to include my style.css file in the home.ejs file being rendered by express.js. However, I keep encountering the following error: Refused to apply style from 'http://localhost:2000/cssFile/style.css' because its MIME t ...

Using JQuery AJAX to transfer unstructured list elements to an ASP.net MVC controller action

Need help passing list item values to controller action method as model, but the model is returning null. Below is the JQuery code I have attempted: Here is my HTML: <ul class="to_do" id="Emaillist"> <li class="alert" value="2">example list ...

Choosing an option from a PHP MySQL table based on a JavaScript value

I am attempting to create a select box that displays a value based on whether the database has a "yes" or "no" in the specified column. Despite my efforts, I am unable to identify any syntax errors causing this code snippet to not function properly. JavaSc ...

The content of the served HTML Table remains static and requires a server restart for any updates to

Having been encountering this issue for quite some time, I have searched extensively for a solution but to no avail. Therefore, I am taking matters into my own hands and posing the question myself. The dilemma is as follows: https://i.stack.imgur.com/UZrQ ...