Solved

div and number on same line

Posted on 2004-10-05
11
1,718 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:HeadAcheMike
  • 2
  • 2
  • 2
  • +4
11 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 12227711
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
0
 
LVL 19

Expert Comment

by:webwoman
ID: 12227752
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.
0
 
LVL 33

Expert Comment

by:hongjun
ID: 12227756
tables can also solve it
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 12227853
another way ... use span instead of div
0
 
LVL 2

Author Comment

by:HeadAcheMike
ID: 12227965
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12228848
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&
0
 
LVL 7

Expert Comment

by:a1programmer
ID: 12230175
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 %>
0
 
LVL 19

Expert Comment

by:webwoman
ID: 12233881
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.
0
 
LVL 31

Accepted Solution

by:
seanpowell earned 100 total points
ID: 12238857
My preference would be a simple CSS styling, although I generally stay away from floating content or absolute positioning unless I need to - it can cause problems with external content.

Probably something like this would be how I'd end up:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<style type="text/css">

div
{
      background: #0000FF;
      text-align:right;
      height:16px;
      margin:4px 0;
}

span
{
      background-color:#ffffff;
      padding-left:4px;
      font-size:16px;
}

</style>
</head>
<body>

<div style="width:60px"><span>30%</span></div>
<div style="width:90px"><span>60%</span></div>
<div style="width:40px"><span>10%</span></div>

</body>
</html>

Sean
0
 
LVL 2

Author Comment

by:HeadAcheMike
ID: 12268313
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.
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 12269421
Thanks HeadacheMike, I'm happpy it worked out for you, and thanks for the A :-)

Sean
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now