473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Positioning in DIV with scrollbar

Hi all.
I have a div with a scrollbar, which contains an image:
<div style=" width:15em; height:10em; overflow:scroll;">
<img src="some.gif"/>
</div>

The image is rather small, it occupies only a small part of the div.
This way the image appears in the top left corner of a div.
I want it to appear in the center of the div.

I tried adding align:center to style, and also adding another div
inside the frst one with style="align:center", but this doesn't work.

Is there a way for div with a scrollbar to position embedded tags
in the center of a div?

Thank you in advance for your help.

Anna
Jul 20 '05 #1
6 46649
Anna:
I have a div with a scrollbar, which contains an image:
<div style=" width:15em; height:10em; overflow:scroll;">
<img src="some.gif"/>
</div> The image is rather small, it occupies only a small part of the div.
It's a bit strange that you've set the width of the div in "em"s, when
the only content is an image. The actual size of the div will thus
depend on the font and font size being actually used in display although
there is no actual text in that div. That could be quite another font
and size than you've set in your CSS. If the only content in the div is
an image, then a size in "px" is probably better.

(You must also have an alt attribute in the img.)
This way the image appears in the top left corner of a div.
I want it to appear in the center of the div. I tried adding align:center to style, and also adding another div
inside the frst one with style="align:center", but this doesn't work.


There is no property "align" in CSS. Try "text-align: center".

--
Bertilo Wennergren <be******@gmx.net> <http://www.bertilow.com>

Jul 20 '05 #2
Anna wrote:
I want it to appear in the center of the div.


Top centre, bottom centre or middle centre?

If the image is purely decorational (I assume it is because your example
didn't include any alt text) then you could use:

<div style="width:15em; height:10em; overflow:scroll;
background: white url(some.gif) no-repeat scroll top center;">
&nbsp;</div>

or

<div style="width:15em; height:10em; overflow:scroll;
background: white url(some.gif) no-repeat scroll center center;">
&nbsp;</div>

or

<div style="width:15em; height:10em; overflow:scroll;
background: white url(some.gif) no-repeat scroll bottom center;">
&nbsp;</div>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?page=132

Jul 20 '05 #3
an**@ubaccess.com (Anna) wrote in message news:<8e**************************@posting.google. com>...
I want [an image] to appear in the center of the div.
I tried adding align:center to style, [snip] but this doesn't work.


You need to use 'text-align:center' (as images are inline content).

--- Stephen Morley ---
http://www.safalra.com
Jul 20 '05 #4
Thanks everybody for the answer.
I can't make the image a background of the div, because it can be not
image,
but some other content inside this scrolled div.
So I've added 'text-align:center' to the style attribute of the div.
Now the image is top centered. But I actually want it middle centered,
and cannot find the right css attribute for that.
vertical-align doesn't work on divs.
So is there any other css attribute that can make this image to be
middle centered in the scrollable div?

Thank you all very much for your help.

Anna

us****@safalra.com (Safalra) wrote in message news:<c5**************************@posting.google. com>...
an**@ubaccess.com (Anna) wrote in message news:<8e**************************@posting.google. com>...
I want [an image] to appear in the center of the div.
I tried adding align:center to style, [snip] but this doesn't work.


You need to use 'text-align:center' (as images are inline content).

--- Stephen Morley ---
http://www.safalra.com

Jul 20 '05 #5
How am I supposed to post my replies in a newsgroup?:
http://allmyfaqs.com/faq.pl?How_to_post

Anna wrote:
Thanks everybody for the answer.
I can't make the image a background of the div


--
Brian
follow the directions in my address to email me

Jul 20 '05 #6
an**@ubaccess.com (Anna) wrote in message news:<8e**************************@posting.google. com>...
us****@safalra.com (Safalra) wrote in message news:<c5**************************@posting.google. com>...
an**@ubaccess.com (Anna) wrote in message news:<8e**************************@posting.google. com>...
I want [an image] to appear in the center of the div.
I tried adding align:center to style, [snip] but this doesn't work.


You need to use 'text-align:center' (as images are inline content).


vertical-align doesn't work on divs.
So is there any other css attribute that can make this image to be
middle centered in the scrollable div?

[top posting fixed]

No, but there's a hack involving some extra mark-up, for details see:

http://www.wpdfd.com/editorial/wpd0103.htm#toptip

From your posts so far, it seems you are under the impression that CSS
attributes correspond directly to old HTML attributes. This is not so;
I suggest you have a browse of the CSS recommendation:

http://www.w3.org/TR/REC-CSS2/

--- Stephen Morley ---
http://www.safalra.com
Jul 20 '05 #7

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

Similar topics

9
by: Bryan R. Meyer | last post by:
Hello Everyone, The problem of browser resizing has become an issue for me. While redesigning my webpage, I set the left and right margins to be auto so that my content would be centered. ...
3
by: Mike Anderson | last post by:
I'm having a problem with the positioning of a div block in IE6. http://www.uah.edu/Athletics/index.shtml When the window is resized to a width smaller than the width of the "body" div (that...
6
by: Susan | last post by:
This time I've got a url! http://www.wmich.edu/ucm/testing/index_pos.htm 1) How can I make the lengths of the white sections (the main area and the link area on the right) the same length? ...
1
by: lilo | last post by:
Hi, I'd like to position the scrollbar on the left side of a table cell, as the navigation buttons are on the right side, and i would like the scroll bar to be on the opposite side. Any way to...
17
by: George Hester | last post by:
http://tinyurl.com/5uj6w The lower middle icon the "block" should not drop down when the mouse is over it. How can I stop that? Also the navigation divs both top and bottom should follow the...
20
by: Geoffrey H. Goldberg | last post by:
I have made a remote control window which opens from its parent. On loading, the remote is positioned relative to the screen using window.moveTo(x,y). What I would like to happen is the remote...
1
by: Eric | last post by:
I have a page with some ASP.NET controls at the top and a datalist which might include anything from 1 to 25 elements below them, all laid out with absolute CSS positioning. The problem I'm...
4
by: TheCeej | last post by:
I'm sorry to post what is ultimately a myspace problem, but I'm sure I'd still be having this problem with any html/css document, so the answer would more than likely be able to help anyone out. I'm...
18
by: LayneMitch | last post by:
Hello. After getting great advice on positioning, I've edited my code and it's looking more stable. Now I need a little assistance with background image placement. Please click on this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.