php怎么把图片设为背景

angryTom
angryTom 原创
2023-02-26 21:28:01 12699浏览

我们可以在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相关知识,请访问PHP中文网

以上就是php怎么把图片设为背景的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。