使用flex固定头部和底部中间滚动

使用flex固定头部和底部中间滚动

关键点:
* root纵向布局高度充满整个浏览器界面并且隐藏滚动条
* content设置滚动,flex设置1,否则当所有item的高度太小时footer会离开底部
* item设置高度后,必须设置flexShrink为0,否则当所有item高度超过content高度时item会被压缩掉

‘100vh’浏览器视口高度的百分比,这里是100%;
flex为1其他元素为0时(默认为0),当有多余空间时会被flex为1的元素侵占;
flexShrink为0,当空间被压缩时flexShrink为0的元素不被压缩;

代码如下:

class App extends React.Component {
  render() {
    const items = [1, 2, 3, 4, 5, 6, 7]
    return (
        <div style={Style.root}>
            <div style={Style.head}>head</div>
            <div style={Style.content}>
                {items.map((item, index) => {
                    return <div key={index} style={Style.item}>{item}</div>
                })}
            </div>
            <div style={Style.footer}>footer</div>
        </div>
    )
  }
}

const Style = {}
Style.root = {
    display: 'flex',
    flexDirection: 'column',
    height: '100vh',
    overflowY: 'hidden'
}

Style.head = {
    height: 80,
    backgroundColor: '#ccc',
}

Style.footer = {
    height: 80,
    backgroundColor: '#ccc',
} 

Style.content = {
    display: 'flex',
    flexDirection: 'column',
    flex: 1, 
    overflowY: 'scroll'
}

Style.item = {
    display: 'flex',
    height: 200,
    flexShrink: 0,
    backgroundColor: 'rgb(232, 128, 36)',
    margin: 10
}

export default App;
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 公司年会滚动抽奖系统的HTML源码是用来构建网页界面的代码,通常包括HTML标签、CSS样式表和JavaScript脚本。 HTML标签用于定义网页的结构,如头部、主体和底部,以及各个元素的属性和内容。在公司年会滚动抽奖系统的HTML源码中,可能会包含抽奖界面的布局和各个操作按钮的定义。 CSS样式表用于美化界面,通过定义元素的样式和布局,可以使界面看起来更加美观和一致。在公司年会滚动抽奖系统的HTML源码中,可能会包含各个元素的颜色、大小、字体等样式的定义。 JavaScript脚本用于实现网页的交互功能,通过定义事件和处理函数,可以实现抽奖系统的滚动效果、抽奖号码的生成和展示等功能。在公司年会滚动抽奖系统的HTML源码中,可能会包含抽奖逻辑的实现,如随机生成中奖号码和滚动展示中奖结果的动画效果。 总之,公司年会滚动抽奖系统的HTML源码是通过HTML标签、CSS样式表和JavaScript脚本共同构建的,用于实现抽奖系统的界面展示和交互功能。这些源码的编写和组合可以根据具体需求进行调整和优化,以实现更好的用户体验和系统性能。 ### 回答2: 公司年会滚动抽奖系统的HTML源码是一个网页的源代码,主要用于构建具有滚动抽奖功能的网页页面。以下是一个简化的HTML源码示例: ``` <!DOCTYPE html> <html> <head> <title>公司年会滚动抽奖系统</title> <style> /* CSS样式表用于美化页面样式 */ body { font-family: Arial, sans-serif; background-color: #f2f2f2; } .container { max-width: 800px; margin: 0 auto; padding: 20px; background-color: white; border: 1px solid #ccc; border-radius: 5px; } h1 { text-align: center; } .winner { color: #ff0000; font-size: 24px; font-weight: bold; text-align: center; margin-bottom: 30px; } .button { display: inline-block; padding: 10px 20px; background-color: #4CAF50; color: white; text-decoration: none; border-radius: 5px; } </style> <script> // JavaScript代码用于控制抽奖逻辑 function roll() { // 这里编写抽奖滚动逻辑 // 当点击抽奖按钮后,滚动指针,最终停留在一个抽奖结果上 // 将抽奖结果显示在页面上的.winner元素中 } </script> </head> <body> <div class="container"> <h1>公司年会滚动抽奖系统</h1> <div class="winner"></div> <button class="button" onclick="roll()">点击抽奖</button> </div> </body> </html> ``` 以上示例中的代码为公司年会滚动抽奖系统提供了一个基本的页面结构和样式,并包含了一个抽奖按钮和一个用于显示抽奖结果的区域。在具体的JavaScript代码中,可以根据需要编写抽奖逻辑,实现抽奖滚动和停止,并将最终的抽奖结果展示在页面上。当用户点击抽奖按钮时,调用JavaScript中的`roll()`函数触发抽奖逻辑。 ### 回答3: 公司年会滚动抽奖系统的HTML源码如下: ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>公司年会滚动抽奖系统</title> <style> .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } .button { padding: 10px 20px; background-color: #f0f0f0; color: #333; border: none; border-radius: 5px; cursor: pointer; } #result { margin-top: 20px; font-weight: bold; } </style> </head> <body> <div class="container"> <h1>公司年会滚动抽奖系统</h1> <button class="button" onclick="startLottery()">开始抽奖</button> <div id="result"></div> </div> <script> var participants = ["员工A", "员工B", "员工C", "员工D", "员工E"]; // 参与抽奖的员工名单 function startLottery() { var resultElement = document.getElementById("result"); // 生成一个随机数作为索引,从参与抽奖的员工名单中获取一个幸运员工 var randomIndex = Math.floor(Math.random() * participants.length); var luckyParticipant = participants[randomIndex]; resultElement.innerText = "恭喜 " + luckyParticipant + " 中奖啦!"; } </script> </body> </html> ``` 以上是一个简单的公司年会滚动抽奖系统的HTML源码。界面中包含一个抽奖按钮和一个用于展示中奖结果的文本框。点击"开始抽奖"按钮会在参与抽奖的员工名单中随机选择一个员工,并将结果显示在文本框中。参与抽奖的员工名单可以通过修改JavaScript代码中的`participants`数组来支持不同的名单。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值