PDA

View Full Version : CSS div widths ???? HELP ????


Andy92
03-17-2006, 11:31 PM
Hi there,

I am making a .css style sheet for all my pages on my site to refer to, but...

Instead of setting a <div> tag a specific width like...

#body_stuff .page_title_text{
width: 50px;
padding-left: 4px;
padding-right: 4px;
}

Is there a way to set the width to expand to however much text you write in the div tag?

Like if you write...

Hello


Then the div tag will be the width of the words you write in there? (Including the padding on the right and left).

Is there a way to do this so the div tag has the width of the words you write in there?

Help please!!:)

_Aerospace_Eng_
03-17-2006, 11:34 PM
Look into table-cell and inline-block displays.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
html, body {
margin:0;
padding:0;
border:0;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:0.9em;
}
#container {
width:400px;
height:400px;
margin:20px auto;
position:relative;
}
#blocky {
display:inline-block;
background:#FF0000;
border:1px solid #000;
padding:2px;
}
</style>

</head>

<body>
<div id="container">
<span id="blocky">This is text</span>
This is content with a semi transparent image on top.
</div>
</body>
</html>
This allows you to add borders and what not. IE will let you add a width but other browsers won't.

Andy92
03-18-2006, 03:19 PM
Thank you soo much! It worked! Thanks! :) :thumbsup: