【页面布局】Flex 经典骰子布局 第十三届蓝桥杯(Web 应用开发)线上模拟赛

【页面布局】Flex 经典骰子布局

考试需求

考试需求

解答:

index.html:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>骰子布局</title>
    <style>
        body {
     
            /* width: 1024px; */
            margin: 10px 0 0 0;
            display: flex;
            justify-content: space-around;
        }

        body>div {
     
            display: flex;
            width: 100px;
            height: 100px;
            border-radius: 4px;
            border: 2px solid red;
            box-sizing: border-box;
        }

        p {
     
            width: 15px;
            height: 15px;
            background-color: black;
            border-radius: 50%;
            margin: 2px;
        }

        .div1 {
     
            justify-content: center;
            align-items: center;
        }

        /*todo:请补全剩余骰子布局代码*/

        .div2 {
     
            justify-content: space-around;
            flex-direction: column;
            align-items: center;
        }

        .div3 {
     
            justify-content: space-around;
            /* flex-direction: column; */
            /* align-items: space-between; */
            padding: 10px;
        }

        .div03 {
     
            align-self: center;
        }

        .div003 {
     
            align-self: flex-end;
        }


        .div4 {
     
            display: flex;
            justify-content: space-around;
        }

        .div04 {
     
            display: flex;
            flex-direction: column;
            justify-content: space-around;
        }

        .div5 {
     
            display:
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,我们需要了解一下Flex布局的基本概念和属性。Flex布局是一种基于容器和项目的布局模型,它可以自适应不同的屏幕尺寸,并且可以轻松地实现水平和垂直居中等效果。以下是一个简单的Flex布局的代码示例: HTML代码: ```html <div class="container"> <div class="item">Item 1</div> <div class="item">Item 2</div> <div class="item">Item 3</div> </div> ``` CSS代码: ```css .container { display: flex; justify-content: space-between; align-items: center; } .item { width: 100px; height: 100px; background-color: #ccc; } ``` 在上面的代码中,我们使用了`display:flex`来定义容器的布局模式。`justify-content`属性可以定义项目在主轴方向上的对齐方式,这里我们选择了`space-between`,表示项目之间平均分配空间。`align-items`属性可以定义项目在交叉轴方向上的对齐方式,这里我们选择了`center`,表示项目在交叉轴方向上居中对齐。 接下来,我们来实现一个产品页面的布局。假设我们的产品页面包含一个顶部导航栏、一个左侧菜单栏、一个主要内容区域和一个底部信息栏。以下是一个简单的Flex布局的代码示例: HTML代码: ```html <div class="container"> <div class="header">Header</div> <div class="sidebar">Sidebar</div> <div class="content">Content</div> <div class="footer">Footer</div> </div> ``` CSS代码: ```css .container { display: flex; flex-direction: column; height: 100vh; } .header { height: 60px; background-color: #f5f5f5; } .sidebar { width: 200px; background-color: #eee; } .content { flex: 1; background-color: #fff; } .footer { height: 40px; background-color: #f5f5f5; } ``` 在上面的代码中,我们使用了`flex-direction:column`来定义容器的布局方向为纵向布局。`height: 100vh`用于设置容器的高度为视口的高度。`header`和`footer`分别设置了固定高度,`sidebar`设置了固定宽度,`content`的`flex:1`表示它会自动填满剩余的空间。 这样,我们就完成了一个简单的产品页面的布局。当然,实际应用中还需要更多的样式和细节处理,但Flex布局可以让我们轻松地实现各种复杂的布局效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值