Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Fixed Width

Posted on 2012-03-25
6
Medium Priority
?
146 Views
Last Modified: 2012-03-29
I have a page using CSS with a state code on the left:

AL Dothan Computer & Technology Group http://dctug.apcug.org/

AZ Colorado River Computer Club  http://www.crccaz.com/
AZ Payson Area Computer Association http://www.pacaonline.org/

CA Computer User’s Group of Redding http://cugr.apcug.org/
CA Greater South Bay User Group  http://gsbug.apcug.org/

Because it is a proportional font the name (after the State Code) will not be perfectly lined up. I could do this easily with tables, but how can I do it without tables

i.e. how can I set <span class="state">AL</span> the css code for "state" so that it is a certain specific width, but I guess it should be measured in "em"s since if the font size is changed, it should be wider.
0
Comment
Question by:singleton
  • 3
  • 2
6 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37763877
<span> is an 'inline' element and unless you change it to 'block', it takes the size of it's content.  But because your example is a case of "tabular data", I would just use a table.  Or you could used floated divs with different classes.  You need to clear or break the right div.
0
 
LVL 11

Author Comment

by:singleton
ID: 37764018
what would an inline block be?

and I thought a div would start on next line
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37764357
A 'div' without any styling will take up the entire horizontal space where it is.  But if you give it a 'width' and 'float' it in CSS, you can put them side by side.  Here is a simple demo of that idea.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<head> 
<style type="text/css">
<!-- 
body { background-image: url("bkgrnd.jpg");background-color: #ffffff; }
#wrap {margin-left: auto;margin-right: auto;width:80%;background-image: url("content.jpg");background-color: #ffeeee;} 
#header {background-image: url("header.jpg");background-color: #eeeeff;} 
#sidebar {float:left;width:20%;background-color: #eeffee;} 
#content {float:left;width:60%;background-color: #f7f7f7;} 
#sidebar-2 {float:left;width:20%;background-color: #eeffee;} 
#footer {clear:both;background-color: #ddeeee;} 
--> 
</style> 
</head> 
<body> 
<!--start of wrap-->
<div id="wrap">

<div id="header">Header</div>

<div id="sidebar">Sidebar</div>

<div id="content">Content<br />
and More<br />
Content</div>

<div id="sidebar-2">Sidebar-2</div>

<div id="footer">Footer</div>
</div>
<!--end of wrap-->

</body>
</html>

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Author Comment

by:singleton
ID: 37765234
But there the width is % of screen width. Can the width be a function of font size, which I think is what em means.  Basically I have a two character field, which might contain something narrow like II but could be something wide like WW. (I realize neither is a state code, but you see what I mean. I would like to specify something like 3em, which I think would give me enough room for MM or WW, plus have enough space for another M. If the font size is 10pt that would be enough size for 10pt MM or WW, but if font size is 30pt, it becomes larger, enough for 30pt MM or WW.
0
 
LVL 22

Accepted Solution

by:
Kim Walker earned 2000 total points
ID: 37766430
You could also use p (paragraph) tags wrapped in divs:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Untitled Document</title>
		<style type="text/css">
		p { margin: 6px 0 6px 2em; }
		p.stateabbr { width: 2em; margin: 0; float: left; }
		div.extraspace { margin-top: 24px; }
		</style>
	</head>
	<body>
		<div>
			<div><p class="stateabbr">AL</p><p>Dothan Computer & Technology Group http://dctug.apcug.org/</p></div>
			<div class="extraspace"><p class="stateabbr">AZ</p><p>Colorado River Computer Club  http://www.crccaz.com/</p></div>
			<div><p class="stateabbr">AZ</p><p>Payson Area Computer Association http://www.pacaonline.org/</p></div>
			<div class="extraspace"><p class="stateabbr">CA</p><p>Computer User’s Group of Redding http://cugr.apcug.org/</p></div>
			<div><p class="stateabbr">CA</p><p>Greater South Bay User Group  http://gsbug.apcug.org/</p></div>
		</div>
	</body>
</html>

Open in new window

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37766916
singleton, I posted the code so you would have something to work with.  Download it and try the different things you think of.  I was just showing the technique.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Suggested Courses

877 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