使用css无法正常工作的图像居中

时间:2014-09-06 20:19:32

标签: html css image centering

我刚刚开始参加一个大约4周前的网页设计课程,我对它非常感兴趣。如果有人能像我一样帮助新手,我会非常感激。

我不太确定这里的问题是什么。代码工作在我的一个单独的文件,但什么时候 我试图开始一个新项目,它不再适用了。 :/

这是我的HTML:

<!DOCTYPE html>
<html>
<head>
<title>Good Boy</title>
<link rel="stylesheet" type="text/css" href="goodboyslove.css">
<link rel="shortcut icon" href="images/GBFavicon.ico">
</head>

<body>
<a href="http://www.oriko-san.tumblr.com/"><img id="gblogo" class="center" src="images/GB.png" alt="good boy logo" width="128" height="128">

这是我的CSS:

<!DOCTYPE css>

.center {
display: block;
margin-left: auto;
margin-right: auto; }

#gblogo{position:relative;top:32px;}

2 个答案:

答案 0 :(得分:4)

doctype是一种文档类型声明,在CSS文档中无效。删除它将解决问题。 CSS属于MIME类型,您使用链接标记的type="text/css"声明该类型。

Here是关于HTML的简介文章,其中包含使用doctype

的部分内容

答案 1 :(得分:0)

试试吧! (我不保证

您的HTML文件:

<!DOCTYPE html>
<html>
<head>
<title>Good Boy</title>
<link rel="stylesheet" type="text/css" href="goodboyslove.css">
<link rel="shortcut icon" href="images/GBFavicon.ico">
</head>

<body>
<a href="http://www.oriko-san.tumblr.com/"><img id="gblogo" class="center" src="images/GB.png" alt="good boy logo" width="128" height="128" /></a>
</body>

您的CSS文件:

.center {
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
}