0

我已经找到了一个类似的问题,但没有点击。

这是我的代码,我想要两个背景。我知道如何添加两个背景,但一个背景图像需要在一个特定的位置,通过使用 div 来完成。我的代码可能有最简单的缺陷。请注意,我是一个新手,并试图从我已经知道的少量知识再次进入 Web 开发。

<head>
<style type="text/css">
        body {
            <div id="currentpage">
                background-image: url(bgsource/contactpage.png);
                background-repeat: no-repeat;
            </div>
        }
        #currentpage{
            position: absolute;
            width:auto;
            height:auto;
            left:424px;
            top:134px;
            margin-left:0px;
            margin-top:0px; 
        }
</style>
<?php include_once("general.php"); ?>
</head>

我可能想包括我有一个加载到每个页面的 general.php 模板,这是否也会影响背景工作?

4

4 回答 4

1

您的 html 和 css 不正确。请参阅下面的更正

<style type="text/css">

        #currentpage{
            position: absolute;
            width:auto;
            height:auto;
            left:424px;
            top:134px;
            margin-left:0px;
            margin-top:0px;
    background-image: url(bgsource/contactpage.png);
    background-repeat: no-repeat;
                    }
</style>

和 html 这样做

<div id="currentpage"></div>
于 2012-07-19T04:14:59.040 回答
1

像这样更改您的代码。因为您不能像您在问题中提到的那样在 css 中应用 html 标记。

 <head>
    <style type="text/css">
    #currentpage{
          position: absolute;
          width:auto; /* specify width */
          height:auto; /* specify height */
          left:424px;
          top:134px;
          margin-left:0px;
          margin-top:0px;
          background-image: url(bgsource/contactpage.png);
          background-repeat: no-repeat;
    }
    </style>
    </head>
    <body>
       <div id="currentpage"></div>
    </body>

并指定widthheight用于div显示图像。否则你将有一个白色的背景。

于 2012-07-19T04:19:19.023 回答
1
       **change your css and html**

         <head>

           <style type="text/css">
        #currentpage{
            position: absolute;
            width:xx;
            height:xx;
            left:424px;
            top:134px;
            margin-left:0px;
            margin-top:0px; 
            background-image: url(bgsource/contactpage.png);
            background-repeat: no-repeat;
                    }
</style>


</head>
    <body>
   <div id="currentpage"></div>
    </body>
于 2012-07-19T04:20:13.860 回答
0

是的。你不能在你的 css 页面或 css 脚本中使用 div 标签。

        background-image: url(bgsource/contactpage.png);
        background-repeat: no-repeat;
        position: absolute;
        width:auto;
        height:auto;
        left:424px;
        top:134px;
        margin-left:0px;
        margin-top:0px; 

仅在您的 css 页面或脚本标签中使用上述代码,但在 css 中不允许使用 div 标签

于 2012-07-19T04:25:54.960 回答