简体   繁体   English

如何将 CSS 样式放入 php 代码中?

[英]How to put CSS style inside a php code?

I want to edit the input boxes of table ie the fields where user inputs username and password in a table.我想编辑表格的输入框,即用户在表格中输入用户名和密码的字段。 I have created this table inside php code.我在 php 代码中创建了这个表。

Now I want to make the input field texts in different color and only in small letters not caps.现在我想用不同的颜色制作输入字段文本,并且只能用小写字母而不是大写字母。

I tried to give class for the td selected such as class="smallCaps" and tried to edit in the external css file but it didn't work.我尝试为所选的 td 提供课程,例如class="smallCaps"并尝试在外部 css 文件中进行编辑,但没有奏效。

<?php 
if ($username && $userid){
   echo "You have logged in as <b> $username </b>. Click here to <a href='logout.php'>         Logout </a>";  
 }
  else {
 $form = "<form action= 'index.php' method='POST'> 
 <table> 
    <tr> <td> <font color='black' face='arial' size='3'>Username:  </font> </font></td>    <td> <input type='text' name='user' placeholder='Username' > </td>
    <td> <font color='black' face='arial' size='3'>Password: </td>  </font><td> <input type='password' name='password' placeholder='Password'></td> 
    <td> <button type='submit' class='btn' name='loginbtn' value ='Login'><font size='3'>Login</font> </td></button>
    <tr><td> <a href='signup.php'> <font color='black' face='arial' size='3'>Register</font> </a> </td> </tr>
  </table>
   </form>";

I am not sure what you are doing here.我不确定你在这里做什么。 Did you include the external css file?您是否包含外部 css 文件?

And I assume you did [ class='smallCaps' ] not [ class="smallCaps" ] which would conflict echo.我假设你做了 [ class='smallCaps' ] 而不是 [ class="smallCaps" ] 这会与 echo 冲突。

you should try inline styling like that:你应该尝试这样的内联样式:

<table style=" background-repeat:no-repeat; width:450px;margin:0;" cellpadding="0" cellspacing="0" border="0">
  <tr style="height:40px; width:450px; margin:0;">
    <td style="height:40px; width:40px; margin:0;">

etc....等等....

Try to keep your client side and your server side codes separately.尝试分别保留客户端和服务器端代码。 You can do so by doing the following:您可以通过执行以下操作来做到这一点:

echo '<table class="myClass">';

and then go put the table styles in the class you declared然后将表格样式放在您声明的类中

.myClass{
    top: 15px;
    left: 10px;
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM