Go Back   Velocity Reviews > Newsgroups > HTML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

HTML - Positioning in DIV with scrollbar

 
Thread Tools Search this Thread
Old 11-23-2003, 04:01 PM   #1
Default 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


Anna
  Reply With Quote
Old 11-23-2003, 04:47 PM   #2
Bertilo Wennergren
 
Posts: n/a
Default Re: Positioning in DIV with scrollbar
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 <> <http://www.bertilow.com>



Bertilo Wennergren
  Reply With Quote
Old 11-23-2003, 04:54 PM   #3
Toby A Inkster
 
Posts: n/a
Default Re: Positioning in DIV with scrollbar
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



Toby A Inkster
  Reply With Quote
Old 11-23-2003, 07:56 PM   #4
Safalra
 
Posts: n/a
Default Re: Positioning in DIV with scrollbar
(Anna) wrote in message news:<. 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


Safalra
  Reply With Quote
Old 11-24-2003, 02:13 PM   #5
Anna
 
Posts: n/a
Default Re: Positioning in DIV with scrollbar
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

(Safalra) wrote in message news:<. com>...
> (Anna) wrote in message news:<. 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



Anna
  Reply With Quote
Old 11-25-2003, 09:14 AM   #6
Safalra
 
Posts: n/a
Default Re: Positioning in DIV with scrollbar
(Anna) wrote in message news:<. com>...
> (Safalra) wrote in message news:<. com>...
> > (Anna) wrote in message news:<. 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


Safalra
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46