NameSilo

Centering an Image Using CSS

Spacemail by SpaceshipSpacemail by Spaceship
Watch

aaronfalloon

Established Member
Impact
6
How do you center an image using CSS? Thanks in advance.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
The image needs to be in a container and then use 'text-align'.
 
0
•••
The whole thing would look like this:
Code:
text-align:center;

-Steve
 
0
•••
I read somewhere were that wasn't the recomended way, is there any other methods?
 
0
•••
Code:
margin-left: auto;
margin-right auto;

You might need to set width, but that should work.
 
0
•••
What other method with CSS is there?

You can either use css in the header of your file, an external style sheet, or, within an image tag directly in its CSS "style" attribute. I use the first two regularly, but the third is not my favorite.

-Steve
 
0
•••
Here's a one I found using The Anointed One. I haven't tested it myself, so it may or may not work.

Code:
<div style="text-align: center;">
  <div style="text-align: left; margin: 1em auto; width: 50%;">
  </div>
</div>
 
0
•••
Thanks for the help guys, only the first method seems to be working. Thanks again.
 
0
•••
you could also use

Code:
<img src="file.jpg" align="center">
 
0
•••
I don't think thats using CSS but thanks anyway.
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back