views:

64

answers:

3

I have a couple of div tags nested withing each other and a few span tags nested like below:-

<div id="leftcol">
<div id="tagcloud">
<span class="mytags"><a href="">tag1</a></span><span class="mytags"><a href="">tag2</a> and a few more spans of the same type
</div>
</div>

Now the issue is that spans overflow their container div tag.Can somebody be kind enough to let me know how to get these spans to be wrapped inside their conatiner div (here the div with the id tagcloud).both the outer divs have a width of 300px specified.

(Additional info- I have done a css reset using the YUI reset-fonts-grids. I am just getting acustomed to CSS .. ) Edit:-The site can be looked at frekshrek.appspot.com ... the tag cloud just does not wrap inside its container div

A: 

It sounds like you are floating the spans inside the div container. If this is the case, and you want the 'tagcloud' to contain (wrap) the floated spans then you need to clear the floats by adding the following to the tagcloud CSS:

div.tagcloud {
    overflow: auto;
    width: 100%;
}

An explanation of this technique can can be found here: http://www.quirksmode.org/css/clearing.html

Simon Dyson
No I am not floating the spans inside at all. The only css that applies there sets the width of the outer two divs and the font of the span tags. That is It. While the above solution helps to fit the span inside the div, it induces a scroll bar at the bottom. It does not wrap the span from one line to the other below when the width is about to be exceeded
rubicondude
A: 

You have no spaces between your spans, so the browser sees them all as one single long word. If you add a single space or a line break between each span they will be treated as separate words and wrapped accordingly.

Simon Dyson
You can always edit your first answer and either add the update or replace the initial one completely. Helps keeping the answer section clean ;)
FreekOne
Would there be any other way as I am generating the span tags dynamically through a for loop ,on the server , enclosing them in a div and sending it . Cant figure out a way of adding spaces between them
rubicondude
In your for loop you could try adding ' ' immediately after the closing span tag. This is the html entity for a non-breaking space. So for example, the server should return something like: <span>...</span> <span>...</span>
Simon Dyson
Wouldn't it be much simpler to just add one line in the CSS file ?
FreekOne
I wont be able to do that Simon , as I am using some sort of html helpers there. Whatever I would have to do, would have to be in the CSS file.What Line are you talking of FreekOne. Would be really helpful, if something that like worked out!
rubicondude
A: 

Try declaring float: left; on the .mytagcloud class. Something like:

.mytagcloud{
    float: left;
    margin: 5px;
    font-family: 'Reenie Beanie', arial, serif;
}

in your basiclayout.css file, line 71.

FreekOne
You are GOD! :-).. Thanks
rubicondude
Glad to be of help :)
FreekOne
@rubic @Freek - you shouldn't use `margin: 5px;` on any floated element. In IE6, double float margin bug takes effect. I would stick with `padding: 5px;`, or `margin: 5px 5px 5px 0;`.
orokusaki
@orokusaki: the `margin` property was already in @rubicondude's CSS file, but thanks for the heads up. On the same note, are we seriously *still* supposed to be supporting IE6 ?
FreekOne