CSS div length is too big
How can I make a CSS div which width is as tall as the text it contains? I tried
div.reqspace {
float : left;
width : 10px;
}
but found that there is no length attribute. Now my div is almost as wide as the screen is.
<?php include("sitestartend.php");
site_start('xyz);?>
<?php include("helpfun.php");
$addr = getRealIpAddr();
if ($addr != '$myaddr') {
echo '<p>Sivusto on kehitteillä.</p></body></html>';
die();
}
include("navbar.php"); ?>
navbar ladattu!
<div id="reqspace">
Sähköpostiosoite: <br/>
Valitse salasanasi: <br/>
</div>
<input type="text" name="email" value="" />
<input type="text" name="email" value="" />
<input type="password" name="password" value="" />
<input type="submit"/>
</body>
</html>
sitestartend.php
<?php
function site_start($name) {
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>';
echo ' <title>'.$name.'</title>';
echo ' <link type="text/css" rel="stylesheet" href="styles.css" />';
echo '</head>';
echo '<body>';
}
function site_end() {
echo '</body>\n</html>';
}
helpfun.php
<?php
function getRealIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
开发者_如何学JAVA{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>
You can set a height
value, in px. Also, in a floated div, it's often helpful to use something like this:
<div class="reqspace">My content
<div style="clear: both;"></div>
</div>
That "clear" div, while empty, will help the browser understand where the bottom of the div is. It's not the cleanest HTML ever, but it gets the job done.
Perhaps you're looking for the height attribute? Although you are setting things in terms of pixels so it'll really only be as wide and tall as the text as long as it doesn't exceed that. Might try a fluid measurement like em.
you must do that:
div.reqspace {
position : relative;
width : auto;
display : table;
}
for example, if you have a list with x number of child li, in this way you list li will be with dynamic width on each child.
精彩评论