你好,美好的一天!自从我第一次来这里以来,我真的不知道如何在这里发布。请不要犹豫,教我一些基础知识。无论如何,这是我的代码。
body{
margin: 0;
padding: 0;
background: url(bg.jpg) no-repeat;
background-size: cover;
}
.box{
width: 450px;
background: rgba(0, 0, 0, 0.4);
padding: 40px;
text-align: center;
margin: auto;
margin-top: 5%;
color: white;
font-family: 'Century Gothic',sans-serif;
}
.box-img{
border-radius: 50%;
width: 200px;
height: 200px;
}
.box h1{
font-size: 40px;
letter-spacing: 4px;
font-weight: 100;
}
.box h5{
font-size: 20px;
letter-spacing: 3px;
font-weight: 100;
}
.box p{
text-align: justify;
}
ul{
margin: 0;
padding: 0;
}
.box li{
display: inline-block;
margin: 6px;
list-style: none;
}
.box li a{
color: white;
text-decoration: none;
font-size: 60px;
transition: all ease-in-out 250ms;
}
.box li a:hover{
color: #b9b9b9;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://use.fontawesome.com/d1341f9b7a.js"></script>
<link rel="stylesheet" href="style.css">
<title>Personal WebSite</title>
</head>
<body>
<div class="box">
<img src="profile.jpg" alt="" class="box-img">
<h1>DarkCode</h1>
<h5>Web Devloper - Web Designer</h5>
<?php include("menu.php"); ?>
<ul>
<li><a href="#"><i class="fa fa-facebook-square" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-twitter-square" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-google-plus-square" aria-hidden="true"></i></a></li>
</ul>
</div>
</body>
</html>
这是我要包含在框中的php文件(menu.php)
<?php
class Fruit{
public $name;
public $color;
function __construct($name, $color){
$this->name = $name;
$this->color = $color;
}
function get_name(){
return $this->name;
}
function __destruct(){
echo "<h1>The fruit is {$this->name} and the color is {$this->color}.</h1>";
}
}
$apple = new Fruit("Apple", "red");
//echo $apple->get_name();
?>
运行此代码将在框外显示echo语句。如何将该语句放入div类中?
您当前的方法应在内显示该语句<div class="box"> </div>
。但是,如果内容开箱即用,则可能是由于CSS中的某些问题所致。
您能否分享CSS代码,还可以分享内容显示方式的屏幕截图。
==================编辑后======================
我所做的第一个修正是:我使用<?php include "./menu.php"; ?>
而不是<?php include("menu.php"); ?>
第二个是当您回显时,它会正确显示在div中。__destruct()函数在脚本末尾自动调用,其内容仅在开箱即用的位置显示。没有评论echo $apple->get_name();
最后,__ destruct()用于恢复在对象的生存期内分配的堆空间,关闭文件或数据库连接以及释放网络资源。
如果您确实要显示H1,则可以进行此更改。
<?php
$des="";
class Fruit
{
public $name;
public $color;
function __construct($name, $color)
{
$this->name = $name;
$this->color = $color;
}
function get_name()
{
return $this->name;
}
function __destruct()
{
global $des;
$des = "<h1>The fruit is {$this->name} and the color is {$this->color}.</h1>";
}
}
$apple = new Fruit("Apple", "red");
echo $apple->get_name();
unset($apple);
echo $des;
?>
有用的链接:PHP未设置
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句