Solved

Fixed Width

Posted on 2012-03-25
6
142 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
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…
Suggested Courses

632 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