Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Align centre

Featured Replies

hello guys,


I am creating my first website, and i did all the borders, using divs.

i looks like this Yso3pQ2.png.


how do i align at the centre?

Put your entire layout inside a <div></div> (that's within the body tags, of course) with the following CSS:

div{
    margin: auto;
}

This'll align it down the middle.

  • Author

can you post up the html code

sure

 

html code

<Doctype HTML>
<html>
<head>
		<link type="text/css" rel="stylesheet" href="first-project.css"/>
    <title> E.luxman</title>
       <body>
                <script type="text/javascript">
                    
                    Document.write("hey now brown cow");
                    
           
                </script>
           
           <div align="center"></div>
           <div id="logo"></div>
           <div id="menue"></div>
           <div id="main"></div>
           <div id="footer"></div>

    </body>

</html>

css

body{
    height:850px;
    width:1000px;    
    background-image:url(images/provaimg_10.png)
}

#logo{
    margin-left:50px;
    margin-right:50px;
    margin-top:25px;
    border:2px solid;
    width:700px;
    height:100px;
    border-radius:10px;
    position:absolute;
    align-self:center;

}

#menue{
    margin-left:50px;
    margin-right:50px;
    margin-top:145px;
    border:2px solid;
    height:285px;
    width:148px;
    border-radius:10px;
    position:absolute;
}

#main{
    margin-left:220px;
    margin-right:50px;
    margin-top:145px;
    border:2px solid;
    height:551px;
    width:530px;
    position:absolute;
    border-radius:10px;
}

#footer{
    margin-left:50px;
    margin-right:50px;
    margin-top:745px;
    margin-bottom:50px;
    border:2px solid;
    position:absolute;
    border-radius:10px;
    height:69px;
    width:699px;
    display:center;
}

  • Author

have a look at what i done here and implement it into your code

 

http://jsfiddle.net/QxcbD/

Oh thanks a lot, could you please explain why you used the container div? and why did you set to class and not ID?

I would use a container as it explains itself realy it contains all the divs you are using so if you want to position them all easily you just position the container. As for IDs you can only use them once in a page where as a class you can use multiple times, you can also stack classes like so

 

 

.container {
   margin:auto !important;
}
.full-width {
   width: 100%;
}
.half-width {
   width: 50%;
}
.blue {
   color:blue;
}

 
<div class="container full-width blue">blue full width</div>
<div class="container full-width">full width</div>

<div class="container half-width">half width</div>
<div class="container half-width blue">blue half width</div>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.