gpt4 book ai didi

jquery - 如何使用 CSS 将我的 div 在表格中居中?

转载 作者:太空狗 更新时间:2023-10-29 15:22:18 26 4
gpt4 key购买 nike

我正在尝试向我的网站之一添加幻灯片。整个页面布局在一个 HTML 表格中(我非常讨厌并且没有选择)。我想将我的幻灯片放映集中在那个特定的列中。这是我的 CSS 的样子:

#slideshow {
position:relative;
}

#slideshow IMG {
position:absolute;
z-index:8;
opacity:0.0;
}

#slideshow IMG.active {
z-index:10;
opacity:1.0;
}

#slideshow IMG.last-active {
z-index:9;
}

这是我用来更改图像的 JQuery 函数:

function slideSwitch() {
var $active = $('#slideshow IMG.active');

if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

// use this to pull the images in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');

$active.addClass('last-active');

$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}

$(function() {
setInterval( "slideSwitch()", 5000 );
});

最后是表格内的幻灯片 div:

<td bgcolor="red" align="center" valign="top"> 
<div id="slideshow">
<img src="2009Slideshow\1.jpg" alt="Slideshow Image 1" class="active" />
<img src="2009Slideshow\2.jpg" alt="Slideshow Image 2" />
<img src="2009Slideshow\3.jpg" alt="Slideshow Image 3" />
etc...
etc...
</div>
</td>

那么为什么我不能让我的幻灯片放映在该列的中心?

最佳答案

通过使用 css 属性“text-align:center;”,内联元素可以很容易地居中。 block 元素应使用“margin-left:auto;margin-right:auto;”居中对齐。并给它们一个固定的宽度。在您的特定情况下,我建议使用 span 而不是“div”或完全摆脱 div 并使用 text-align 方法。

更新

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Centering</title>
<style type="text/css">
table{
border:1px solid black;
}
span{
background-color:red;
color:white;
}
td{
text-align:center;
width:200px;
}
</style>
</head>
<body>
<div class="item" id="item1">
<table>
<tr>
<td>
<span>Hi there!</span>
</td>
</tr>
</table>
</div>
</body>
</html>

关于jquery - 如何使用 CSS 将我的 div 在表格中居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1042209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com