3

I'm currently working on a website written in HTML (and CSS of course) I have one JavaScript in it... just a little slideshow.

There's an anchor tag with an image in it before the script and after the script there's also a anchor tag with an image in it.

...
<a href="... .html">
    <img class="img" src="... .png" title="..."></a>
<script type="text/javascript">
    <!-- the script text -->
</script>
&nbsp;&nbsp;&nbsp;
<a href="... .html">
    <img class="img" src="... .png" title="..."></a>
...

My problem is the line break before and after the script tag. I want it to be

image    slideshow(script)    image

All used images (including the slideshow content) have the same height.

I've tried display: inline; and white-space: nowrap; (and every other white-space thing) I've put it both directly into the in the html file (style="display:inline;" or style="white-space:nowrap;" and into the css file (script { display: inline; } and script { white-space: nowrap; })

 

Does anybody know how to prevent the line breaks before and after the script tag??

8
  • 3
    The script tag should not be in your HTML body to begin with. Commented Dec 5, 2012 at 19:02
  • You could try script{display:none} but that should be the default anyways. Commented Dec 5, 2012 at 19:06
  • 2
    also note that &nbsp; is not a good substitute for real margins. Commented Dec 5, 2012 at 19:06
  • Any chance you could have accidentally set display:block to one of the a's or imgs? Commented Dec 5, 2012 at 19:08
  • 2
    It not the script tag causing the line break, it's the script. If you replace your script with something like 'var x = 0;' you'll see there is no break. But also what Diodeus said. Commented Dec 5, 2012 at 19:09

2 Answers 2

2

I would recommend putting each of these elements in a separate div, giving them a fixed width, then floating them accordingly (be sure to clear your floats if you do this).

ie

<div id="leftImg" style="width:220px; float:left;">
<img src="..." />
</div>

<div id="slideShow" style="width:220px; float:left;">
<script>your script here</script>
</div>

<div id="rightImg" style="width:220px; float:left;">
<img src="..." />
</div>

<div style="clear:left;"></div>

Edit: There is nothing wrong with a slideshow script being in the body of your page. If it were a script that posted information then server side validation would have to be done for security purposes, but there is nothing wrong with how you're doing it.

Sign up to request clarification or add additional context in comments.

Comments

1

Place the script inside a hidden div.

<div style="display:none"><script>...</script></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.