472,961 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

text next to image

Hi,
I am new to CSS.
I want to have an image (170x250) centered and have some text to the
right of it, starting from top of the image.
I have:

..info
{
position: absolute;
top:100px;
left:200px;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
color: #000000;
word-spacing: normal;
line-height: 10pt;
padding:10
}
..info img {
position:absolute;
top:0;
left:0;
width:170px;
align:center;
padding:10;
float:left;
}

and in html:
<div class="info">
<p><img ...> blah blah blah
</div>

But the text starts from the bottom of the image.

Where am I goofing up?

Dec 6 '05 #1
7 13791
as*******@hotmail.com wrote:
Hi,
I am new to CSS.
I want to have an image (170x250) centered and have some text to the
right of it, starting from top of the image.
I have:

.info
{
position: absolute;
top:100px;
left:200px;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
color: #000000;
word-spacing: normal;
line-height: 10pt;
padding:10
}
.info img {
position:absolute;
top:0;
left:0;
width:170px;
align:center;
padding:10;
float:left;
}

and in html:
<div class="info">
<p><img ...> blah blah blah
</div>

But the text starts from the bottom of the image.

Where am I goofing up?

The position absolute in the img style means it will ignore the .info
container.

All you really need is
..info img {float:left;}
<div class="info">
<img ...> blah blah blah
</div>
Dec 6 '05 #2
Thank you meltdown.
if I want to center both the image and the text next to the image and
assign some charactersitics to the blah blah text, do I do:

..info {
float:left;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
color: #000000;
word-spacing: normal;
line-height: 20pt;
font-weight: 700;
text-align:center;
padding:10
}
..info img {
float:left;
}

This seems to not show part of the image, but when I click on it, it
shows the whole image! Or, whe I keep adding new lines of "blah blah"
the image keeps showing more of the hidden part.

Dec 6 '05 #3
as*******@hotmail.com wrote:
I want to have an image (170x250) centered and have some text to the
right of it, starting from top of the image.
I have:

.info
{
position: absolute;
top:100px;
left:200px;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
line-height: 10pt;
Really bad idea. 100% is good but 100% might be 6pt ot might be 26pt
depending on the user's settings, so drop the fixed line-height toa
void problems.
padding:10
10 what?
}
.info img {
position:absolute;
top:0;
left:0;
width:170px;
align:center;
padding:10;
float:left;
}
float and position: absolute; can not be used together like that. See
the CSS spec for details.
and in html:
<div class="info">
<p><img ...> blah blah blah
</div>

But the text starts from the bottom of the image.

Where am I goofing up?


Assuming that your container is variable width (if it's fixed width the
whole things is even easier).

..info {
position: relative;
margin-top: 100px;
}

..info p {
margin-left: 50%;
padding: 1em 1em 1em 90px;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
color: #000000;
background-color: #FFFFFF;
}

..info img {
position: absolute;
left: 50%;
top: 1em;
margin-left: -85px;
border: 1px solid red;
}
<div class="info">
<img src="" alt="" width="170" height="250" />
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas. Fusce lacus. Suspendisse potenti. Pellentesque
mauris ligula, faucibus sit amet, sagittis quis, pellentesque at,
magna. Vivamus justo neque, vestibulum vitae, malesuada eget, pharetra
quis, lorem. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Quisque at urna id lectus suscipit malesuada. Nullam est. Donec a sem.
Aenean hendrerit, augue egestas hendrerit iaculis, augue metus dictum
enim, molestie tincidunt dolor magna non quam. Cras est. Proin
facilisis lacus vitae mi.</p>

Image is centered and text appears to the right of the image, and the
tops of both text and image are aligned.

Steve

Dec 6 '05 #4
as*******@hotmail.com wrote:
I want to have an image (170x250) centered and have some text to the
right of it, starting from top of the image.


http://homepage.ntlworld.ie/spartanicus/temp.htm

--
Spartanicus
Dec 6 '05 #5
as*******@hotmail.com wrote:
Thank you meltdown.
if I want to center both the image and the text next to the image and
assign some charactersitics to the blah blah text, do I do:

.info {
float:left; You want everything in the center, why float the .info container to
the left ? font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
color: #000000;
word-spacing: normal;
line-height: 20pt;
font-weight: 700;
text-align:center; This make the text centered on each line, and it won't do anything to
the image, since the image is floated. padding:10
}
.info img {
float:left;
}

This seems to not show part of the image, but when I click on it, it
shows the whole image! Or, whe I keep adding new lines of "blah blah"
the image keeps showing more of the hidden part.

If you want to center the content, give .info automatic margins.
Then .info will be centered. To limit info to a small area in the
center, give it a limited width:

.info {width:40%;margin:auto}

Here is an example:
http://www.reenie.org/test/test20.htm
Dec 6 '05 #6
Thanks a lot Steve.
I tried your code but:
- the image did not show at all. When I removed the "margin-left:-85px"
it showed up.
- The text shows at the bottom, with some distance between itself and
the image.
I used the sample from Spartanicus' page and it works, although the
text for some reason, starts a little lower than the top of the image
(unlike his sample page).

I sincerely appreciate your assistance and pointing my mistakes to me.

Dec 6 '05 #7
as*******@hotmail.com wrote:
Thanks a lot Steve.
I tried your code but:
What code? Please quote the parts of the message you are replying to.
- the image did not show at all.
In which browsers? And with which doctype? I tested in IE6, FireFox
1.0.7 and Opera 8.51 with a doctype that triggers standards mode.

It doesn't work in IE5.5 (image overlaps text slightly) but that could
be corrected by feeding IE<6 slightly differnt styles via conditional
comments or any one of a number of CSS hacks.

See http://steve.pugh.net/test/test100.html for my demo.
When I removed the "margin-left:-85px" it showed up.
But then it won't be centered.
- The text shows at the bottom, with some distance between itself and
the image.
If you've removed the margin from the image then there will be all
sorts of things different.
I used the sample from Spartanicus' page and it works, although the
text for some reason, starts a little lower than the top of the image
(unlike his sample page).


Spartanicus' solution is simpler than mine. Use it instead. Are you
using the same doctype he is? If not then doctype sniffing may explain
the vertical alignment differences.

Steve

Dec 7 '05 #8

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

Similar topics

2
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I...
8
by: Chris Beall | last post by:
I'm struggling with how to handle, on a web page, images that contain text that the user must be able to read. Examples: tombstone photos, photos or scans of historic documents (handwritten or...
2
by: UJ | last post by:
I have need to convert a text string (with formatting) to an image. This is so that I can resize the image to different sizes and the formatting stays exactly the same regardless of the size. I...
5
by: SeanT | last post by:
Greetings and salutations! I am having a real issue with the VB.NET TreeView control. I need to display an image (a.k.a. logo, picture, etc) from a file as the treenode object. I can not seem to...
4
by: Samuel R. Neff | last post by:
I have a set of radio buttons in a win form that each have an image and text, like so: O O O O How can I set it up so that the image is left aligned, next to the radio button...
8
by: DarkSaturn | last post by:
Is there a method of using the CSS float command on images to contain itself within a single paragraph? The problem I'm running into is trying to use float images on a listing page, I have an...
1
by: helraizer1 | last post by:
Hi all, I have a dynamic image that picks out data from a dynamically created .line file. showimage.php(5) <?php include("linesfile.php5"); $linesDataFile = new DataFile("data.line");
8
by: Jonathan Sachs | last post by:
I'm trying to compose a list of items, each of which consists of text that wraps around a picture at the left margin. The examples I have seen tell me to do it like this: <p><img src="xxxx.jpg"...
8
tharden3
by: tharden3 | last post by:
Hey Bytes, The website I'm working on is coming along just fine, and I'd like to thank all of you PHP folks who have been helping me out. I'm almost done with the coding! I'm trying to get the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.