473,799 Members | 3,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Centering image in div

Hi,

I have a div with an image inside it. The image needs to be centered in
the div. I thought I could do this by setting the image's margin to
"auto auto", but it seems to do nothing. What am I missing here?

Thanks,
Aaron

P.S. Here are the exact styles I'm using:
..imageholder { width: 100px; height: 50px; border: 2px solid black;
float: right; margin-right: 20px;}
..cat-table td img {margin: auto auto;}

Jul 20 '05 #1
7 6812
Aaron skrev:
I have a div with an image inside it. The image needs to be centered in
the div. I thought I could do this by setting the image's margin to
"auto auto", but it seems to do nothing. What am I missing here?


Use text-align: center

auto works only on block elements, not inline elements.

And if you want to use margin: auto on block elements, you will
have to set width on it.
--
Knud
Jul 20 '05 #2
Allright, I set the style for the image to {display: block; margin:
auto;}. Shouldn't this then center it in the div it's in? It does
center it horizontally, but it remains at the top vertically. Any ideas?

Thanks,
Aaron

Knud Gert Ellentoft wrote:
Aaron skrev:

I have a div with an image inside it. The image needs to be centered in
the div. I thought I could do this by setting the image's margin to
"auto auto", but it seems to do nothing. What am I missing here?

Use text-align: center

auto works only on block elements, not inline elements.

And if you want to use margin: auto on block elements, you will
have to set width on it.


Jul 20 '05 #3
Knud Gert Ellentoft wrote:
Use text-align: center


VERTICALLY
Jul 20 '05 #4
Els
Timo Nentwig wrote:
Knud Gert Ellentoft wrote:
Use text-align: center


VERTICALLY


No need to shout. At the time Knud responded, the OP hadn't
stated yet that he meant vertically.

--
Els
http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -

Jul 20 '05 #5
Aaron wrote:
Hi,

I have a div with an image inside it. The image needs to be centered in
the div. I thought I could do this by setting the image's margin to
"auto auto", but it seems to do nothing. What am I missing here?

Have you tried "vertical-align"?

--
jmm dash list at sohnen-moe dot com
(Remove .TRSPAMTR for email)
Jul 20 '05 #6
Els wrote:
No need to shout. At the time Knud responded, the OP hadn't stated yet
that he meant vertically.


Oh, sorry, my fault. I just posted a similar question shortly ago
("centering vertically" :-)

I apologize.

Jul 20 '05 #7
Aaron wrote:
Shouldn't this then center it in the div it's in? It does center
it horizontally, but it remains at the top vertically. Any ideas?


Sure. Search the group archives. The topic of centering --
horizontally and vertically -- has been discussed *numerous* times.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1894
by: Greg Shannan | last post by:
I normally centre an image using a <p align="center"> ... </p> format, but I understand that this is "deprecated" in the latest standard in favour of styles. The problem is that I cannot find a style that will centre an image, "text-align" doesn't work and probably shouldn't. So what is the "standards-correct" method of centering an image? TIA .... Greg Shannan
18
4217
by: Heath | last post by:
Is it proper to center images in a <div> by using the text-align: center property? Or is there a better way?
2
2243
by: Ryan W Sims | last post by:
I'm having trouble with centering in IE... http://www.ryanwsims.com/koh/ The image should center over the text. It does in Firebird, but not in IE for some reason. If you look at http://www.ryanwsims.com/sd.php everything's fine (i.e. centered)
17
2516
by: Applebrownbetty | last post by:
Hi, I'd like to append/amend the following code from the Dreamweaver extension "Open Picture Window Fever" for the ability to center the PopUp window: By default, it allows the window to be offset on the left and top, but does not include a centering option. I'm thinking it would include something like (screen.width-imageWidth)/2; somewhere but not sure how do go about doing this.
6
2324
by: Jerry Camel | last post by:
I want to center an image on the screen and have text centered over the image. What's the best way to do this? I've been playing with style tags and I can get the stuff to center automatically OR have the text appear on top of the image. But in the second case, the image and text aren't centered properly. Any help is appreciated... Jerry
3
2085
by: The New iSoftware Company | last post by:
Any one know how to center a control like the image editors on the market (fireworks/photoshop/etc)? This way should support scrolling and zoom. Is there a way to draw overlays that is inverted from an image with out going pixel by pixel? LIke the title safe areas in premiere?
3
4213
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a top level <divthen I can place it with CSS attribute 'left:', but this is a fixed offset. Is it possible to have a <divcentered in the browser window? 2. Verticle centering in <div>
2
3064
by: rudicheow | last post by:
SHORT VERSION ============= I have a bunch of identical fixed-size single-celled tables that rest against each other horizontally thanks to "float:left". These tables are dynamically generated and the number of them can vary greatly. They are all contained within a parent table cell, which is centred on the page. But I am unable to find a way of centering these table cells within the parent cell.
1
2288
by: =?Utf-8?B?ZnJhbmt5?= | last post by:
Hello, I've created a table that has two rows that are span across three columns. The third row has three columns, each with an image. The last row is also span accross three columns. The span rows are centering their data. however, the row with three columns, each with images (myimages1-3) are not centering with the rest of the table. Any idea why? Thanks in advance!
4
5287
by: harryusa | last post by:
I am trying to center 2 images concentrically which are z-indexed to lay on top of each other making an image with a border from another image that has a transparent center. I need the images to be horizonally and vertically centered within a <TD> </TD> area. No matter what I do the two image just present one above the other, albeit centered, NOT on top of each other. I originally did the entire page layout in TABLES until I found out I.E. 7...
0
10470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10247
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10214
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7561
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.