Having difficulty aligning the content to the middle

My goal is to have my calculator centered on the page, but it keeps aligning top left after adding a footer. Any solutions?

I'm struggling to figure out how to center my calculator properly with the added footer. Can anyone provide some guidance?

body {
  display: flex;
  flex-direction: row;
  align-content: center;
  justify-content: center;
  margin: 0;
  font-size: 18px;
  background-image: linear-gradient(to right, lightgray, white);
}

.wrapper {
  display: flex;
  align-content: center;
  justify-content: center;
  flex-direction: column;
  width: 100%;
  height: 100vh;
}

.container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 275px;
  /*  height: 415px; */
  border: 1px solid rgba(0, 0, 0, 0.5);
  box-shadow: 0px 0px 5px 5px rgba(0, 0, 0, 0.5);
}

.sub-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* height: 100%;  */
  /*   width: 800%; */
}

.display {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  /* border: 1px solid white; */
  width: 100%;
  height: 65px;
  /*   margin: 0 0 5% 0;  */
  color: white;
  background-color: black;
}

#result-display {
  margin-right: 8%;
}

.button-grid {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  justify-content: space-between;
}

.item {
  width: 68px;
  height: 65px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  color: black;
  font-size: 18px;
  background-color: rgba(209, 190, 200, 0.17);
}

.item:hover,
[data-type="nonNumber"]:hover {
  background-color: rgba(252, 252, 252, 0.2);
}

#Enter {
  width: 206px;
}

#Enter {
  background-color: orange;
}

#Enter:hover {
  background-color: rgb(255, 165, 0, 0.6);
}

#AC {
  background-color: #fcfcfc;
}

[data-type="nonNumber"] {
  background-color: lightgray;
}

footer {
  background: rgba(128, 128, 128, 0.3);
  padding: 8px 0;
  display: flex;
  justify-content: center;
  margin-top: auto;
}
    <div class="wrapper">
      <div class="container">
        <div class="sub-container">
          <div class="display">
            <p id="result-display">

            </p>
          </div>
          <div class="button-grid">
            <div>
              <button class="item" id="7" data-type="number">
                7
              </button>
            </div>
            <div>
              <button class="item" id="8" data-type="number">
                8
              </button>
            </div>
            <div>
              <button class="item" id="9" data-type="number">
                9
              </button>
            </div>
            <div>
              <button class="item" id="divide" data-type="nonNumberFunction">
                &divide;
              </button>
            </div>
            <div>
              <button class="item" id="4" data-type="number">
                4
              </button>
            </div>
            <div>
              <button class="item" id="5" data-type="number">
                5
              </button>
            </div>
            <div>
              <button class="item" id="6" data-type="number">
                6
              </button>
            </div>
            <div>
              <button class="item" id="multiply" data-type="nonNumberFunction">
                &times;
              </button>
            </div>
            <div>
              <button class="item" id="1" data-type="number">
                1
              </button>
            </div>
            <div>
              <button class="item" id="2" data-type="number">
                2
              </button>
            </div>
            <div>
              <button class="item" id="3" data-type="number">
                3
              </button>
            </div>
            <div>
              <button class="item" id="subtract" data-type="nonNumberFunction">
                &minus;
              </button>
            </div>
            <div>
              <button class="item" id="0" data-type="number">
                0
              </button>
            </div>
            <div>
              <button class="item" id="decimal" data-type="nonNumber">
                .
              </button>
            </div>
            <div>
              <button class="item" id="AC" data-type="nonNumber">
                AC
              </button>
            </div>
            <div>
              <button class="item" id="add" data-type="nonNumberFunction">
                &plus;
              </button>
            </div>
            <div>
              <button class="item" id="Enter" data-type="nonNumber">
                &equals;
              </button>
            </div>
            <div>
              <button class="item" id="Backspace" data-type="nonNumber">
                DEL
              </button>
            </div>
          </div>
        </div>
      </div>
      <div>
      </div>
      <footer><span>Built by <a href="https://www.twitter.com/mrsamlj" target="_blank">@MrSamLJ</a></span></footer>
    </div>

https://jsfiddle.net/s9ebLdvt/13/

Answer №1

To keep it simple, just use the margin: auto property for the .container.

Alternatively, you can set the <body> to its default display and make sure the wrapper is set to inline-flex:

body {
  text-align: center;
  margin: 0;
  font-size: 18px;
  background-image: linear-gradient(to right, lightgray, white);
}

.wrapper {
  display: inline-flex;
  align-content: center;
  justify-content: center;
  flex-direction: column;
  height: 100vh;
}
/* Rest of the CSS code... */
<div class="wrapper">
      <div class="container">
        <div class="sub-container">
          <div class="display">
            <p id="result-display">

            </p>
          </div>
          <div class="button-grid">
           /* Button grid HTML elements... */
          </div>
        </div>
      </div>
      <div>
      </div>
      <footer><span>Made with &lt;3 by <a href="https://www.twitter.com/mrsamlj" target="_blank">@MrSamLJ</a></span></footer>
    </div>

Preview

https://i.sstatic.net/BwhBS.png

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

Adjusting footer position and spacing between header elements using CSS

Is there a way to ensure my footer always stays at the bottom, even when my content is limited? And how can I reduce the space between two heading tags? Check out the HTML and CSS code here: https://jsbin.com/guwugaloci/edit?html,css,output View t ...

Is there a way to automatically send users to a different PHP file once they click "submit"?

I need to redirect to a different php file named index2.php. The username and password values are already set as follows: Username=sid, Password=yeaoklogin. When the user clicks on the Login button, they should be redirected to a page called index2.php. ...

My jquery filter is not functioning properly

I need help making the active class work on each category when clicked, shifting to the next one. I've tried implementing it but no luck so far. $(document).ready(function() { $('.list-inline-item').click(function() { const value = ...

"Trouble arose when I tried to incorporate additional functions into my JavaScript code; my prompt feature is not

As a beginner in HTML and JS coding, I am working on creating a page that prompts user input for a name and then executes animations using radio buttons. However, after adding functions for radio button changes, my prompt is no longer functioning properly. ...

SSL page on Wordpress struggles to load CSS files

My current website is on WordPress: The issue I am facing is on this particular page: , where the CSS is not loading correctly. This specific page uses SSL connection, and when checking through Firebug, I noticed that no CSS files are being sent. What co ...

CSS Hover Effects on Navigation Bar Not Displaying as Expected

I was aiming to make one of my Navbar tabs stand out by having a different appearance compared to the others. However, there seems to be an issue with the text color for this particular tab in the hover state - it works inconsistently across different brow ...

Unusual occurrence: unexpected positioning issue with iOS and Chrome (Windows)

My website looks perfect on Firefox, but unfortunately, it's not displaying correctly on Safari (iOS) and some Chrome devices. The Menu-Bar, which should be position fixed, is not showing properly. I'm not sure what the issue is. Screenshots: ...

Bootstrap 4.0 fixed navbar - Resolved alignment problem

I am working on dividing my navbar into two equal parts. I want the right side to contain my menu and the left side to have my icon and search bar. When the search bar is clicked, it should extend to fill the rest of the half in the left part. I have manag ...

Activate Popover with Hover and simply click anywhere to dismiss

Currently utilizing Bootstrap 4 and intrigued by the popover feature that activates on hover and closes when clicked anywhere. I'm also interested in making links functional within the popover. Any suggestions or tips on how to achieve this? $(doc ...

One effective method for populating my form following the retrieval of JSON data

Currently, I am working on a VueJs project where I am fetching data from a Mysql database using Axios. My next step is to implement an edit option for user profiles. I am wondering what the most efficient method is for populating the form with the fetche ...

There seems to be a problem with Bootstrap 4 Nav-tabs when forms are added inside them, causing

Previously, when the content consisted only of text and you clicked on the nav-tabs link, it displayed the necessary information. However, after adding these forms, the functionality stopped working. It seems like the issue lies with form integrations. Her ...

Creating a Form with Dynamic HTML when Button is Clicked

I have been working on enhancing the functionality of my website app located at , but unfortunately, I have not been successful so far. My goal is to introduce a vendor information form with just one click of a button and then enable users to add products ...

I require a breakdown of the JavaScript code, please

Are you struggling with a code snippet that involves CSS, JavaScript, and HTML? Let's take a look at the complete code: <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="http://snipplicious.com/css/bo ...

Achieve a centered content with a stretched background using Bootstrap 5

Having some trouble with aligning items in a div using align-items-stretch to stretch the background and align-items-center to vertically center the content. It seems that the alignment issue occurs when there's a very long title present. https://i.s ...

Issues with navigating sliders

I've encountered a problem with my slider arrows while following a YouTube tutorial. They are supposed to appear next to the picture and testimonial, but instead, they are showing up at the top. This issue wasn't present initially, but after enco ...

Unusual blue outline spotted on Firefox

Could you please review the following code snippet: http://www.jsfiddle.net/tt13/5CxPr/21 In Firefox, there is a strange blue border that appears when selecting multiple rows by pressing the ctrl button. However, this issue does not occur in Chrome. Thi ...

The CSS hamburger menu halves in size when being closed

I have successfully created a CSS/JS hamburger menu with a transforming icon upon clicking. However, I encountered a bug where, upon clicking the 'close' button on the hamburger, the navigation menu cuts behind the header, resulting in a messy ap ...

Understanding the contrast between viewport and responsive web design is essential in developing a

Can you explain the distinction between using <meta name='viewport'> and implementing Responsive web design with CSS Media Screen? It appears that these two methods serve similar purposes. Even without including <meta name='viewpo ...

Page is missing images and product details being displayed

I have been diligently working on creating a product page for my wife’s jewelry site. Following a PHP tutorial, I implemented the code and attempted to run the page. Unfortunately, I encountered an issue where none of the images, including the header and ...

Hide the Modal Content using JavaScript initially, and only reveal it once the Onclick Button is activated. Upon clicking the button, the Modal should then be displayed to

While trying to complete this assignment, I initially attempted to search for JavaScript code that would work. Unfortunately, my first submission resulted in messing up the bootstrap code provided by the professors. They specifically requested us to use Ja ...