php通过设置style实现改图片为背景

php通过设置style实现改图片为背景

这篇文章主要为大家详细介绍了php通过设置style实现改图片为背景的方法,文中示例代码介绍的非常详细,图文详解容易学习,非常适合初学者入门,感兴趣的小伙伴们可以参考一下。


php通过设置style实现改图片为背景

我们可以在php中输出样式代码,达到改变html背景图片的目的。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- 通过设置style实现改变背景 -->
<body <?php echo 'style="background:url(图片.jpg);"'; ?> >
<form action="DataBase.php" method="post">
用户名:<input type="text" name="username" maxlength="40"/><br/>
密码:<input type="password" name="pwd" maxlength="40"/><br/>
<input type="submit" value="提交"/>
</form>
</body>
</body>
</html>

但是并不建议在php代码中输出样式文件,应该在html文档中书写,或单独写css样式文件,在html中引入。

1、在html中写css

<!-- 在head标签内书写css -->
<style>
body{background:url(背景图片地址);}
</style>

2、引入css文件

//main.css文件
body{background:url(背景图片地址);}

//在html文件head标签中引入
<link rel="stylesheet" href="main.css">

看完上诉内容,你们掌握php通过设置style实现改图片为背景的方法了吗?如果想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!