FreeCodeCamp - BootStrap img-responsive text-center btn

本文介绍如何使用Bootstrap框架优化网页布局,包括使图片自适应屏幕宽度、居中标题元素、改进按钮样式等技巧。

First, add a new image below the existing one. Set its src attribute to https://bit.ly/fcc-running-cats.

It would be great if this image could be exactly the width of our phone's screen.

Fortunately, with Bootstrap, all we need to do is add the img-responsive class to your image. Do this, and the image should perfectly fit the width of your page.

<img src="https://bit.ly/fcc-running-cats" class="img-responsive" />

img-response 会自适应屏幕的宽度,不需要传统的html5那样去设置它的大小

Now that we're using Bootstrap, we can center our heading element to make it look better. All we need to do is add the class text-center to our h2 element. the text-primary is the same as the btn-primary

<h2 class="text-primary  text-center">CatPhotoApp</h2>

Bootstrap has its own styles for button elements, which look much better than the plain HTML ones.

<button class="btn">Like</button>

By making them block elements with the additional class of btn-block, your button will stretch to fill your page's entire horizontal space and any elements following it will flow onto a "new line" below the block.

<button class="btn btn-block">Like</button>

The btn-primary class is the main color you'll use in your app. It is useful for highlighting actions you want your user to take.

<button class="btn btn-block btn-primary">Like</button>

Bootstrap comes with several pre-defined colors for buttons. The btn-info class is used to call attention to optional actions that the user can take.

<button class="btn btn-block btn-info">info</button>

Bootstrap comes with several pre-defined colors for buttons. The btn-info class is used to call attention to optional actions that the user can take.

<button class="btn btn-block btn-danger">Delete</button>

转载于:https://my.oschina.net/u/1273644/blog/857166

已经博主授权,源码转载自 https://pan.quark.cn/s/053f1da40351 在计算机科学领域,MIPS(Microprocessor without Interlocked Pipeline Stages)被视作一种精简指令集计算机(RISC)的架构,其应用广泛存在于教学实践和嵌入式系统设计中。 本篇内容将深入阐释MIPS汇编语言中涉及数组处理的核心概念与实用操作技巧。 数组作为一种常见的数据结构,在编程中能够以有序化的形式储存及访问具有相同类型的数据元素集合。 在MIPS汇编语言环境下,数组通常借助内存地址与索引进行操作。 以下列举了运用MIPS汇编处理数组的关键要素:1. **数据存储**: - MIPS汇编架构采用32位地址系统,从而能够访问高达4GB的内存容量。 - 数组元素一般以连续方式存放在内存之中,且每个元素占据固定大小的字节空间。 例如,针对32位的整型数组,其每个元素将占用4字节的存储空间。 - 数组首元素的地址被称为基地址,而数组任一元素的地址可通过基地址加上元素索引乘以元素尺寸的方式计算得出。 2. **寄存器运用**: - MIPS汇编系统配备了32个通用寄存器,包括$zero, $t0, $s0等。 其中,$zero寄存器通常用于表示恒定的零值,$t0-$t9寄存器用于暂存临时数据,而$s0-$s7寄存器则用于保存子程序的静态变量或参数。 - 在数组处理过程中,基地址常被保存在$s0或$s1寄存器内,索引则存储在$t0或$t1寄存器中,运算结果通常保存在$v0或$v1寄存器。 3. **数组操作指令**: - **Load/Store指令**:这些指令用于在内存与寄存器之间进行数据传输,例如`lw`指令用于加载32位数据至寄存器,`sw`指令...
根据原作 https://pan.quark.cn/s/cb681ec34bd2 的源码改编 基于Python编程语言完成的飞机大战项目,作为一项期末学习任务,主要呈现了游戏开发的基本概念和技术方法。 该项目整体构成约500行代码,涵盖了游戏的核心运作机制、图形用户界面以及用户互动等关键构成部分。 该项目配套提供了完整的源代码文件、相关技术文档、项目介绍演示文稿以及运行效果展示视频,为学习者构建了一个实用的参考范例,有助于加深对Python在游戏开发领域实际应用的认识。 我们进一步研究Python编程技术在游戏开发中的具体运用。 Python作为一门高级编程语言,因其语法结构清晰易懂和拥有丰富的库函数支持,在开发者群体中获得了广泛的认可和使用。 在游戏开发过程中,Python经常与Pygame库协同工作,Pygame是Python语言下的一款开源工具包,它提供了构建2D游戏所需的基础功能模块,包括窗口系统管理、事件响应机制、图形渲染处理、音频播放控制等。 在"飞机大战"这一具体游戏实例中,开发者可能运用了以下核心知识点:1. **Pygame基础操作**:掌握如何初始化Pygame环境,设定窗口显示尺寸,加载图像和音频资源,以及如何启动和结束游戏的主循环流程。 2. **面向对象编程**:游戏中的飞机、子弹、敌人等游戏元素通常通过类的设计来实现,利用实例化机制来生成具体的游戏对象。 每个类都定义了自身的属性(例如位置坐标、移动速度、生命值状态)和方法(比如移动行为、碰撞响应、状态更新)。 3. **事件响应机制**:Pygame能够捕获键盘输入和鼠标操作事件,使得玩家可以通过按键指令来控制飞机的移动和射击行为。 游戏会根据这些事件的发生来实时更新游戏场景状态。 4. **图形显示与刷新**:...
【顶级SCI复现】高比例可再生能源并网如何平衡灵活性与储能成本?虚拟电厂多时间尺度调度及衰减建模(Matlab代码实现)内容概要:本文围绕高比例可再生能源并网背景下虚拟电厂的多时间尺度调度与储能成本优化问题展开研究,重点探讨如何在保证系统灵活性的同时降低储能配置与运行成本。通过构建多时间尺度(如日前、日内、实时)协调调度模型,并引入储能设备衰减建模,提升调度精度与经济性。研究结合Matlab代码实现,复现顶级SCI论文中的优化算法与建模方法,涵盖鲁棒优化、分布鲁棒、模型预测控制(MPC)等先进手段,兼顾风光出力不确定性与需求响应因素,实现虚拟电厂内部多能源协同优化。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事新能源、智能电网、能源互联网领域的工程技术人员。; 使用场景及目标:① 掌握虚拟电厂多时间尺度调度的核心建模思路与实现方法;② 学习如何将储能寿命衰减纳入优化模型以提升经济性;③ 复现高水平SCI论文中的优化算法与仿真流程,服务于科研论文写作与项目开发。; 阅读建议:建议结合文中提供的Matlab代码逐模块分析,重点关注目标函数设计、约束条件构建及求解器调用过程,配合实际案例数据进行调试与验证,深入理解优化模型与物理系统的映射关系。
<think>我们之前已经讨论了@media (max-width: 576px)的用法,现在来看@media (min-width: 576px)。这个媒体查询用于指定当屏幕宽度大于或等于576px时应用的样式,通常用于平板、桌面等较大屏幕设备的样式设计。 # Vue 中 @media (min-width: 576px) 的应用详解 在Vue中使用 `@media (min-width: 576px)` 主要用于针对平板、桌面等较大屏幕设备的样式设计。这个媒体查询表示当屏幕宽度大于或等于576px时应用指定的样式规则。 ## 基本使用方式 ### 在单文件组件中使用 ```vue <template> <div class="responsive-container"> <div class="content-box"> <h1>响应式设计示例</h1> <p>在不同屏幕尺寸下查看效果</p> </div> </div> </template> <script> export default { name: 'ResponsiveComponent' } </script> <style scoped> /* 基础样式(所有设备) */ .responsive-container { padding: 20px; } .content-box { padding: 20px; background-color: #f0f8ff; border-radius: 8px; } /* 平板及以上设备样式 (≥576px) */ @media (min-width: 576px) { .responsive-container { display: flex; justify-content: center; } .content-box { width: 80%; padding: 30px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } } </style> ``` ### 关键点解释 - `@media (min-width: 576px)` 是桌面优先设计中常用的断点 - 576px 是Bootstrap框架中的小屏幕界限(sm)的下限 - 通常用于调整布局、增加内边距、改变字体大小等 ## 高级应用技巧 ### 1. 多列布局调整 ```vue <template> <div class="gallery"> <div v-for="item in 6" :key="item" class="gallery-item"> 项目 {{ item }} </div> </div> </template> <style scoped> .gallery { display: flex; flex-wrap: wrap; gap: 10px; } .gallery-item { flex: 1 1 100%; padding: 15px; background: #eee; text-align: center; } /* 小屏幕(平板)及以上 */ @media (min-width: 576px) { .gallery-item { flex: 1 1 calc(50% - 20px); /* 两列布局 */ } } /* 中等屏幕及以上 */ @media (min-width: 768px) { .gallery-item { flex: 1 1 calc(33.333% - 20px); /* 三列布局 */ } } /* 大屏幕 */ @media (min-width: 992px) { .gallery-item { flex: 1 1 calc(25% - 20px); /* 四列布局 */ } } </style> ``` ### 2. 导航栏响应式改造 ```vue <template> <nav :class="['navbar', { 'expanded': isExpanded }]"> <div class="nav-toggle" @click="isExpanded = !isExpanded"> <span v-if="!isExpanded">☰</span> <span v-else>×</span> </div> <ul class="nav-links"> <li><a href="#">首页</a></li> <li><a href="#">关于</a></li> <li><a href="#">服务</a></li> <li><a href="#">联系</a></li> </ul> </nav> </template> <script> export default { data() { return { isExpanded: false } } } </script> <style scoped> .navbar { background: #333; color: white; padding: 10px; } .nav-toggle { display: block; cursor: pointer; font-size: 24px; } .nav-links { display: none; list-style: none; padding: 0; margin: 0; } .nav-links li a { color: white; text-decoration: none; display: block; padding: 10px; } /* 平板及以上设备 - 隐藏切换按钮,显示导航链接 */ @media (min-width: 576px) { .nav-toggle { display: none; } .nav-links { display: flex; } } /* 移动端展开状态 */ .expanded .nav-links { display: block; } </style> ``` ### 3. 响应式表格设计 ```vue <template> <div class="table-container"> <table> <thead> <tr> <th>姓名</th> <th>邮箱</th> <th>职位</th> <th>部门</th> </tr> </thead> <tbody> <tr v-for="(item, index) in tableData" :key="index"> <td data-label="姓名">{{ item.name }}</td> <td data-label="邮箱">{{ item.email }}</td> <td data-label="职位">{{ item.position }}</td> <td data-label="部门">{{ item.department }}</td> </tr> </tbody> </table> </div> </template> <script> export default { data() { return { tableData: [ { name: '张三', email: 'zhangsan@example.com', position: '工程师', department: '技术部' }, { name: '李四', email: 'lisi@example.com', position: '设计师', department: '设计部' }, { name: '王五', email: 'wangwu@example.com', position: '产品经理', department: '产品部' } ] } } } </script> <style scoped> .table-container { overflow-x: auto; } table { width: 100%; border-collapse: collapse; } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; } /* 小屏幕下表格转为卡片式 */ @media (max-width: 575px) { thead { display: none; } tr { display: block; margin-bottom: 15px; border: 1px solid #ddd; border-radius: 4px; } td { display: block; text-align: right; position: relative; padding-left: 50%; } td::before { content: attr(data-label); position: absolute; left: 0; width: 45%; padding-left: 15px; font-weight: bold; text-align: left; } } /* 平板及以上设备显示正常表格 */ @media (min-width: 576px) { table { box-shadow: 0 0 10px rgba(0,0,0,0.1); } } </style> ``` ## 响应式设计最佳实践 1. **桌面优先 vs 移动优先**: - `min-width` 用于桌面优先设计(从小屏幕到大屏幕) - `max-width` 用于移动优先设计(从大屏幕到小屏幕) 2. **断点选择策略**: ```css /* 超小设备 (<576px) - 默认移动样式 */ /* 小设备 (≥576px) */ @media (min-width: 576px) { ... } /* 中等设备 (≥768px) */ @media (min-width: 768px) { ... } /* 大设备 (≥992px) */ @media (min-width: 992px) { ... } /* 超大设备 (≥1200px) */ @media (min-width: 1200px) { ... } ``` 3. **响应式字体**: ```css body { font-size: 16px; } @media (min-width: 576px) { body { font-size: 18px; } } ``` 4. **响应式图片**: ```vue <template> <picture> <source media="(min-width: 992px)" srcset="large.jpg"> <source media="(min-width: 576px)" srcset="medium.jpg"> <img src="small.jpg" alt="响应式图片"> </picture> </template> ``` ## 常见问题解决方案 **问题:** 媒体查询在特定断点不生效 **解决:** 检查样式顺序,确保媒体查询的顺序正确(从小到大或从大到小) ```css /* 错误的顺序 - 较大的断点会覆盖较小的 */ @media (min-width: 992px) { ... } @media (min-width: 768px) { ... } /* 这个会被992px的覆盖 */ /* 正确的顺序 - 从小断点到大断点 */ @media (min-width: 576px) { ... } @media (min-width: 768px) { ... } @media (min-width: 992px) { ... } ``` **问题:** 组件库的响应式覆盖问题 **解决:** 使用深度选择器提高优先级 ```css @media (min-width: 576px) { ::v-deep .el-button { padding: 12px 24px; } } ``` **问题:** 打印样式调整 **解决:** 添加打印媒体查询 ```css @media print { .no-print { display: none; } } @media (min-width: 576px) and print { body { font-size: 12pt; } } ``` §§相关问题§§: 1. 在Vue中如何实现移动优先和桌面优先的混合响应式设计? 2. 如何使用Vue的provide/inject响应屏幕尺寸变化? 3. 在Vue3中如何结合Composition API实现响应式布局逻辑? 4. 如何优化Vue应用在不同断点切换时的性能? </think> # Vue 中 `@media (min-width: 576px)` 的深入解析与应用 在 Vue 中使用 `@media (min-width: 576px)` 是响应式设计的核心技巧之一,它允许你在屏幕宽度达到 576px 及以上时应用特定样式。这个断点通常对应 Bootstrap 的 "sm"(小屏幕)尺寸,适合用于平板和桌面设备的样式调整。 ## 基础用法与示例 ### 基本组件结构 ```vue <template> <div class="responsive-container"> <div class="content-box"> <h1>响应式标题</h1> <p>内容区域</p> <div class="grid-container"> <div class="grid-item" v-for="i in 3" :key="i">项目 {{ i }}</div> </div> </div> </div> </template> <script> export default { name: 'ResponsiveComponent' } </script> <style scoped> /* 基础样式 - 适用于所有设备 */ .responsive-container { padding: 15px; } .content-box { background-color: #f5f5f5; border-radius: 8px; padding: 20px; } .grid-container { display: block; } .grid-item { background-color: #e0e0e0; padding: 10px; margin-bottom: 10px; border-radius: 4px; } /* 小屏幕及以上设备样式 (≥576px) */ @media (min-width: 576px) { .responsive-container { padding: 30px; max-width: 1200px; margin: 0 auto; } .content-box { padding: 30px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } .grid-container { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; } .grid-item { margin-bottom: 0; } } /* 中等屏幕及以上设备 (≥768px) */ @media (min-width: 768px) { .grid-container { grid-template-columns: repeat(3, 1fr); } } </style> ``` ## 进阶应用场景 ### 1. 动态布局切换 ```vue <template> <div :class="['layout-container', { 'desktop-layout': isDesktop }]"> <aside v-if="isDesktop" class="sidebar"> <!-- 桌面端侧边栏内容 --> </aside> <main class="main-content"> <!-- 主要内容区域 --> </main> </div> </template> <script> export default { data() { return { windowWidth: window.innerWidth } }, computed: { isDesktop() { return this.windowWidth >= 576; } }, mounted() { window.addEventListener('resize', this.updateWindowWidth); }, beforeDestroy() { window.removeEventListener('resize', this.updateWindowWidth); }, methods: { updateWindowWidth() { this.windowWidth = window.innerWidth; } } } </script> <style scoped> /* 移动端布局 */ .layout-container { display: block; } .sidebar { display: none; /* 移动端隐藏侧边栏 */ } .main-content { width: 100%; } /* 桌面端布局 (≥576px) */ @media (min-width: 576px) { .layout-container { display: flex; } .sidebar { display: block; width: 250px; min-height: 100vh; background: #2c3e50; color: white; } .main-content { flex: 1; padding: 20px; } } </style> ``` ### 2. 响应式表单布局 ```vue <template> <form class="responsive-form"> <div class="form-group"> <label for="name">姓名</label> <input type="text" id="name"> </div> <div class="form-row"> <div class="form-group"> <label for="email">邮箱</label> <input type="email" id="email"> </div> <div class="form-group"> <label for="phone">电话</label> <input type="tel" id="phone"> </div> </div> <button type="submit">提交</button> </form> </template> <style scoped> .responsive-form { display: block; } .form-group { margin-bottom: 15px; } .form-row { display: block; } label { display: block; margin-bottom: 5px; } input { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; } /* 小屏幕及以上设备 (≥576px) */ @media (min-width: 576px) { .form-row { display: flex; gap: 20px; } .form-group { flex: 1; margin-bottom: 20px; } input { padding: 10px; } button { padding: 10px 20px; font-size: 16px; } } </style> ``` ### 3. 响应式导航菜单 ```vue <template> <nav class="navbar"> <div class="navbar-brand">网站Logo</div> <!-- 移动端菜单按钮 --> <button class="mobile-menu-btn" @click="toggleMenu">☰</button> <!-- 导航链接 --> <ul :class="['nav-links', { 'active': menuOpen }]"> <li><a href="#">首页</a></li> <li><a href="#">产品</a></li> <li><a href="#">服务</a></li> <li><a href="#">关于我们</a></li> <li><a href="#">联系我们</a></li> </ul> </nav> </template> <script> export default { data() { return { menuOpen: false } }, methods: { toggleMenu() { this.menuOpen = !this.menuOpen; } } } </script> <style scoped> .navbar { display: flex; justify-content: space-between; align-items: center; padding: 15px; background: #333; color: white; } .mobile-menu-btn { display: block; background: none; border: none; color: white; font-size: 24px; cursor: pointer; } .nav-links { display: none; position: absolute; top: 60px; left: 0; right: 0; background: #333; list-style: none; padding: 0; margin: 0; } .nav-links.active { display: block; } .nav-links li a { display: block; padding: 10px 15px; color: white; text-decoration: none; } /* 小屏幕及以上设备 (≥576px) */ @media (min-width: 576px) { .mobile-menu-btn { display: none; } .nav-links { display: flex; position: static; background: transparent; } .nav-links li a { padding: 5px 15px; } .nav-links li a:hover { background: #444; border-radius: 4px; } } </style> ``` ## 响应式设计最佳实践 ### 1. 断点策略 ```css /* 默认样式 - 移动优先 (小于576px) */ /* 小屏幕 (≥576px) */ @media (min-width: 576px) { /* 平板和桌面布局 */ } /* 中等屏幕 (≥768px) */ @media (min-width: 768px) { /* 桌面布局优化 */ } /* 大屏幕 (≥992px) */ @media (min-width: 992px) { /* 大桌面布局 */ } /* 超大屏幕 (≥1200px) */ @media (min-width: 1200px) { /* 超大桌面布局 */ } ``` ### 2. 响应式工具函数 ```js // utils/responsive.js export const breakpoints = { sm: 576, md: 768, lg: 992, xl: 1200 }; export function useResponsive() { const screen = reactive({ width: window.innerWidth, height: window.innerHeight }); const isMobile = computed(() => screen.width < breakpoints.sm); const isTablet = computed(() => screen.width >= breakpoints.sm && screen.width < breakpoints.md ); const isDesktop = computed(() => screen.width >= breakpoints.md); const updateDimensions = () => { screen.width = window.innerWidth; screen.height = window.innerHeight; }; onMounted(() => { window.addEventListener('resize', updateDimensions); }); onUnmounted(() => { window.removeEventListener('resize', updateDimensions); }); return { screen, isMobile, isTablet, isDesktop }; } ``` ### 3. 响应式图片处理 ```vue <template> <div class="responsive-image"> <picture> <!-- 小屏幕显示方形图片 --> <source media="(max-width: 575px)" srcset="image-square-small.jpg, image-square-large.jpg 2x" > <!-- 中等屏幕显示横向图片 --> <source media="(min-width: 576px) and (max-width: 991px)" srcset="image-landscape-small.jpg, image-landscape-large.jpg 2x" > <!-- 大屏幕显示高清图片 --> <source media="(min-width: 992px)" srcset="image-hd.jpg" > <!-- 默认图片 --> <img src="image-default.jpg" alt="响应式图片示例" class="image-content" > </picture> </div> </template> <style scoped> .responsive-image { max-width: 100%; height: auto; } .image-content { width: 100%; height: auto; display: block; } @media (min-width: 576px) { .responsive-image { border-radius: 8px; overflow: hidden; box-shadow: 0 4px 8px rgba(0,0,0,0.1); } } </style> ``` ## 常见问题与解决方案 ### 问题1:媒体查询不生效 **原因**:样式优先级问题或断点冲突 **解决**:确保媒体查询放在普通样式之后,按从小到大的顺序排列 ```css /* 正确顺序 */ .element { /* 基础样式 */ } @media (min-width: 576px) { /* sm */ } @media (min-width: 768px) { /* md */ } /* 错误顺序 - 可能导致覆盖问题 */ @media (min-width: 768px) { /* md */ } @media (min-width: 576px) { /* sm - 这个会覆盖上面的样式 */ } ``` ### 问题2:组件库样式覆盖 **原因**:第三方组件库样式优先级更高 **解决**:使用深度选择器或提高特异性 ```css @media (min-width: 576px) { /* 使用深度选择器覆盖组件库样式 */ ::v-deep .el-button { padding: 12px 24px; font-size: 16px; } /* 或通过增加特异性 */ .my-container .el-button { padding: 12px 24px; } } ``` ### 问题3:移动端和桌面端行为差异 **解决方案**:使用条件渲染和响应式计算属性 ```vue <template> <div> <!-- 移动端显示汉堡菜单 --> <button v-if="isMobile" @click="openMenu">☰</button> <!-- 桌面端显示完整导航 --> <nav v-else> <a href="#">首页</a> <a href="#">产品</a> <a href="#">服务</a> </nav> <!-- 响应式组件 --> <component :is="isMobile ? MobileComponent : DesktopComponent" /> </div> </template> <script> import { useResponsive } from '@/utils/responsive'; export default { setup() { const { isMobile } = useResponsive(); return { isMobile }; }, components: { MobileComponent, DesktopComponent } } </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值