Html 使用css对中div
这是我的css文件中的片段Html 使用css对中div,html,css,alignment,Html,Css,Alignment,这是我的css文件中的片段 #centered{ position: relative; text-align: center; width: 50%; margin-left: auto; margin-right: auto; } #table{ text-align: center; font-size: 1.5em; font-weight: 900; background-color: #5E9DC8; }
#centered{
position: relative;
text-align: center;
width: 50%;
margin-left: auto;
margin-right: auto;
}
#table{
text-align: center;
font-size: 1.5em;
font-weight: 900;
background-color: #5E9DC8;
}
这是我尝试使用的html部分:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Bicycle Store Database</title>
<link rel="stylesheet" type="text/css" href="web.css" />
</head>
<body>
<h1>ACME BICYCLE SHOP</h1>
<h2>GET IN GEAR!</h2>
<div id="centered">
<table id="table" border="0" cellpadding="10">
<tr>
<td><a href="search_inv.php" class="navTest">Go Shopping!</a><br/><br/>
<a href="search_service.html" class="navTest">Check a Service Ticket</a></td>
</tr>
</table>
</div>
<p><br/><a href="index.html">HOME</a></p>
</body>
</html>
自行车商店数据库
ACME自行车店
准备好!
结果是:
我读到的所有内容都表明我做得很正确,但在我所有的浏览器中都偏离了中心。有什么想法吗?为什么要用这个表?有什么具体原因吗?你就不能这样做吗
<div class="center">
<a href="#">Go Shopping</a>
<br>
<a href="#"></a>
</div>
.center {
margin: auto;
/* Other styles goes here, width height background etc */
}
.中心{
保证金:自动;
/*其他样式在这里,宽度高度背景等*/
}
为什么要使用表来进行此操作?有什么具体原因吗?你就不能这样做吗
<div class="center">
<a href="#">Go Shopping</a>
<br>
<a href="#"></a>
</div>
.center {
margin: auto;
/* Other styles goes here, width height background etc */
}
.中心{
保证金:自动;
/*其他样式在这里,宽度高度背景等*/
}
div位于页面中央
表格在div中左对齐
添加
表格{margin left:auto;margin right:auto;}
以使表格在div中居中。div在页面中居中
表格在div中左对齐
添加表格{margin left:auto;margin right:auto;}
以使表格在div中居中。您将居中#居中
,但不居中表格。
添加页边距:0自动代码>到#表格
您正在居中#居中
,但不是其中的表格。
添加页边距:0自动
到#table
如果没有任何表格数据,则不应使用table元素。使用table
来设置页面样式被认为是一种不好的做法;当需要显示表格数据时使用它。那里没有任何表格数据,不应该使用表格元素。使用表格
设置页面样式被认为是一种不好的做法;当需要显示表数据时使用它。谢谢大家,这是一种总结。我摆脱了表格,修复了css,所有的东西都被拨号了。谢谢大家,这是一种总结。我摆脱了表格,修复了css,一切都已拨号。