Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Need a simple *everything centered* html template

Need a simple *everything centered* html template

Scheduled Pinned Locked Moved Web Development
htmlmobileadobequestion
8 Posts 4 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14987492
    wrote on last edited by
    #1

    Hello again... [Thought I could do this on my own in Adobe Dreamweaver, but I guess not]. I need a basic (responsive) html template whereby everything on the page is centered vertically in divs...both image & text content. (I believe I need what is known as a 'wrapper'...that can be set to a certain width...& then all other content would be centered in that wrapper) If someone can just get me started, w/ just a few centered divs in a wrapper for placement of images & text, I can learn from that basic code & just add content as I go (& will be very appreciative of any effort, from anyone here). thanx, mwForman

    Richard DeemingR J 2 Replies Last reply
    0
    • M Member_14987492

      Hello again... [Thought I could do this on my own in Adobe Dreamweaver, but I guess not]. I need a basic (responsive) html template whereby everything on the page is centered vertically in divs...both image & text content. (I believe I need what is known as a 'wrapper'...that can be set to a certain width...& then all other content would be centered in that wrapper) If someone can just get me started, w/ just a few centered divs in a wrapper for placement of images & text, I can learn from that basic code & just add content as I go (& will be very appreciative of any effort, from anyone here). thanx, mwForman

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Centering in CSS: A Complete Guide | CSS-Tricks - CSS-Tricks[^] For example:

      html, body {
          display: grid;
          height: 100%;
      }
      body > div {
          margin: auto;
      }
      
      
      
      
          Everything in this element is centered, both horizontally and vertically.
      

      Demo[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Centering in CSS: A Complete Guide | CSS-Tricks - CSS-Tricks[^] For example:

        html, body {
            display: grid;
            height: 100%;
        }
        body > div {
            margin: auto;
        }
        
        
        
        
            Everything in this element is centered, both horizontally and vertically.
        

        Demo[^]


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        Member_14987492
        wrote on last edited by
        #3

        Richard... Thanx. I don't need horizontal centering, tho...only vertical (i.e., all content would be centered on the page vertically, but would be positioned at the top of each div). What would that page code look like? Thanx again, MF

        Richard DeemingR J 2 Replies Last reply
        0
        • M Member_14987492

          Richard... Thanx. I don't need horizontal centering, tho...only vertical (i.e., all content would be centered on the page vertically, but would be positioned at the top of each div). What would that page code look like? Thanx again, MF

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Member 14987492 wrote:

          I don't need horizontal centering ... all content ... would be positioned at the top of each div

          Those two statements don't match. If you want content positioned at the top, then it's the vertical centering that you don't want. If you don't want the horizontal centering, then you want the content positioned on the left-hand side. So which is it?


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          M 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Member 14987492 wrote:

            I don't need horizontal centering ... all content ... would be positioned at the top of each div

            Those two statements don't match. If you want content positioned at the top, then it's the vertical centering that you don't want. If you don't want the horizontal centering, then you want the content positioned on the left-hand side. So which is it?


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            M Offline
            M Offline
            Member_14987492
            wrote on last edited by
            #5

            I was pretty clear (I thought). You gave me a code page whereby content was centered on the page but then also centered vertically in the container. I want all the containers (divs) to be centered, but I want the content inside those divs at the *top* of the centered div, not in the *middle* of it. thanx

            Richard DeemingR 1 Reply Last reply
            0
            • M Member_14987492

              I was pretty clear (I thought). You gave me a code page whereby content was centered on the page but then also centered vertically in the container. I want all the containers (divs) to be centered, but I want the content inside those divs at the *top* of the centered div, not in the *middle* of it. thanx

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              But that's exactly what I gave you. :laugh: The content isn't vertically centered within the <div>; it's just that the <div> is only as tall as the content. If you make it taller, the content will still be at the top of the <div>.

              body > div {
              margin: auto;
              min-height: 5em;
              outline: 4px dotted green;
              }

              Demo[^]


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              1 Reply Last reply
              0
              • M Member_14987492

                Richard... Thanx. I don't need horizontal centering, tho...only vertical (i.e., all content would be centered on the page vertically, but would be positioned at the top of each div). What would that page code look like? Thanx again, MF

                J Offline
                J Offline
                Jabbar Hussain
                wrote on last edited by
                #7

                upcoming jobs for Web Developer Jobs 2022 from all Pakistani Newspapers and Newspaper Jobs. We have new December 2022 Web Developer Jobs, November 2022 and October 2022 jobs from all cities

                1 Reply Last reply
                0
                • M Member_14987492

                  Hello again... [Thought I could do this on my own in Adobe Dreamweaver, but I guess not]. I need a basic (responsive) html template whereby everything on the page is centered vertically in divs...both image & text content. (I believe I need what is known as a 'wrapper'...that can be set to a certain width...& then all other content would be centered in that wrapper) If someone can just get me started, w/ just a few centered divs in a wrapper for placement of images & text, I can learn from that basic code & just add content as I go (& will be very appreciative of any effort, from anyone here). thanx, mwForman

                  J Offline
                  J Offline
                  Jeremy Falcon
                  wrote on last edited by
                  #8

                  Just to add to Richard's great answer, you may wish to adjust your styles:

                  html,
                  body {
                  display: grid;
                  height: 100vh;
                  margin: 0;
                  padding: 0;
                  }

                  Technically, having height 100% on the body works out to be the same in that context. But it means 100% of the parent element. If there is a lot of content this may not mean center on the screen - which can be a good thing. Just depends on your use case. The 100vh always means 100% of the viewport height regardless the size of the body container. Also, the margin and padding is set to zero to avoid the doubling up of the scrollbar.

                  Jeremy Falcon

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups