如何在 HTML 中将幻灯片移动到页面中心
How to move slideshow to the center of page in HTML
<html>
<head>
<meta charset = "utf-8/">
<title> My Student Life </title>
<link rel="stylesheet" href="Pan.css"/> <!--Links to the CSS -->
<script type = "text/javascript"> // JavaScript code
var slideimages = new Array() //SlideShow process begins
imgAlign = "center"
slideimages[0] = new Image() // create new instance of image object
slideimages[0].src = "Welcome.jpg" // set image src property to
slideimages[1] = new Image()
slideimages[1].src = "Code.jpg" //Image source
slideimages[2] = new Image()
slideimages[2].src = "books.jpg"
</script>
</head>
<body class ="Container" Background = "Background.jpg"> <!-- Background Images-->
<div class="headerMenu"> <!-- Div class for menus -->
<h1> My Student Life </h1>
<div id="menu"> <!-- created Menus-->
<ul>
<a href="WelcomePage.html"/> Welcome </a>
<a href=""/></a> <!--Menu links-->
<a href="Menu.html"/> Menu </a>
<a href=""/> </a>
</ul>
</div>
<header>
<h2 color = "white"> Welcome to my Student Life </h2>
</header>
<img src = "Welcome.jpg" width = "500" height ="300" id = "slide" > <!--Image -->
<script type="text/javascript">
var step=0 //starts
function slideit(){ //function called slideit
if (!document.images)
return
document.getElementById('slide').src = slideimages[step].src //Gets image by ID and follows the sliding process
if (step<2)
step++
else
step=0
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",2500)
}
slideit() //Enable the function to perform
</script>
</body>
</html>
我正在为我的一门大学课程创建一个项目,我使用 JS 创建了一个幻灯片,它完美运行,唯一的问题是图像的位置一直到屏幕左侧。我尝试在 css 中向左填充,但仍然不起作用,我在div 类中创建了它,并在 CSS 中调用了该类,但仍然没有结果。对不起我的英语。
在 Pan 中添加以下内容.css :
.Container{
text-align: center;
}
对于您的问题 2,只需在图像中添加右边距,值取决于您:
img{
margin-right: 50px
}
尝试将以下样式添加到您的 img 标签中:
<img src = "Welcome.jpg" width = "500" height ="300" id = "slide" style="margin: auto;" >
相关文章:
- 当#在iFrame中使用HTML时,阻止页面移动
- 移动HTML输入文本框在提交时隐藏软键盘
- 使用jquery为移动布局更改html层次结构
- 移动html/javascript编程中的变量传递
- html视频javascript播放方法在移动Safari中不起作用
- 录制/跟踪html滑块控制移动
- 当我移动引用three.js的html文件时,three.js停止工作
- 根据 URL 中的哈希移动 HTML
- HTML 不加载 CSS ,刷新后一切正常.同样在移动设备上,它在首次加载时不起作用
- 如何在 HTML 中将幻灯片移动到页面中心
- 移动HTML:触摸结束后继续滚动
- 可以使用jQuery'移动HTML背景吗;s设置动画
- 如何在不移动 html 中周围元素的情况下扩展图像
- 从移动 HTML 主体在方向更改时调用 Javascript 函数
- 使用 JavaScript 移动 html td 元素
- 有条件地移动html元素
- 在页面之间移动html
- DOM -如何移动HTML元素
- 移动html &点击img时,主体从上到上
- 在移动设备上使用javascript移动html的性能问题