Solved

Fixed Width

Posted on 2012-03-25
6
140 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 83

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 83

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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 500 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 83

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
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!
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 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