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, 2003, 05:58 PM
Ashkhan Ashkhan is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 372 Ashkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 57 sec
Reputation Power: 3
Vertical aligning with CSS


Assume a div element with height of 50px. Inside this div is a picture 25x25.
All I need is to vertical align this picture to the middle of that div.
I can do this with padding-top, but the height of parent div can vary.
I tried vertical-align:middle, but it doesn't work. The only thing, that works, is using tables and valign:middle. There should be a way to do it with CSS.

Any idea?

Reply With Quote
  #2  
Old August 27th, 2003, 08:45 AM
crisp crisp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Holland
Posts: 336 crisp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Vertical aligning with CSS

Code:
<style type="text/css">
#container {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 50px;
  height: 50px;
  border: 1px solid black;
}
#picture {
  display: block;
  position: absolute:
  top: 50%;
  left: 50%;
  margin-top: -12px;
  margin-left: -12px;
  width: 25px;
  height: 25px;
}
</style>
<div id="container">
  <img id="picture" src="picture.gif" alt="" />
</div>

Reply With Quote
  #3  
Old August 27th, 2003, 10:50 AM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Vertical aligning with CSS

good work crisp.. i knew it can be done (with %), but i couldn't remember to use margins to make it rigth at the middle...

:^

Reply With Quote
  #4  
Old August 27th, 2003, 04:42 PM
Ashkhan Ashkhan is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 372 Ashkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 57 sec
Reputation Power: 3
RE: Vertical aligning with CSS

Thanks crisp!

It looks good, can't wait to try it.

I hope it will work for major browsers.

Reply With Quote
  #5  
Old August 27th, 2003, 04:50 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,252 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 5
Send a message via Yahoo to bakertrg
RE: Vertical aligning with CSS

50% - half the image, sweet logic, it was baffling me. Has anyone put php variables in a style sheet? Can it be done in an external style sheet, or only in an inline or local style?

one question is #picture the same as .picture ?

Reply With Quote
  #6  
Old August 27th, 2003, 06:35 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 4
RE: Vertical aligning with CSS

You can easily use PHP in an external stylesheet, just reference style.php (or whatever the name of the script is) instead of style.css. style.php just needs to output a valid style sheet rather than HTML.

Your web server is probably setup to serve php pages as text/html by default. This shouldn't be a problem, but adding a header to say it's actually text/css should avoid warnings in really picky browsers.

Reply With Quote
  #7  
Old August 27th, 2003, 08:56 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,252 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 5
Send a message via Yahoo to bakertrg
RE: Vertical aligning with CSS

let me make sure I have this correct:

php Code:
Original - php Code
  1.  
  2. // I currently have this in my header file
  3. <link rel="stylesheet" href="../includes/style.css" type="text/css">
  4. // I can change this to
  5. <link rel="stylesheet" href="../includes/style.php" type="text/css">
  6. // then in my style sheet I could replace
  7. .header {            
  8.         background-color: #C06270; 
  9.     color: #ffffff;
  10.     font-size: 10pt;
  11.     font-weight: bold
  12. }
  13. // with
  14.     background-color: <?php echo $bgcolor ?>;
  15.     color: <?php echo $font_color ?>;
  16.     font-size: 10pt;
  17.     font-weight: bold
  18. }


I have been meaning to experiment with this for a long time but I have just been editing my same old stylesheet on just about every site I make.

I still don't understand #class as opposed to .class is there a difference? I guess I could rtfm...

Reply With Quote
  #8  
Old August 28th, 2003, 02:11 AM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 4
RE: RE: Vertical aligning with CSS

Quote:
let me make sure I have this correct:

Yes, that should work.

Quote:
I still don't understand #class as opposed to .class is there a difference? I guess I could rtfm...



Well, #class is a mis-leading way of writing it. Using #id or #name makes it a little clearer.

# selects elements by id or name attribute
. selects elements by class attribute

Reply With Quote
  #9  
Old August 28th, 2003, 07:38 AM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,252 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 5
Send a message via Yahoo to bakertrg
RE: Vertical aligning with CSS

I see, thanks. I always use class="something" on every element I want to control so I have never used the # sign.

Is defining the link as type="text/css" what you referred to as adding a header?

Reply With Quote
  #10  
Old August 28th, 2003, 11:25 AM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 4
RE: RE: Vertical aligning with CSS

Quote:
Is defining the link as type="text/css" what you referred to as adding a header?


No, that's not what I meant, although you should definitely leave that in there.

If you load your page with Mozilla and open up the Javascript console, you'll probably see something like: Warning: The stylesheet style.php was loaded as CSS even though its MIME type, "text/plain", is not "text/css".

I think adding header('Content-type: text/css') to style.php should fix that. That's getting really picky though, so I wouldn't worry about.

Reply With Quote
  #11  
Old August 28th, 2003, 04:57 PM
Ashkhan Ashkhan is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 372 Ashkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 57 sec
Reputation Power: 3
RE: Vertical aligning with CSS

Using a php file as a style sheet is interesting idea.

One more question:

What units are you using? I'm using pixels but in different browsers pixels have different size and it is hard to control right position of elements.

I think this is cannot be avoided or am I wrong?

Reply With Quote
  #12  
Old August 28th, 2003, 04:59 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Vertical aligning with CSS

if you write old-type html pages, don't worry about content type...

if you want to write XHTML strict standard pages, than you should send that text/css content type...

(you also should send application/xhtml+xml but nobody does that, so what then...)


btw, use em and % units. on normal zoom/text size, 1px is aproximatly around 0.1em, so conversion is not that dificult...

Reply With Quote
  #13  
Old August 28th, 2003, 05:10 PM
Ashkhan Ashkhan is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 372 Ashkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 57 sec
Reputation Power: 3
RE: Vertical aligning with CSS

Hm, I don't see any reason to write pages in XHTML right now.

I even don't know its specifications.

But I don't like when my pages are exactly as I wanted in IE and Opera and then a little bit shaky in Mozilla and Konqueror. But that's an old problem...

Do you know a good page with CSS 'tricks'?

I decided to rewrite my table&CSS structure structure to pure CSS, so it would be handy.

Reply With Quote
  #14  
Old August 28th, 2003, 05:16 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,252 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 5
Send a message via Yahoo to bakertrg
RE: Vertical aligning with CSS

I really like the idea of putting php variables in my style sheet as I already include a file in all my pages has the colors for the project included as variables. Since many of the styles I use, I use repeatedly I drop my standard style sheet in each new project then edit the colors to match the project. If I had variables in there I could just edit the list of colors in one place, one time and presto the color scheme would be done.

Reply With Quote
  #15  
Old August 28th, 2003, 06:58 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 4
RE: RE: Vertical aligning with CSS

Quote:
Hm, I don't see any reason to write pages in XHTML right now.


For an agrument for using XHTML and CSS, see this site.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Vertical aligning with CSS


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!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek