0
 _______________________________________________
|                                               |
|    Image                                      |
|                                               |
|_______________________________________________|

I want set a above rectangle is in center in a page i created that using div tag as code is

.rectangle
{
     width: 73.3%;
     margin:0 50 0 0;         
     border-top:1px solid #46464f;
     border-bottom:1px solid #282832;
     border-left:1px solid #282832;
     border-right:1px solid #282832;
     border-bottom-width:medium;
     border-left-width:medium;
     border-right-width:medium;
     border-top-width:medium;
}

I set <div class="rectangle" align="center"> this code not working

Stuart
  • 711
  • 1
  • 11
  • 35
user3256262
  • 37
  • 1
  • 3
  • 5
  • Try to get something from [**here**](http://stackoverflow.com/questions/2237636/how-to-vertically-center-image-inside-div). Might be same case. – Stuart Feb 04 '14 at 06:43
  • [**Here's**](http://stackoverflow.com/questions/4958385/center-img-inside-a-div-with-css) another topic related. – Stuart Feb 04 '14 at 06:50
  • Just to be clear for I'm already confuse on what you really want. Do you want to set your `
    ` tags be in the center of the page? Not the image or content inside the `
    `?
    – Stuart Feb 04 '14 at 07:02
  • To make things a little more readable you could try compacting your CSS by combining the borders: `.rectangle {width: 73.3%; margin 0 50px 0 0; border: medium solid #282832; border-top-color: #46464f;}`. – Paul Feb 04 '14 at 09:13

3 Answers3

1

Try this:

HTML:

<div align="center">
     <img src="http://fin6.com/wp-content/uploads/2013/07/fb81531cc9cf1512dce7f0e5f36e40fe.jpg" alt="nature"/>
</div>

CSS:

div{
     width: 300px;
     background:red;
     margin:0 auto;
}

img{
     width:150px;
     margin:0 auto;
}

Here is a DEMO

UPDATE

As per your updated question, use margin:0 auto; to center div.

.rectangle
{
     width: 73.3%;
     margin:0 auto;
     border-top:1px solid #46464f;
     border-bottom:1px solid #282832;
     border-left:1px solid #282832;
     border-right:1px solid #282832;
     border-bottom-width:medium;
     border-left-width:medium;
     border-right-width:medium;
     border-top-width:medium;
}

Updated DEMO

immayankmodi
  • 8,210
  • 9
  • 38
  • 55
1

HTML:

<div class="setCenter">Content inside a div tag</div>

CSS:

body {
    width: 100%;
    height: 100%;
    margin:auto;
}

.setCenter {
    margin:auto;
    width:90%;
    height:auto;
    border:1px solid #000;
    color:Green;
}

Here is the DEMO

Stuart
  • 711
  • 1
  • 11
  • 35
0

Try this CSS code:

.rectangle
{
    width: 73.3%; margin:0 50 0 0; 
    border-top:1px solid #46464f; 
    border-bottom:1px solid #282832; 
    border-left:1px solid #282832; 
    border-right:1px solid #282832; 
    border-bottom-width:medium; 
    border-left-width:medium; 
    border-right-width:medium; 
    border-top-width:medium;   
    text-align:center;
}
Stuart
  • 711
  • 1
  • 11
  • 35
rahul bonde
  • 17
  • 1
  • 5