2017-04-07 69 views
-1

我正在使用PHP來檢查表單。如果內容未填入PHP,則會回顯錯誤消息。我想讓我的樣式表受到文本的影響。不是這樣。 CSS影響頁面的其餘部分,只是沒有那個錯誤文本。我嘗試在echo中添加span和class,並嘗試將span和class添加到html中,然後僅回顯文本。沒有效果。css工作表不影響php echo

的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"> 

的PHP

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

和CSS

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

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

我提供的PHP的例子是從我試圖把跨度和類到HTML只是迴應文字內容。

+1

是否'$ notset'包含HTML? – Musa

+0

$ notset包含什麼?並且你是否嘗試<?php if(isset($ notset)){echo「> $ notset「; }?> – OldPadawan

+0

或者是您的抱怨,而不是橫向居中? –

回答

0

我相信問題是您的文件擴展名應該是filename.php而不是filename.html ,並且由於php是服務器端語言,您將不得不在本地主機模式下運行您的代碼以查看更改。 如果您嘗試在文件名.html中運行php代碼,瀏覽器將評論您的php代碼。

// 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>

+0

OP從來沒有提到PHP不工作... –

+0

他提到CSS影響頁面的其餘部分,只是沒有錯誤文本... PHP代碼本身很好,CSS也很好。問題是文件擴展名 –