如何将php文件放在div类中?

安德烈·贝拉

你好,美好的一天!自从我第一次来这里以来,我真的不知道如何在这里发布。请不要犹豫,教我一些基础知识。无论如何,这是我的代码。

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何将 php 放在 php 中

来自分类Dev

如何将引导发光(用于“ form-control” CSS类中)放在div上?

来自分类Dev

如何将“子类”放在一个类中

来自分类Dev

如何将类放在Html.Dropdownlist中?

来自分类Dev

如何将“子类”放在一个类中

来自分类Dev

如何将类放在Html.Dropdownlist中?

来自分类Dev

如何将php变量放在php的目录路径中

来自分类Dev

您如何将li放在不同的div中?

来自分类Dev

如何将<div>放在表格标签中?

来自分类Dev

如何将jdiv中的div放在最前面?

来自分类Dev

如何将 <script> 标签放在 <div> 标签中?

来自分类Dev

如何将jquery放在单独的文件中?

来自分类Dev

如何将界面放在单独的文件中?

来自分类Dev

如何将路径更改.bat文件放在%PATH%中?

来自分类Dev

如何将jquery放在单独的文件中?

来自分类Dev

PDO。如何将连接放在外部文件中

来自分类Dev

如何将javascript放在html文件中

来自分类Dev

如何将Ionic 2 Modal放在单独的文件中?

来自分类Dev

如何将字典变量放在单独的 swift 文件中?

来自分类Dev

如何将所需的参数放在访问php的链接中?

来自分类Dev

如何将 <?php foreach?> 放在基于列的网格中

来自分类Dev

如何将 html href 按钮放在 php 代码中

来自分类Dev

如何将div放在页面顶部

来自分类Dev

如何将div放在容器内?

来自分类Dev

如何将 ap 放在 div 的中心?

来自分类Dev

如何将 ParseQuery 放在单独的类中并在 android 的每个活动中调用此方法?

来自分类Dev

如何将ComboBoxTableCell放在TableView中?

来自分类Dev

如何将jpg放在JComboBox中?

来自分类Dev

如何将重点放在榆木中?

Related 相关文章

热门标签

归档