Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 25th, 2005, 04:31 PM
Ursus Ursus is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Maryland, USA
Posts: 402 Ursus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 4 m 30 sec
Reputation Power: 2
CSS: center dynamic image in div

As a learning tool, I'm updating an old page of mine to use CSS and XHTML and I'm running into a problem aligning the main image in its containing div. What I want to do is center the image both vertically and horizontally. The problem is that the image that displays is dynamically selected from a directory of images, some of which are of landscape orientation and some of which are of portrait orientation.

Now, I know I could use php to determine the dimensions of the image and javascript to reset the positioning attributes, but it seems like a lot of work to replace the old method by which it was centered:
Code:
<p align='center'><img..... /></p>


Can y'all clue me in to a better way to do this?

Thanks.

Reply With Quote
  #2  
Old August 25th, 2005, 09:39 PM
niko_zeta niko_zeta is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Rossmoyne, WA, Australia
Posts: 105 niko_zeta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to niko_zeta Send a message via AIM to niko_zeta Send a message via Yahoo to niko_zeta
RE: CSS: center dynamic image in div

Doesn't this work: ?
Code:
<div style="text-align: center;">
    <img src="<?php echo $imgsrc ?>" />
</div>


Reply With Quote
  #3  
Old August 25th, 2005, 10:12 PM
Ursus Ursus is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Maryland, USA
Posts: 402 Ursus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 4 m 30 sec
Reputation Power: 2
RE: CSS: center dynamic image in div

text-align:center does horizontal, but not vertical

Reply With Quote
  #4  
Old August 26th, 2005, 05:57 PM
Don Macleod Don Macleod is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Western Isles - Scotland
Posts: 2 Don Macleod User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 sec
Reputation Power: 0
RE: CSS: center dynamic image in div

Are you using inline styles or are you linking to an external stylesheet?

Reply With Quote
  #5  
Old August 26th, 2005, 06:07 PM
Ursus Ursus is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Maryland, USA
Posts: 402 Ursus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 4 m 30 sec
Reputation Power: 2
RE: CSS: center dynamic image in div

Inline. Why?

Reply With Quote
  #6  
Old August 26th, 2005, 08:44 PM
Don Macleod Don Macleod is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Western Isles - Scotland
Posts: 2 Don Macleod User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 sec
Reputation Power: 0
RE: CSS: center dynamic image in div

Because inline styles can often make the individual page code unwieldy and its most often better to give a div an identity and define it in an external stylesheet.

Anyway, have you tried extending what niko_zeta said by introducing:

<div style="text-align: center; vertical-align: center">
<img src="<?php echo $imgsrc ?>" />
</div>

Another alternative is to use either relative or absolute positioning depending on which better suits your needs.

Reply With Quote
  #7  
Old August 26th, 2005, 10:17 PM
Ursus Ursus is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Maryland, USA
Posts: 402 Ursus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 4 m 30 sec
Reputation Power: 2
RE: CSS: center dynamic image in div

Yeah, I tried vertical-align: middle, both in the div tag and in the img it contains. I don't care what the w3c says, vertical-align DOES NOT alter an element's position within its parent tag.

I've been avoiding declaring the positioning since to do that I'll have to calculate the dimensions of the image, but it doesn't appear I have much choice.

Thanks for the suggestions.

Reply With Quote
  #8  
Old August 27th, 2005, 03:40 PM
niko_zeta niko_zeta is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Rossmoyne, WA, Australia
Posts: 105 niko_zeta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to niko_zeta Send a message via AIM to niko_zeta Send a message via Yahoo to niko_zeta
RE: CSS: center dynamic image in div

Just a tip: vertical-align seems to only work with table elements like td, th, tr. I've never got it to work with divs.

Reply With Quote
  #9  
Old August 29th, 2005, 12:03 AM
brut brut is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 367 brut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 30 sec
Reputation Power: 2
RE: CSS: center dynamic image in div

This works (sort of) in latest IE/FF, with deviations between, of course.

php Code:
Original - php Code
  1.  
  2.  <div style="text-align:center; height:100%; border-style:solid;">
  3.   <img src="./pic.gif" style="position:relative; top:50%; border-style:solid;" />
  4.  </div>


ps I've made several requests to fix the 'code' tags for this forum to retain formatting, to no avail. Thus the 'php' tags for html.

Reply With Quote
  #10  
Old August 29th, 2005, 12:21 AM
niko_zeta niko_zeta is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Rossmoyne, WA, Australia
Posts: 105 niko_zeta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to niko_zeta Send a message via AIM to niko_zeta Send a message via Yahoo to niko_zeta
RE: CSS: center dynamic image in div

The div must of course not be of "display: block", because block elements are not sensitive to content size: 'height: 100%' will stretch the height of the div to its container's height, not its content's height.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > CSS: center dynamic image in div


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT