473,788 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mixing pixel and em sizing to align images and text

I'm wrestling with how to align images with text. The particular effect
I'm trying to achieve at the moment is to place a heading to the right of
an image, such that the image and text are vertically centred with each
other, regardless of how the user has their fonts set up(1).

See http://www.trawna.com/test/header1.html for some examples of what I've
tried. IE6/Win shows the second one how I want it, but Opera 7.23 and
Mozilla 1.0 don't like any of them. (Too bad we can't use mathematical
operators in CSS; I keep finding places where something resembling
{ margin-top:70px-0.5em; } would come in handy.)

I have a suspicion that the solution will be very simple, and I'll learn
something highly useful out of all this.

(1) A related problem will occur if the default font for h1 text makes it
taller than the image. Would { height:70px; min-height:1em; } be the
"right way" to solve this, and if so what browsers will it still break in?

--
Greg Schmidt gr***@trawna.co m
Trawna Publications http://www.trawna.com/
Jul 20 '05 #1
6 6898
Greg Schmidt <gr***@trawna.c om> wrote:
I'm wrestling with how to align images with text. The particular effect
I'm trying to achieve at the moment is to place a heading to the right of
an image, such that the image and text are vertically centred with each
other, regardless of how the user has their fonts set up(1).


img{vertical-align:middle}
h1{display:inli ne}

<img ...>
<h1>Header</h1>

--
Spartanicus
Jul 20 '05 #2
Greg Schmidt wrote:
I'm wrestling with how to align images with text. The particular effect
I'm trying to achieve at the moment is to place a heading to the right of
an image, such that the image and text are vertically centred with each
other, regardless of how the user has their fonts set up(1).


Make the image a background of the text's block element, positioned at
0% 50%. Set that element's padding-left to include space for the image.
Adjust other properties such that the text is always vertically-centred
in the block.

This will fail if the containing element gets smaller than the image
height, of course.

It's the same technique I (and many others) use for the little external
link icon, although on the other side of the text. See
http://tranchant.plus.com/notes/cable-wrap for an example.

--
Mark.
http://tranchant.plus.com/
Jul 20 '05 #3
On Mon, 05 Jul 2004 22:00:47 +0100, Spartanicus wrote:
Greg Schmidt <gr***@trawna.c om> wrote:
I'm wrestling with how to align images with text. The particular effect
I'm trying to achieve at the moment is to place a heading to the right of
an image, such that the image and text are vertically centred with each
other, regardless of how the user has their fonts set up(1).


img{vertical-align:middle}
h1{display:inli ne}

<img ...>
<h1>Header</h1>


Changing this to <h1><img ...>Header</h1> makes the vertical spacing a
little bit better on some browsers, plus it keeps the logo and the heading
on the same line (albeit not centred with each other) in NN4. The text is
a little bit high in IE5, but I can live with that.

This seems like the best so far. All five trials are still at
http://www.trawna.com/test/header1.html for anyone who wants to see what
I've tried, or make further suggestions.

--
Greg Schmidt gr***@trawna.co m
Trawna Publications http://www.trawna.com/
Jul 20 '05 #4
On Tue, 06 Jul 2004 07:56:38 +0100, Mark Tranchant wrote:
Greg Schmidt wrote:
I'm wrestling with how to align images with text. The particular effect
I'm trying to achieve at the moment is to place a heading to the right of
an image, such that the image and text are vertically centred with each
other, regardless of how the user has their fonts set up(1).


Make the image a background of the text's block element, positioned at
0% 50%. Set that element's padding-left to include space for the image.
Adjust other properties such that the text is always vertically-centred
in the block.

This will fail if the containing element gets smaller than the image
height, of course.

It's the same technique I (and many others) use for the little external
link icon, although on the other side of the text. See
http://tranchant.plus.com/notes/cable-wrap for an example.


I got this to work pretty well in all modern browsers, but the logo is
completely lost in NN4, which isn't acceptable in this instance. I know
that NN4 is likely to end up rendering everything I do significantly
different from other browsers, and that's fine, but losing the corporate
logo is too high a price to pay.

It's an excellent strategy for your external links, particularly because
there is no extra HTML required, but in my situation I think that the logo
is more like content than presentation.

All five trials are still at http://www.trawna.com/test/header1.html for
anyone who wants to see what I've tried, or make further suggestions.

--
Greg Schmidt gr***@trawna.co m
Trawna Publications http://www.trawna.com/
Jul 20 '05 #5
Greg Schmidt <gr***@trawna.c om> wrote:
plus it keeps the logo and the heading
on the same line (albeit not centred with each other) in NN4.


For future queries you might want to mention up front if something needs
to work in NS4 (if you don't we assume otherwise).

People who are aware of what CSS NS4 can and cannot handle are rapidly
becoming extinct (we have one in the local Zoo here, but there's a sign
on the fence saying that we're not allowed to feed him).

--
Spartanicus
Jul 20 '05 #6
On Tue, 06 Jul 2004 22:45:57 +0100, Spartanicus wrote:
Greg Schmidt <gr***@trawna.c om> wrote:
plus it keeps the logo and the heading
on the same line (albeit not centred with each other) in NN4.
For future queries you might want to mention up front if something needs
to work in NS4 (if you don't we assume otherwise).


Well, there are different levels of "working". I don't believe that
everyone here has abandoned graceful degradation, but what may be
considered graceful depends greatly on the situation.

Mark's proposal works for him, because in his situation losing the image
can be considered graceful, but it didn't work for me because my situation
is different. (It's tucked away in the bag of tricks for when I do need
something like that.)

If your suggestion was the only way to get the effect I wanted and there
was no way to get it to work in NN4, then I'd accept that, but as it turns
out the minor modification that I made doesn't appear to break anything
plus it works better in NN4. You got me 95% of the way there, and I didn't
mean to sound like I was ungrateful or disappointed that I had to do the
last 5%; I was just adding what I had discovered for anyone else who finds
the information useful.
People who are aware of what CSS NS4 can and cannot handle are rapidly
becoming extinct (we have one in the local Zoo here, but there's a sign
on the fence saying that we're not allowed to feed him).


I long ago gave up any expectation that I would be able to get pages to
look the same in NN4 and, well, anything else. But I do still put some
small effort into making it look decent.

--
Greg Schmidt gr***@trawna.co m
Trawna Publications http://www.trawna.com/
Jul 20 '05 #7

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

Similar topics

0
1422
by: Richard | last post by:
Considering the code below. Adapting this part of the code from meyerweb.com to my own use, I was playing around with some values and came up with an interesting result I like. Copy and paste the code and try it out and you'll see what I mean. The problem is, somehow in the coding, my thumbnails can not be presented as they are given. The dimensions of the thumbnails are totally dependent upon the fixed value of the height in the first...
6
9902
by: wiewel | last post by:
hi all, i have a strange problem when trying to set up a horizontal menubar: i would like to split the whole screen from left to right into 9 pieces. the first one has a fixed width of 186px. the remaining 8 should all have the same width, depending on the screen resolution. how can i get this to work in both IE and mozilla? i already have a solution that works fine in mozilla, but does not in IE.
33
2440
by: Dave (DreamIsle) | last post by:
Hello. I'm working on a layout that I need to be pixel specific. How can I get the font to stay precisely the height I need? Specifying line-height or font-size in px doesn't yield the results I need. The font size scales when I change the browser's font size and the text moves from where I need it.
2
2490
by: vinit_mahajan99 | last post by:
Hello all, I want to align the images and controls at the bottom of a master page or at the right side. I tried to do it with the table but I was not successful. The image should be seen at the bottom of the page. Please reply....
1
2688
by: rsteph | last post by:
I've got a page with a menu div that is 1066px wide by 150px high. And then I have some images that are 150px by 150px for the menu items. I put the images in a table that is set to 150x150px with a 1px border around the table, and around each cell in the table. For some reason though, a space is appearing inside the table, below the images. I've made the menu div background color red, so that it is obvious what's happened. I've also resized...
3
4422
by: acunnon | last post by:
I am trying to put together an login page my problem is getting the three items aligned to the middle verticaly without specifing a height to anything on the page. CSS html{ height:100%; min-height:100%; } body{ vertical-align:middle;
7
6414
by: teo | last post by:
Hallo, I'd like to retrieve the pixel length of a string. ------------------------ I decided to use MeasureString, but I have a problem with the graphic "instance" of it. I'm in a Sub and
6
1546
by: ITistic | last post by:
http://tinyurl.com/5z4yo4 When viewing this page in Internet Explorer for the first time the outer most table is much wider than it should be and then slowly resizes to the correct size as images are loaded. It's impossible for us to set the dimensions of the product images as they are unknown to the e-commerce software which generates these pages. The pages display in Firefox perfectly. What can we do to correct this?
13
3323
by: Stevo | last post by:
I've found that for IE6+, if you add the property text-align:center to a DIV, then *anything* inside it gets centered. That can be a table, an object/embed, another DIV, an image, or some text. Firefox and Safari on the other hand don't treat text-align in that way. In my tests on those browsers, they only centers images and text. Any DIVs, object/embeds or tables remain default unaligned and generally appear on the left. Considering...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.