Undesired Behavior: <span>(Solved)

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Undesired Behavior: <span>(Solved)

Post 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.
Last edited by raghavan20 on Wed Aug 10, 2005 8:08 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yeah, from what I remember, spans and divs share all the attributes to manipulate, just a differing default set of them.
Post Reply