dongzhan1948 2017-04-07 16:02
浏览 43

css表不影响php echo

I am using PHP to check a form. If the content is not filled in the PHP will echo an error message. I want that text to be effected by my style sheet. It is not. The CSS effects the rest of the page, just not that error text. I tried adding the span and class in with the echo and I tried adding the span and class to the html and just echo the text. No effect.

the HTML

<meta charset="utf-8">
<link rel="stylesheet" href="run.css" type="text/css">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">

the PHP

<span class="errormsg2">
 <?php
    if(isset($notset)){
        echo $notset;
    }
?>
</span>

and the CSS

.pushme:hover{
    background-color: #eb5300;
    color: black;
    text-shadow: none;
}

.errormsg2{
    text-align: center;
    color: red;
    font-weight: bold;
}

The PHP example I provided was from my attempt to put the span and class into the HTML and just echo out the text content.

  • 写回答

1条回答 默认 最新

  • dongying6659 2017-04-07 17:17
    关注

    I believe that the problem is that your file extension should be filename.php instead of filename.html and because php is a server side language you will have to run your code in a localhost mode to see the change. if you try to run php code in a filename.html the browser will comment your your php code.

    // filename.php file, this will work for you
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
        <style>
            .errormsg2{
                text-align: center;
                color: red;
                font-weight: bold;
            }
        </style>
    </head>
    <body>
        <span class="errormsg2">
            <?php
                $notset = "test";
                if(isset($notset)){
                    echo $notset;
                }
            ?>
        </span>
    </body>
    </html>

    </div>
    
    评论

报告相同问题?