0

我正在为 WordPress 网站创建页面模板。

在文件 newpagetemplate.php 我目前有这个代码,只有这个代码:

 <!DOCTYPE html>
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Copywriting for Serious Marketers</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="keywords" content="copywriting, sales writing, marketing" />
 <meta name="copyright" content="Copyright Richard Clunan. All rights reserved." />
 <meta name="description" content="Advice on copywriting and marketing." />
 <meta name="revisit-after" content="7 days" />
 <?php
 /*
 Template Name: Salespage
 */
 ?>
    <div>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <?php the_title(); ?>
            <?php the_content(); ?> 
        <?php endwhile; endif; ?>
    </div>
 </head>
 <body>
 <body topmargin="100">
 <body leftmargin="300">
 <body rightmargin="300">
 <body bottommargin="10">
 </body>
 </html>

如果我的理解是正确的,我用来设置边距的值是 html 代码。

而且,如果我的理解是正确的,我可以使用 CSS 代码。这一点,我认为:

body {
        margin-top: 100px;
        margin-right: 300px;
        margin-bottom: 10px;
        margin-left: 300px;
    }

如果我只是切换这些代码摘录,新版本不会应用边距。

我需要做什么才能使 CSS 代码正常工作?

一种或其他类型的代码是否可能在不同情况下导致更少的问题,例如在不同的浏览器上显示?

4

1 回答 1

0

您的标记有点超出有效性范围。:) 带有 PHP 循环的 div 应该在 vody 中,并且应该只有一个 body 标签。我建议给你的循环 div 一个 id,然后将其用作 CSS 选择器,如下所示:

 <?php
/*
 Template Name: Salespage
 */
?>
<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Copywriting for Serious Marketers</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="copywriting, sales writing, marketing" />
<meta name="copyright" content="Copyright Richard Clunan. All rights reserved." />
<meta name="description" content="Advice on copywriting and marketing." />
<meta name="revisit-after" content="7 days" />
<style>
#content
 {
    margin: 100px 300px 10px;
 }
</style>

</head>
<body>
<div id="content">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php the_title(); ?>
        <?php the_content(); ?>
    <?php endwhile; endif; ?>
    </div>
</body>
</html>
于 2012-07-31T15:06:46.730 回答