SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Text-bottom in Opera

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Text-bottom in Opera

    Hi,

    The following doesn't work in Opera:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <style type="text/css">
    p {font:10pt Arial; background:green; height:16px;}
    img {width:16px; height:16px; vertical-align:text-bottom;}
    </style>
    </head>
    <body>
    <p>An <img src="https://ssl.gstatic.com/images/icons/gplus-16.png" alt=""> image with a text-bottom alignment.</p>
    </body>
    </html>
    Is it a bug or am I missing something?
    Thanks!

  2. #2
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,564
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Vertical-align is can be buggy. Can you just set vertical-align:bottom?
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  3. #3
    Ripe Tomatos silver trophybronze trophy Rayzur's Avatar
    Join Date
    Jun 2007
    Location
    Texas
    Posts
    4,174
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rain Lover View Post
    Is it a bug or am I missing something?
    Thanks!
    Hi,
    Opera does have a bug with vertical-align and I believe you are missing something too.

    Actually vertical-align:text-bottom works fine in Opera, but it does have a bug when vertical-align:bottom is applied to an IMG.
    I remember coming across the problem before and set up a test case here.

    The problem I see with your test case is the fixed height set on your <p>.

    Remove the height and the pt. font-size, then crank up the img size a little bit and you will see that vertical-align:text-bottom works fine in Opera.

    Code HTML4Strict:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>V-A Test</title>
    <style type="text/css">
    p {
        background: green;
    }
    img {
        width: 36px;
        height: 36px;
        vertical-align: text-bottom;
    }
    </style>
    </head>
    <body>
    <p>An <img src="https://ssl.gstatic.com/images/icons/gplus-16.png" alt=""> image with a text-bottom alignment.</p>
    </body>
    </html>


    Now take that code above and simply change it to vertical-align:bottom; then watch Opera fall to pieces.
    As I pointed out in the test case I linked to, the problem occurs when an <img> adjoins anonymous inline boxes.

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rayzur View Post
    Remove the height and the pt. font-size, then crank up the img size a little bit and you will see that vertical-align:text-bottom works fine in Opera.
    It might help, but what if I want to use a small image? I chose a small image, a fixed height for the parent element, and the background color to demonstrate the difference between Opera and other major browsers.

  5. #5
    Ripe Tomatos silver trophybronze trophy Rayzur's Avatar
    Join Date
    Jun 2007
    Location
    Texas
    Posts
    4,174
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rain Lover View Post
    ...I chose a small image, a fixed height for the parent element, and the background color to demonstrate the difference between Opera and other major browsers.
    Hi,
    Yes, I see the difference in the way Opera handles text-bottom. It places it farther down in the parent's content area than it should.

    For x-browser consistency my suggestion would be to use baseline and then tweak the image with a negative margin.
    Of course this will only work with a fixed font-size/line-height. Though it is not recommended to set font-size in px. or pt. for the web but it will give you the same results for your test case.

    I set the line-height at 16px (same as img height) then used a -3px bottom margin on the img. That lines the img bottom up with the text-descenders, which is what text-bottom is supposed to do.

    Code HTML4Strict:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>V-A Test</title>
    <style type="text/css">
    p {
        font: 14px/16px Arial;/*16px line-height to simulate fixed height*/
        background: lime;
        text-decoration: underline;
    }
    img {
        width: 16px;
        height: 16px;
        /*vertical-align: text-bottom;*/
        vertical-align: baseline;/*best choice for x-browser consistency*/
        margin-bottom:-3px;/*now tweak it to fake text-bottom*/
    }
    </style>
    </head>
    <body>
        <p>An <img src="https://ssl.gstatic.com/images/icons/gplus-16.png" alt=""> image with a text-bottom alignment.</p>
    </body>
    </html>

  6. #6
    The CSS Clinic is open silver trophybronze trophy
    SitePoint Award Recipient Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    37,784
    Mentioned
    99 Post(s)
    Tagged
    3 Thread(s)
    Hi,

    You need to set the line-height and then contain the other items on the same line within inline elements so that the img has something to align against.

    This looks the same in Opera Firefox and chrome.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <style type="text/css">
    p {
    	font:10pt Arial;
    	background:green;
    	height:16px;
    	line-height:16px
    }
    img {
    	width:16px;
    	height:16px;
    	vertical-align:text-bottom;
    }
    span { vertical-align:text-bottom; }
    </style>
    </head>
    <body>
    <p><span>An</span> <img src="https://ssl.gstatic.com/images/icons/gplus-16.png" alt=""> <span>image with a text-bottom alignment.</span></p>
    </body>
    </html>

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by Paul O'B View Post
    contain the other items on the same line within inline elements so that the img has something to align against.
    Brilliant! span {vertical-align:text-bottom;} is the key point and seems to be enough to resolve the issue even if you remove the line-height.

    Thank you so much!

  8. #8
    Ripe Tomatos silver trophybronze trophy Rayzur's Avatar
    Join Date
    Jun 2007
    Location
    Texas
    Posts
    4,174
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Paul O'B View Post
    Hi,
    then contain the other items on the same line within inline elements so that the img has something to align against.
    It's a shame that you have to introduce new elements just to make Opera behave though.
    I did point the use of a span in the test case I linked to in my first reply.

    All other browsers are able to to align with the anonymous line boxes.

  9. #9
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rayzur View Post
    I did point the use of a span in the test case I linked to in my first reply.
    Yes, but to tell you the truth I didn't carefully study your test case as it was about vertical-align:bottom. You might want to change its title and the following sentence:
    Opera honors all vertical-alignment on images except BOTTOM

    Thanks anyway!

  10. #10
    The CSS Clinic is open silver trophybronze trophy
    SitePoint Award Recipient Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    37,784
    Mentioned
    99 Post(s)
    Tagged
    3 Thread(s)
    Hi Ray,
    Quote Originally Posted by Rayzur View Post
    All other browsers are able to to align with the anonymous line boxes.
    There's always been a problem with anonymous inline boxes and vertical-align has been buggy in one way or another from day one in quite a few browsers. I always make sure that where alignment is critical I contain the inline elements in a span or similar. It's a pain to add extra elements when not really needed but it does seem to make it more stable. There are still many other bugs though to catch us out

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •