Center box on webpage

center div horizontally and vertically
how to center a webpage in html
center image in div vertically and horizontally
how to center a div
center webpage on screen
html5 center div
center div vertically
div float center

I wrote a tiny little website which can be found here. Everything is working as expected, except for two issues:

  • The box should sit in the center of the page ideally (with a bit of padding between it and the navbar, and some padding between it and the bottom)
  • There should be no whitespace at the bottom (the particles.js background should span the entire webpage)

Unfortunately, I'm not a very experienced web developer, so the solution to this escapes me. Here is the relevant HTML:

<div class="stage">
  <div id="particles-js"></div>
  <div class="container">
    <div class="box">
      <span>Hello, world!</span>
    </div>
  </div>
</div>

and the CSS:

body, html {
    height:100%;
    width: 100%;
}

.stage {
    position: relative;
    height: 100%;
    width: 100%;
    background-color: black;
}

#particles-js {
    position: sticky;
    height: 100%;
}

.container {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    align-container: center;
    justify-content: center;
    max-width: 60%;
    max-height: 60%;
}

.box {
    align-self: center;
    background-color: black;
    color: white;
    position: absolute;
    left: 20%;
    right: 20%;
    bottom: 0;
    border: solid green;
    text-align: center;
}

Thank you!

since your navbar is fixed it is taken from the document flow, therefore top:0 will stretch the box to the, so it won't puch the box, here we either play a guessing game or involve JS, We gonna take the navbar height and use it to push box respectively, then add as much as you need for the the space you want from the top and bottom.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body,
html {
  height: 100%;
  width: 100%;
}

.stage {
  position: relative;
  height: 100%;
  width: 100%;
  background-color: black;
}

#particles-js {
  position: sticky;
  height: 100%;
}

.container {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  max-width: 60%;
  max-height: 60%;
}

.box {
  align-self: center;
  background-color: black;
  color: white;
  position: absolute;
  left: 20%;
  right: 20%;
  bottom: 10px;
  /* the extra space you wanted */
  top: 61px;
  /* the height being 51px + 10px from a the extra space you wanted*/
  border: solid green;
  text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Spooky Internet</a>
    </div>
    <div id="navbar" class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Blog</a></li>
      </ul>
    </div>
  </div>
</nav>
<div class="stage">
  <div id="particles-js"></div>
  <div class="container">
    <div class="box">
      <span>Hello, world!</span>
    </div>
  </div>
</div>

How To Center a Website, Use a container element and set a specific max-width . A common width many websites use is 960px. To actually center the page, add margin: auto . The following  You Can Create Your Own Professional Webpage with the Wix Website Builder. Gain Access to the Advanced Tools that You Need and Get Customer Support as You Go.

I edited the below 2 css code.Hope this is what you need.

.stage {
position: relative;
background-color: black;
}

.box {
align-self: center;
background-color: black;
color: white;
position: absolute;
left: 20%;
right: 20%;
top:50%;
border: solid green;
text-align: center; 
}

Centering a Website, all websites HTML here --> </div> </body> #page-wrap body { text-align: center​; } #page-wrap { text-align: left; width: 800px; margin: 0 auto; }. As IE won't  How To Center Your Website. Use a container element and set a specific max-width. A common width many websites use is 960px. To actually center the page, add margin: auto. The following example will center the website on screens that are wider than 500px. On screens that are less than 500px wide, it will span the whole of the page:

CSS: centering things, A common task for CSS is to center text or images. In fact DIV.container { min-​height: 10em; display: table-cell; vertical-align: middle } <DIV  I wrote a tiny little website which can be found here.Everything is working as expected, except for two issues: The box should sit in the center of the page ideally (with a bit of padding between it and the navbar, and some padding between it and the bottom)

div center in webpage | css div box conainer, Form - Cannot align a form to the center of webpage The div moved the label only and not the text fields nor the submit button? 1 Like. How to Center Web Page Content Using CSS - Centering Web Page Content Open Notepad or a comparable text editing application. Create the basic HTML skeleton of the website. Within the <head> </head> tags add the following style definition. Inside the <body></body> tags add the following div tags.

Form - Cannot align a form to the center of webpage, The box-align CSS property specifies how an element aligns its contents across its layout in a perpendicular direction. Keyword values */ box-align: start; box-​align: center; box-align: end; Not for use in new websites. Don't use the HTML element <center> to center images and text; it has been deprecated, and modern web browsers no longer support it. This, in large part, is a response to HTML5's clear separation of structure and style: HTML creates structure, and CSS dictates style.

box-align, Create an initial "wrap" DIV that will be the website's wrapper. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. How to Centre ("Center") Text on Your Web Page with CSS by Christopher Heng, thesitewizard.com I recently received an email from a visitor asking me how she could centre ("center" in US English) some text in the middle of a box.

Comments
  • Sorry I mistakenly pressed enter before completing my code. So top: 50% in ".box" places the box in center and removing height and width from ".stage" removes the white space from the bottom.