Page 1 of 1

Undesired Behavior: <span>(Solved)

Posted: Wed Aug 10, 2005 5:12 am
by raghavan20
I have always had this problem making a css class work with a span

for example:
.cAlign{
text-align:center;
}

<span class = 'cAlign'>HTML: Chat name has already been taken; choose another name</span>

But this doesnot work in the code while a div works properly for the same css class in the same file.

Suggestions are welcome.

Posted: Wed Aug 10, 2005 7:56 am
by feyd
a span is, unless otherwise defined, always the same dimensions as the content it holds. So trying to center in a span will do nothing unless you set it's dimensions larger than its content. A div on the otherhand is, unless otherwise defined, the size of its container thereby often being larger than its content and doing the alignment.

Divs are also block level, versus spans which are inline elements. All these attributes can be fiddled with in CSS, of course.

Posted: Wed Aug 10, 2005 8:07 am
by raghavan20
thanks for your answer.
I was trying with other code.

Code: Select all

<html>
<head>
<style type="text/css">
<!--
.cAlign {
	text-align:center;
	color:#CC3300;
	background-color:#0000CC;
	font-size:1.4em;
	width:30%;
	height:40;
	float:left;
	margin:5px;
}
-->
</style>
</head>
<body>
	<span class="cAlign" style="">hi all</span>
	<span class="cAlign" style="">hi everyone</span>
</body>
</html>
Now I have found the code for the span to work like div. Also works with float property.

Posted: Wed Aug 10, 2005 8:10 am
by feyd
yeah, from what I remember, spans and divs share all the attributes to manipulate, just a differing default set of them.