Link to home
Start Free TrialLog in
Avatar of HeadAcheMike
HeadAcheMike

asked on

div and number on same line

Simple one i think but i dont know how to fix it.

I have a div, for example:

<div style="background: #0000FF; width: 13px; height: 15px;">&nbsp;</div>13<br>

and the number displays on the line below it, but i want it to display next to it

how do i make it do that?

Thank you
Avatar of hongjun
hongjun
Flag of Singapore image

try this

<div style="background: #0000FF; width: 13px; height: 15px;position:absolute">&nbsp;</div><span style="position:relative;left:12px;top:0px">13</span><br>


hongjun
Avatar of webwoman
webwoman

What EXACTLY are you trying to do, and why do you have an empty div? I suspect this is really convoluted and you want to do something simple, like put a block of color next to the number -- and there are lots of other, easier ways to do that.
tables can also solve it
Avatar of knightEknight
another way ... use span instead of div
Avatar of HeadAcheMike

ASKER

webwoman, its for a poll display, i was thinking have a div to represent the bar then display the percentage it represents next to it.

How would you recommend doing it if not that way? should i go with span as others have suggested?

I don't really want to use tables and i was hoping to avoid positioning with absolute or relative... if thats the only way then ok but i don't know so much about how positioning works this way, the pro's and con's of each etc so didn't really want to step onto unknown territory.

Thank you for the advice so far
Well if you don't want to add a tag around the 13 just float the div:

<div style="background: #0000FF; width: 13px; height: 15px;float:left">&nbsp;</div>13<br>

Cd&
Why not do this?

You may want to make sure that the div is wide enough to put behind the number...


<%  if  percent < 15 then %>
     <div style="background: #0000FF; width: 13px; height: 15px;float:left">&nbsp;</div><%=percent%>

<% else %>
     <!--- put the number on the div --->
     <div style="background: #0000FF; width: 13px; height: 15px;"><%=percent%></div>

<% end if %>
Why not use an image? A 1x1 block of color can easily be sized to whatever you need, and set to float. SEt up a class that floats whatever side you want.
.divleft {float:left; }

<div class="divleft"><img src="colorblock.gif" width="13" height="15"></div>13

The added advantage is that you can use that class on other things as well.
ASKER CERTIFIED SOLUTION
Avatar of seanpowell
seanpowell
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Apologies for delay in getting back to you.

COBOLdinosaur, the Float came close to it but caused problems when i had multiple div's and i couldn't quite figure out a solution with that one so i had to abandon that idea.

a1programmer, sorry thats not quite what im looking for, thanks anyway.

webwoman, an image would be an option but i was hoping to keep the whole "system" within one file without any additional content for convienience. Thank you for the suggestion nonetheless.

Sean, Thank you, that is a perfect example and subsequently i will be accepting your answer.

I appreciate that others suggested similar methods prior to this but i couldn't figure out how to get it to render correctly, Seans example without the need for positioning was just great.
Thanks HeadacheMike, I'm happpy it worked out for you, and thanks for the A :-)

Sean