Kompx.com or Compmiscellanea.com

CSS centering image

Windows : Internet Explorer 6.0+, Firefox 1.0+, Google Chrome, Opera 5.0+ [ 1 ], Safari 3.1+, SeaMonkey 1.0+ [ 2 ].

Linux : Firefox 1.0+, Google Chrome / Chromium, Opera 5.0+, SeaMonkey 1.0+ [ 3 ], NetSurf 2.6+, Hv3.

CSS horizontal centering of an image. Example:

Image

HTML / XHTML. Code:

<div class="example">

<img src="image.jpg" alt="Image" />

</div>

CSS. Code:

.example {position: relative; left: 0px; top: 0px; height: auto; width: 100%; float: left; padding: 10px; border: 1px #ccc solid; background: #fafafa;}

.example img {display: block; margin: 0 auto;}

CSS properties of a container (here it is example) may vary, image centering is achieved by styles applied to the image itself: .example img {display: block; margin: 0 auto;}.


[ 1 ]

As well as Opera 4.0+, if shorthand CSS is not used in styles. That is, if it is .example img {display: block; margin-left: auto; margin-right: auto;}.

[ 2 ]

As well as Netscape 6.01+, Mozilla 0.6+.

[ 3 ]

As well as Netscape 6.01+, Mozilla 0.6+.


Aliosque subditos et thema

 

CSS centering image

 

CSS horizontal centering of an image. Example: HTML / XHTML. Code: <div class="example"> <img src="image.jpg" alt="Image" /> </div> CSS. Code: .example {position: relative; left: 0px; top: 0px; height: auto; width: 100%; float: left; padding: 10px; border: 1px #ccc solid; background: #fafafa;} .example img {display: block; margin: 0 auto;} CSS properties of a container (here it is example) may vary, image centering is achieved by styles applied to the image itself: .example img {display: block; margin: 0 auto;}. [ 1 ] As well as Opera 4.0+, if shorthand CSS is not used in styles. That is, if it is .example img {display: block; margin-left: auto; margin-right: auto;}. [ 2 ] As well as Netscape 6.01+, Mozilla 0.6+. [ 3 ] As well as Netscape 6.01+, Mozilla 0.6+.

CSS centering <hr />

 

CSS centering <hr />, if its width is less than 100%. Horizontal centering. Example: HTML / XHTML. Code: <hr /> CSS. Code: hr {width: 50%; margin: 0 25% 0 25%;} /* Extra CSS, just styling the look: */ hr {height: 1px; float: left; border: 0px; color: #f00; background: #f00;} Note: mostly it works both with float: left and float: none. But float: left makes it for sure. [ 1 ] As well as Netscape 4.04+, Mozilla 0.6+. [ 2 ] As well as Netscape 4.04+, Mozilla 0.6+.