473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Equally positioning DIV's and putting text on images

Hi:) I've been trying to position some element's on my page and I can't
come up with a way to equally position 4 DIV's in another DIV without
explicitly setting the width of the "child" DIV's. Here's what the code
look's like:

<div id="Heading">
<a id="WP">WERSJA POLSKA</a>
<div id="Buttons">
<div id="Home" class="ButtPart"><img
src="Images/Buttons/blank_button.gif" alt="" class="InButtPart" />
<div id="ab"HOME </div></div>
<div id="HTML" class="ButtPart">
<img src="Images/Buttons/blank_button.gif"
class="InButtPart"
alt=""/></div>
<div id="PP" class="ButtPart">
<img src="Images/Buttons/blank_button.gif" alt=""
class="InButtPart"/></div>
<div id="C#" class="ButtPart">
<img src="Images/Buttons/blank_button.gif" alt=""
class="InButtPart"/></div>
</div>
</div>

and the css file:

#WP
{font-weight:bold;color:red;text-align:right;float:right;margin-top:0.5%;margin-bottom:2%}
..ButtPart
{float:left;width:20%;text-align:center;margin-top:0.5%;margin-bottom:2%}
#LM {float:left}
#Buttons {width:70%}
#ab {position:absolute;text-align:center}

Right now it work's but I would like to know if there's a way to do it
without having to play around with the width.
The second and more inportant problem is how to make the text "HOME"
appear exactly in the middle of the first button image. I read about
backgrounds, positioning layers but non of this seems to work in this
case.
I would be gratefull if someone could help me cause today I spent about
5 hours trying to find a sollution without much success

Dec 15 '06 #1
8 3803
On 2006-12-15, Woodchuck <wo*******@postpro.netwrote:
Hi:) I've been trying to position some element's on my page and I can't
come up with a way to equally position 4 DIV's in another DIV without
explicitly setting the width of the "child" DIV's. Here's what the code
look's like:

<div id="Heading">
<a id="WP">WERSJA POLSKA</a>
<div id="Buttons">
<div id="Home" class="ButtPart"><img
src="Images/Buttons/blank_button.gif" alt="" class="InButtPart" />
<div id="ab"HOME </div></div>
<div id="HTML" class="ButtPart">
<img src="Images/Buttons/blank_button.gif"
class="InButtPart"
alt=""/></div>
<div id="PP" class="ButtPart">
<img src="Images/Buttons/blank_button.gif" alt=""
class="InButtPart"/></div>
<div id="C#" class="ButtPart">
<img src="Images/Buttons/blank_button.gif" alt=""
class="InButtPart"/></div>
</div>
</div>

and the css file:

#WP
{font-weight:bold;color:red;text-align:right;float:right;margin-top:0.5%;margin-bottom:2%}
.ButtPart
{float:left;width:20%;text-align:center;margin-top:0.5%;margin-bottom:2%}
#LM {float:left}
#Buttons {width:70%}
#ab {position:absolute;text-align:center}

Right now it work's but I would like to know if there's a way to do it
without having to play around with the width.
Only with a table. You can give the whole table a width, put each
ButtPart in a cell, and the UA will aim to make the cells equal widths.
The second and more inportant problem is how to make the text "HOME"
appear exactly in the middle of the first button image. I read about
backgrounds, positioning layers but non of this seems to work in this
case.
How about: use a background image, set line height, and make the text a
vertically-aligned-middle text-aligned-centre inline. Like this:

div
{
background-image: url(home.png);

/*
Set these to whatever size you want the image to be, preferably
the same values as its intrinsic size.
*/
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
}

span
{
vertical-align: middle;
}

....

<div>
<span>HOME</span>
</div>

May not work in IE.
Dec 15 '06 #2
First of all thanks for your answer:)
Only with a table. You can give the whole table a width, put each
ButtPart in a cell, and the UA will aim to make the cells equal widths.
Hmm... I read in many places that tables should be used only to present
tabular data... Why isn't there a CSS way to accomplish such a layout?

As for the image and text problem I tried what you proposed and it
works both in IE and Firefox but now I have the rest of my images
stacked underneath the
first one. I must rethink what is going on cause I can't full
comprehend this CSS language :) Maybe someone knows a good tutorial
explaining the layout possibilities of this language? :)
As for the idea of using the image as a background I don't know if it
will work cause i I want that image to be anchored to a hyperlink and I
don't know if you could do it for backgrounds.

Dec 16 '06 #3
On 2006-12-16, Woodchuck <wo*******@postpro.netwrote:
First of all thanks for your answer:)
>Only with a table. You can give the whole table a width, put each
ButtPart in a cell, and the UA will aim to make the cells equal widths.

Hmm... I read in many places that tables should be used only to present
tabular data... Why isn't there a CSS way to accomplish such a layout?
There is, display: table-cell and friends, they just don't work in IE.
As for the image and text problem I tried what you proposed and it
works both in IE and Firefox
Good.
but now I have the rest of my images stacked underneath the first one.
Sounds like they're ending up slightly too wide for some reason. But
you'd need to post a url to a page reproducing the problem.
I must rethink what is going on cause I can't full comprehend this CSS
language :) Maybe someone knows a good tutorial explaining the layout
possibilities of this language? :) As for the idea of using the image
as a background I don't know if it will work cause i I want that image
to be anchored to a hyperlink and I don't know if you could do it for
backgrounds.
You can't hyperlink the background image itself, but you can hyperlink
the box it's in which is just as good.

e.g.

a
{
display: block;
background-image: url(home.png);
width: 100px;
height: 100px;
}

....

<a href="http://home"></a>
Dec 16 '06 #4
On 2006-12-16, Ben C <sp******@spam.eggswrote:
[snip]
You can't hyperlink the background image itself, but you can hyperlink
the box it's in which is just as good.

e.g.

a
{
display: block;
background-image: url(home.png);
width: 100px;
height: 100px;
}

...

<a href="http://home"></a>
Following up to myself here... but I should point out that there are
likely to be some accessibility problems with this for users without CSS
enabled.
Dec 16 '06 #5

Ben C wrote:
There is, display: table-cell and friends, they just don't work in IE.
Thanks very much:):) This is the most helpful answer in weeks:):) I
have read a little about display: table-cell and this is what I was
waiting for. It looks like I won't have to learn floating, and all
those complicated CSS stuff cause CSS tables look much easier:) As for
IE I read that they-re working hard on the support for this feature in
the next version:) Right now I'll stick to an HTML table...
You can't hyperlink the background image itself, but you can hyperlink
the box it's in which is just as good.
(...)
Sounds like they're ending up slightly too wide for some reason. But
you'd need to post a url to a page reproducing the problem.
(...)
Following up to myself here... but I should point out that there are
likely to be some accessibility problems with this for users without CSS
enabled.

That's an idea, but your right about that accessibility concern. I want
all my webpage content to be visible on as much devices as I can, and
much of them (for example cell phones) probably won't have CSS support.
I think I need to find a different way to position that text. From what
I read about layers they look good but I don't know what positioning to
choose... It would be good to to put the text in a layer and make it
behave just like the container was empty. Than I could position it
exactly the same way I positioned the image. Is there such positionning
in CSS?

Dec 16 '06 #6
On 2006-12-16, Woodchuck <wo*******@postpro.netwrote:
>
Ben C wrote:
[snip]
>You can't hyperlink the background image itself, but you can hyperlink
the box it's in which is just as good.
(...)
>Sounds like they're ending up slightly too wide for some reason. But
you'd need to post a url to a page reproducing the problem.
(...)
>Following up to myself here... but I should point out that there are
likely to be some accessibility problems with this for users without CSS
enabled.


That's an idea, but your right about that accessibility concern. I want
all my webpage content to be visible on as much devices as I can, and
much of them (for example cell phones) probably won't have CSS support.
You could just put some text in the <abut make it display: none in the
CSS.

i.e.

a
{
display: block;
width, height, background-image, etc...
}

a span
{
display: none;
}

<a href="home"><span>Home</span></a>

That way someone with no CSS will just get the text "Home", but people
with CSS will get the graphic but not the text.

Surely mobile phones will have CSS though? Accessibility is still a good
goal though. I'd better not talk you out of that one having already
given you an excuse to use tables...
I think I need to find a different way to position that text. From what
I read about layers they look good but I don't know what positioning to
choose... It would be good to to put the text in a layer and make it
behave just like the container was empty. Than I could position it
exactly the same way I positioned the image. Is there such positionning
in CSS?
What's a "layer"?
Dec 16 '06 #7
Ben C wrote:
>
a span
{
display: none;
}

<a href="home"><span>Home</span></a>

That way someone with no CSS will just get the text "Home", but people
with CSS will get the graphic but not the text.
Except for those people who browse with image loading disabled, or
anyone using a screen reader. :(

--
Berg
Dec 16 '06 #8
You could just put some text in the <abut make it display: none in the
CSS.
(...)
That way someone with no CSS will just get the text "Home", but people
with CSS will get the graphic but not the text.
Surely mobile phones will have CSS though? Accessibility is still a good
goal though. I'd better not talk you out of that one having already
given you an excuse to use tables...
:) You haven't talked me out:) As for the mobile phones they probably
will, but at least now some don't. I have a 132x176 Siemens CX65 and I
don't think it has CSS:) I still want to have all the data (images,
animations, text etc.) in XHTML and just the layout stuff in CSS.

What's a "layer"?
Sorry:) I meant a DIV but in the context that it's positioned "on top"
of the other DIV's. I think I explained it quite good in that paragraph
so you might as well just substitute "layer" for "div".

Dec 17 '06 #9

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

Similar topics

13
by: murali | last post by:
Hello everyone, I used absolute positioning with div tag in my website. The page looks cool as long as someone doesn't try to zoom in by increasing the text size (ctrl++ or thru changing font...
9
by: Bryan R. Meyer | last post by:
Hello Everyone, The problem of browser resizing has become an issue for me. While redesigning my webpage, I set the left and right margins to be auto so that my content would be centered. ...
1
by: DB McGee | last post by:
I'm having difficulities positioning text over an image. Specifically, I am trying to position the text within each <div> to the topleft of each image within that <div>. The following works as I...
4
by: salty_dogs | last post by:
i have a site that works well in ie6 for the pc. but i've also seen it (don't have a mac) with ie for mac and safari. both of these browsers produce different and unwanted results. the biggest...
4
by: TheCeej | last post by:
I'm sorry to post what is ultimately a myspace problem, but I'm sure I'd still be having this problem with any html/css document, so the answer would more than likely be able to help anyone out. I'm...
2
by: nonsensitor | last post by:
I'm just learning xhtml & css, primarily from westciv's online tutorials and css guide. I've run into a couple of problems with a page I'm developing that I can't figure out. The first problem is...
2
by: nino9stars | last post by:
Hello, I have just started messing with absolute positioning on webpages, and it definitely let's you do some creative things. Well, after much searching and help, I got the images I was using...
9
by: wreed | last post by:
I have several questions. I ran my html and css through a checker, and fixed all of the errors it found. 1) I was using IE for development, but have now switched to FF after reading other posts....
4
by: Christopera | last post by:
Hello, I have built a site that uses two divs, one verticle, and one horizontal as graphic style for the ite. The problem I am having is that if the browser is resized very small the divs are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.