php教程--案例10(网页布局)

编程知识 更新时间:2023-04-06 04:51:17

t195.php

<?php
//case 10 网页布局
//定义常量,防止直接访问引入页面
define('WEBTEST','test1');
?>
<html>
<head>
    <meta charset="UTF-8">
    <title>网页布局</title>
    //样式表
    <style type="text/css" rel="stylesheet">
        .title
        {
            width: 98%;
            height: 100px;
            background-color: #cccccc;
            margin: 3px auto;
            text-align: center;
        }
        .content
        {
            width: 60%;
            height: 600px;
            float: left;
        }

        .content .lst
        {
            width: 90%;
            height: 580px;
            margin: 0 auto;
        }

        .content .lst .pic
        {
            float: left;
            width: 320px;
            height: 160px;
            background-color: #CCCCCC;
            margin: 5px;
            padding: 5px;
        }

        .content .lst .pic img
        {
            width: 300px;
            height: 150px;
            padding: 5px;
        }

        .side
        {
            width: 38%;
            height: 600px;
            float: right;
        }

        .side ul
        {
            list-style: none;
        }

        .side ul li
        {
            text-indent: 20px;
        }

        .side p
        {
            margin: 0;
            padding: 5px;
            font-size: 20px;
            color: #7f7f7f;
        }
        .footer
        {
            width: 98%;
            height: 100px;
            background-color: #cccccc;
            margin: 3px auto;
            text-align: center;
            clear: both;
        }
    </style>
</head>
<body>
    <div class="title">header</div>
    <div class="content"><?php include ('./t196.php');?></div>
    <div class="side"><?php include ('./t197.php');?></div>
    <div class="footer">footer</div>
</body>
</html>

t196.php

<?php
//访问限制
if(!defined('WEBTEST'))
{
    exit('No access!');
}
//图片列表
$books = array('cat.jpg','cat.jpg','cat.jpg','cat.jpg','cat.jpg','cat.jpg');
?>

<div class="lst">
    //:,endforeach是php 7 新语法
    <?php foreach ($books as $book):?>
    <div class="pic">
        <img src="./img/<?php echo $book;?>">
    </div>
    <?php endforeach;?>
    <div style="clear:both"></div>
</div>

t197.php

<?php
//访问限制
if(!defined('WEBTEST'))
{
    exit('No access!');
}

?>

<h2>PHP培训班开训信息</h2>
<ul>
    <?php
    //数组列表
    $arr = array(
        array('PHP基础班','西安--第01期','兰州--第02期','白银--第03期'),
        array('PHP中级班','成都--第11期','重庆--第12期','宁波--第13期'),
        array('PHP高级班','杭州--第31期','上海--第32期','郑州--第33期')
    );
    //数组首个元素放入p标签,其他放入无序列表
    foreach ($arr as $values)
    {
        foreach($values as $k=>$v):
            echo $k > 0 ? "<li>{$v}</li>":"<p>{$v}</p>";
        endforeach;
    }
    ?>
</ul>

 

更多推荐

php教程--案例10(网页布局)

本文发布于:2023-04-06 04:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/a26bf8a8642850681be7825ce487dbb4.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   案例   网页   教程   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 48340文章数
  • 14阅读数
  • 0评论数