Solved

Fixed Width

Posted on 2012-03-25
6
137 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 82

Expert Comment

by:Dave Baldwin
Comment Utility
<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
Comment Utility
what would an inline block be?

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

Expert Comment

by:Dave Baldwin
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Author Comment

by:singleton
Comment Utility
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 21

Accepted Solution

by:
Kim Walker earned 500 total points
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

763 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

7 Experts available now in Live!

Get 1:1 Help Now