mrgerbik2013
mrgerbik2013

Reputation: 97

How to prevent line break before and after <script> tag (JavaScript) in HTML?

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??

Upvotes: 3

Views: 2502

Answers (2)

Andres
Andres

Reputation: 11

Place the script inside a hidden div.

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

Upvotes: 1

Brandon Clapp
Brandon Clapp

Reputation: 70473

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.

Upvotes: 2

Related Questions