473,803 Members | 3,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Centering Image in <DIV>

CJM
I've inserted a new banner in an existing page and I want the banner image
to be centered (horizontally) within its container. I'm not bothered whether
the accompanying line of text is restricted to the width of the image and
centered, or whether is simply fills the width of the container.

I've tried various things to achieve this (e.g setting margins to auto) but
I'm not having much luck.

The URL for the page is: http://www.eminox.es

And the key stylesheet is: http://www.eminox.es/_lib.css/home.css

The containing DIV has the following styling:

..hl06 {
width:510px;
height:100px;
position: absolute;
top: 66px;
left: 230px;
font-size: 75%;
padding: 4px 10px;
}

And the relevant HTML snippet is:

<div class="hl06 yellow">
<img src="/home/images/fiaa_468x60.gif " height="60" width="468" alt="FIAA
Feria de madrid 14 - 17 Octubre 2008, Pabellón 9 Puesto C27">
Visítenos en la <strong>Feria Internacional del Autobús y Autocar</strong>
en Madrid, del 14 al 17 de octubre <strong>Pabelló n 9 Puesto C27</strong>.
</div>

As you can see, the container is 51-px wide, and the image is 470px wide; I
considered manually fixing the position, but I'd prefer to master a more
fluid technique. I've stripped out the abortive crap from previous attempts,
so hopefully it's as near to a blank canvas as we will get.

Thanks in advance.

CJM
Oct 2 '08 #1
9 2516
On 2 Oct, 17:41, "CJM" <cjmn...@remove me-yahoo.co.ukwrot e:
I've tried various things to achieve this (e.g setting margins to auto) but
I'm not having much luck.
CSS has two notions of "centring"

Block-behaving elements will center if you set their own margins to
auto.

Inline-behaving elements (and this includes <imgwith default CSS
settings) will respond to setting text-align on their parent (i.e. the
<div>) instead.
Oct 2 '08 #2
CJM


"Andy Dingley" <di*****@codesm iths.comwrote in message
news:4f******** *************** ***********@m74 g2000hsh.google groups.com...
On 2 Oct, 17:41, "CJM" <cjmn...@remove me-yahoo.co.ukwrot e:
>I've tried various things to achieve this (e.g setting margins to auto)
but
I'm not having much luck.

CSS has two notions of "centring"

Block-behaving elements will center if you set their own margins to
auto.

Inline-behaving elements (and this includes <imgwith default CSS
settings) will respond to setting text-align on their parent (i.e. the
<div>) instead.
I'd considered text-align, but I don't want the text part of it centered.

So I wrapped the the whole lot in a <spanand set it's margins to auto and
it's width to 470px, but that didn't work either.

Oct 2 '08 #3
CJM wrote:
"Andy Dingley" <di*****@codesm iths.comwrote in message
news:4f******** *************** ***********@m74 g2000hsh.google groups.com...
>Block-behaving elements will center if you set their own margins to
auto.

Inline-behaving elements (and this includes <imgwith default CSS
settings) will respond to setting text-align on their parent (i.e. the
<div>) instead.

I'd considered text-align, but I don't want the text part of it centered.

So I wrapped the the whole lot in a <spanand set it's margins to auto
and it's width to 470px, but that didn't work either.
I had a similar problem which I solved by setting both "text-align: center"
on the containing box and "margin: 0 auto" on the img itself. If you don't
want the text centered, you could either set "text-align: left" for the
text (and have that rule after the div text-align rule) or have the image
and the text each in their own <divcontainer .

Have you tried "display: block" for the img to make it behave as a block?

Irina

--
"Of course it is happening inside your head, Harry, but why on earth
should that mean that it is not real?" --Albus Dumbledore
http://www.valdyas.org/foundobjects/index.cgi Latest: 01-Oct-2008
Oct 2 '08 #4
Gazing into my crystal ball I observed "CJM" <cj*******@exam ple.com>
writing in news:6k******** ****@mid.indivi dual.net:
>

"Andy Dingley" <di*****@codesm iths.comwrote in message
news:4ff25660-ff45-43d0-afa3-9c914f5192f3
@m74g2000hsh.go oglegroups.com.
..
>On 2 Oct, 17:41, "CJM" <cjmn...@remove me-yahoo.co.ukwrot e:
>>I've tried various things to achieve this (e.g setting margins to
auto) but
I'm not having much luck.

CSS has two notions of "centring"

Block-behaving elements will center if you set their own margins to
auto.

Inline-behaving elements (and this includes <imgwith default CSS
settings) will respond to setting text-align on their parent (i.e.
the <div>) instead.

I'd considered text-align, but I don't want the text part of it
centered.

So I wrapped the the whole lot in a <spanand set it's margins to
auto and it's width to 470px, but that didn't work either.

Span is inline. Use a block level element, or display an inline element
as block.

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Oct 2 '08 #5
CJM wrote:
So I wrapped the the whole lot in a <spanand set it's margins to
auto and it's width to 470px, but that didn't work either.
Because a span is in-line and not a block. In-line elements cannot be
centered. Centering something that is in-line does not make sense. If
you want an image inside a div to be centered, but not the text inside
the div, you may need to place the image and text inside thier own divs.
Oct 2 '08 #6
CJM wrote:
>

"Andy Dingley" <di*****@codesm iths.comwrote in message
news:4f******** *************** ***********@m74 g2000hsh.google groups.com...
>On 2 Oct, 17:41, "CJM" <cjmn...@remove me-yahoo.co.ukwrot e:
>>I've tried various things to achieve this (e.g setting margins to
auto) but
I'm not having much luck.

CSS has two notions of "centring"

Block-behaving elements will center if you set their own margins to
auto.

Inline-behaving elements (and this includes <imgwith default CSS
settings) will respond to setting text-align on their parent (i.e. the
<div>) instead.

I'd considered text-align, but I don't want the text part of it centered.

So I wrapped the the whole lot in a <spanand set it's margins to auto
and it's width to 470px, but that didn't work either.

<span class="banner"> <img style="display: block;margin:au to;" src="......

--
Gus
Oct 2 '08 #7

Gus Richter wrote:
CJM wrote:
>>
I'd considered text-align, but I don't want the text part of it centered.

So I wrapped the the whole lot in a <spanand set it's margins to auto
and it's width to 470px, but that didn't work either.

<span class="banner"> <img style="display: block;margin:au to;" src="......
The <spanis superfluous if its only content is the <img>.

--
Berg
Oct 2 '08 #8
On 2008-10-02, Scott Bryce <sb****@scottbr yce.comwrote:
CJM wrote:
>So I wrapped the the whole lot in a <spanand set it's margins to
auto and it's width to 470px, but that didn't work either.

Because a span is in-line and not a block. In-line elements cannot be
centered. Centering something that is in-line does not make sense.
It does make sense and you can do it-- by setting text-align on the
container.
If you want an image inside a div to be centered, but not the text
inside the div, you may need to place the image and text inside thier
own divs.
I think the easiest thing here, as has been suggested, is to get rid of
the span altogether and give the img display: block and auto left and
right margins.
Oct 2 '08 #9
Bergamot wrote:
Gus Richter wrote:
>CJM wrote:
>>I'd considered text-align, but I don't want the text part of it centered.

So I wrapped the the whole lot in a <spanand set it's margins to auto
and it's width to 470px, but that didn't work either.
<span class="banner"> <img style="display: block;margin:au to;" src="......

The <spanis superfluous if its only content is the <img>.

Actually it isn't the only content, but also contains subsequent text,
however, pursuant to your comment I checked without the pertinent SPAN
tags and it is not necessary, at least for Firefox.

--
Gus
Oct 3 '08 #10

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

Similar topics

8
14468
by: Daniel Hansen | last post by:
I know this must seem totally basic and stupid, but I cannot find any reference that describes how to control the spacing between <p>...</p> and <div>...</div> blocks. When I implement these on a page, there is a huge gap (like 3/8 inch or 25 px) between them. This is driving me bananas. What the hey am I missing? dh ------------------------------------------------ Dan Hansen ------------------------------------------------
4
3487
by: Hal Canary | last post by:
<div align="center"> does not seem to be identical to <div style="text-align:center">, as this example http://home.earthlink.net/~canaryh3/example.html points out. Yet the 'align' attribute is deprecated. Does anyone have any ideas?
3
4637
by: CMAR | last post by:
To center my <div>, I am currently using something like <div id="navcontainer" align="center"> This centers fine, but is deprecated code. I have seen these two solutions recommended. 1) body { text-align: center; min-width: 500px;
3
3815
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644" onclick="__doPostBack('SitesRadioButtonList_3','')" language="javascript" />
3
4214
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>
7
2463
by: simchajoy2000 | last post by:
Hi, I am just a javascript beginner so maybe this is a simple problem but I am trying to do some rollovers on images in a separate <div>. Here is the relevent piece of my code: <html> <head> <script type="text/javascript"> if (document.images) {
3
7855
by: rsteph | last post by:
I'm using two divs to create a shadowed-box type effect. Within the top div I want to put an image. I can get the image to center right to left, but not top to bottom. I'm making a series of boxes, and the images in them aren't all the same size. So I've sized the boxes to mach the largest of them, and I want to center them, so those that are smaller will be in the middle of the first div. Here's the code on the page: <table border="0"...
8
609
by: CJM | last post by:
I've inserted a new banner in an existing page and I want the banner image to be centered (horizontally) within its container. I'm not bothered whether the accompanying line of text is restricted to the width of the image and centered, or whether is simply fills the width of the container. I've tried various things to achieve this (e.g setting margins to auto) but I'm not having much luck. The URL for the page is: http://www.eminox.es
4
5289
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...
8
10050
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF editor. A fellow member of the PCG has helped me by creating a bit of Javascript to emulate the scrolling and using Google I've now gotten it into a state where it almost passes the W3C Markup Validation Service. However, the one error, Error Line 166,...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10316
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
10295
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
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
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...
1
4275
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
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
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.