0

I am very beginner at coding and most the answers I have come across have just gone straight over my head. The only code I have to make my slideshow work (which it is working) is:

<script type="text/javascript">
<!-->
var image1=new Image()
image1.src="congo.jpg"
var image2=new Image()
image2.src="snow.jpg"
var image3=new Image()
image3.src="mekong.jpg"
//-->
</script>

and in the body section:

<img src="congo.jpg" name="slide" width="400" height="300">
<script type="text/javascript">
<!--
var step=1
function slideit(){
document.images.slide.src=eval("image"+step+".src")
if(step<3)
step++
else
step=1
setTimeout("slideit()",2500)
}
slideit()
//-->
</script>

I have no clue how to center this or put in a margin. I tried placing it within a table so I could manipulate its location, which didn't work (assuming it's just not that easy), and tried messing around with a tag to center but I was just pulling at strings! What is the proper way to add margin/center? Thank you.

Jessica
  • 13
  • 2
  • 6

2 Answers2

3
/*css*/

.slideshowContainer {
position:relative;
width:400px;
height:300px;
margin:0 auto;
clear:both;
}



<!-- HTML -->


<div class="slideshowContainer">
<img src="congo.jpg" name="slide" width="400" height="300">
</div>

Always try to style your divs with css style sheets or in head of the page. Try to avoid styling inline like div style="". This is bad practice.

Charlie
  • 163
  • 8
0

You just need to put <div> around your slideshow and apply text-align:center to the div.

<div style="text-align:center;">
    <img src="congo.jpg" name="slide" width="400" height="300">
</div>

Quick and dirty example: https://jsfiddle.net/pbsz9spu/

PaddyMack
  • 73
  • 1
  • 6
  • That made so much sense. I think that crossed my mind but I didn't end up trying it before now. Worked like a charm! Thank you tons!!! – Jessica Apr 22 '15 at 18:00
  • You should also read the other answer here. Avoid inline styling. I only used it here as an example. Put styles in your css stylesheet if you have one. – PaddyMack Apr 22 '15 at 18:02