Solved

Fixed Width

Posted on 2012-03-25
6
141 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

739 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