九宫格

本文通过两个实例展示了如何使用HTML与CSS进行响应式网页布局,并介绍了一种基于PHP的方法来动态生成这些布局,这种方法可以提高开发效率并增强页面的灵活性。

第一种

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="/static/materialize/css/materialize.css" rel="stylesheet">
    <title>demo</title>
    <style>
        * {
            font-family: "微软雅黑";
        }

        .box {
            height: 33vw;
            border-right: #eeeeee 1px solid;
            border-bottom: #eeeeee 1px solid;
            display: -webkit-flex; /* Safari */
            display: flex;
            justify-content: center;
            align-items: center;
        }

        @media only screen and (min-width: 601px) {
            .box {
                height: 25vw;
            }
        }

        @media only screen and (min-width: 993px) {
            .box {
                height: 16.666vw;
            }
        }

        .box div {
            width: 100%;
            display: inline-block;
        }

        .box div .logo {
            width: 55px;
            height: 55px;
            line-height: 55px;
            font-size: 30px;
            font-style: normal;
        }

        .box div p {
            margin-top: 7px;
            margin-bottom: 0;
            color: black;
        }
    </style>
</head>
<body>
<main class="row center">
    <a href="">
        <div class="col s4 m3 l2 box">
            <div>
                <div class="logo circle white-text red"></div>
                <p>今天</p>
            </div>
        </div>
    </a>

    <a href="">
        <div class="col s4 m3 l2 box">
            <div>
                <div class="logo circle white-text amber"></div>
                <p>明天</p>
            </div>
        </div>
    </a>

</main>
</body>
</html>

第二种

public function Index()
    {
        $aItem = $this->itemBuilder("地址链接", "今天", "text", "今", "red");
        $bItem = $this->itemBuilder("地址链接", "明天", "logo", "明", "amber");

        $list = [$aItem, $bItem];
        $this->assign("list", $list);
        $this->assign("title", "");
        return view("index");
    }

    private function itemBuilder($url = "#", $text = "测试", $type = "text", $logo = "测", $color = "red", $isBlank = false)
    {
        $item = (object)null;
        $item->href = $url;
        $item->text = $text;
        $item->type = $type;
        $item->logo = $logo;
        $item->color = $color;
        if ($isBlank)
            $item->target = "target='_blank'";
        else
            $item->target = "";
        return $item;
    }
<main class="row center">
    {foreach $list as $item}
    <a href="{$item->href}" {$item->target}>
        <div class="col s4 m3 l2 box">
            <div>
                {switch name="item->type"}
                {case value="logo"} <i class="fa {$item->logo} {$item->color} white-text circle logo"></i>{/case}
                {case value="text"}
                <div class="logo circle white-text {$item->color}">{$item->logo}</div>
                {/case}
                {/switch}
                <p>{$item->text}</p>
            </div>
        </div>
    </a>
    {/foreach}
</main>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值