Flex 2 技巧 - 圓角容器遮罩

本文介绍了一种在Flex2中使用圆角容器并解决内容溢出问题的方法。通过创建额外的圆角对象作为遮罩,可以有效地隐藏超出边界的元素,实现美观的圆角效果。

Flex 2 技巧 - 圓角容器遮罩

Flex 2 很多容器都有支援圓角邊框的設定 cornerRadius
不過容器的物件卻會超出圓角邊界
使用上不太方便~~

以下利用另一個圓角物件當作 Mask,遮住超出圓角的物件

view plain |  copy to clipboard |  print |  ? | 
∙∙∙∙∙∙∙∙∙10∙∙∙∙∙∙∙∙20∙∙∙∙∙∙∙∙30∙∙∙∙∙∙∙∙40∙∙∙∙∙∙∙∙50∙∙∙∙∙∙∙∙60∙∙∙∙∙∙∙∙70∙∙∙∙∙∙∙∙80∙∙∙∙∙∙∙∙90∙∙∙∙∙∙∙∙100∙∙∙∙∙∙∙110∙∙∙∙∙∙∙120∙∙∙∙∙∙∙130∙∙∙∙∙∙∙140∙∙∙∙∙∙∙150
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
  3.  <mx:HBox>
  4.   <mx:Label text="Border Thickness"/>
  5.   <mx:NumericStepper id="step1" maximum="100" value="6"/>
  6.   <mx:Label text="Corner Radius"/>
  7.   <mx:NumericStepper id="step2" maximum="100" value="16"/>
  8.  </mx:HBox>
  9.  <mx:Canvas width="80%" height="80%" id="c1"
  10.   borderStyle="solid" borderThickness="{step1.value}" cornerRadius="{step2.value}">
  11.   <mx:Canvas width="100%" height="100%" id="c2"
  12.    borderStyle="solid" borderThickness="0" cornerRadius="{step2.value - step1.value}"
  13.    backgroundColor="#0" cacheAsBitmap="true"/>
  14.   <mx:Canvas width="100%" height="100%" mask="{c2}" cacheAsBitmap="true">
  15.    <mx:Button x="-32" y="-45" width="100" height="100" label="Button"/>
  16.    <mx:Button x="228" y="-45" width="100" height="100" label="Button"/>
  17.    <mx:Button x="390" y="119" width="100" height="100" label="Button"/>
  18.    <mx:Button x="10" y="119" width="100" height="100" label="Button"/>
  19.    <mx:Button x="218" y="263" width="100" height="100" label="Button"/>
  20.    <mx:Button x="598" y="323" width="100" height="100" label="Button"/>
  21.    <mx:Button x="598" y="-37" width="100" height="100" label="Button"/>
  22.    <mx:Button x="-45" y="280" width="100" height="100" label="Button"/>
  23.   </mx:Canvas>
  24.  </mx:Canvas>
  25. </mx:Application>

    執行效果:

    轉載請註明出處  http://ticore.blogspot.com/2007/09/flex-2.html

    <template> <view class="page-container"> <!-- 打开弹框的按钮 --> <!-- 遮罩--> <view class="mask" v-if="localShow" @click="hideDialog"></view> <!-- 弹框 --> <view class="dialog" :class="{ 'dialog-show': localShow }"> <view class="dialog-content"> <view class="dialog-header"> <text class="dialog-title">提示</text> <text class="close-icon" @click="hideDialog">×</text> </view> <view > <button @click="nextStep">下一步</button> <button @click="nextStep">下一步</button> </view> </view> </view> </view> </template> <script> export default { props: { showDialog: { type: Boolean, default: false, }, showModel: { type: Boolean, default: false, }, }, watch: { showModel(newVal) { // 监听父组件数据变化 this.localShow = newVal; }, }, data() { return { localShow: this.showDialog, // 本地副本 // 返回假数据 data: { }, }; }, created() { console.log("onload", this.showDialog); }, onload() { console.log("onload", this.showDialog); }, methods: { // 隐藏弹框 hideDialog() { this.localShow = false; this.$emit("update:show-model", false); // 通知父组件更新 }, }, }; </script> <style lang="scss" scoped> .page-container { padding: 20rpx; font-family: "PingFangSC-Regular", "PingFang SC", sans-serif; font-weight: 400; font-style: normal; color: #0d0d0d; background: #f3f5f8; } .mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 998; } .dialog { position: fixed; bottom: -100%; left: 0; width: 100%; height: calc(100% * 2 / 3); transition: bottom 0.3s ease; z-index: 999; display: flex; justify-content: center; align-items: flex-end; // bottom: 0; } .dialog-show { bottom: 0; } .dialog-content { background-color: #fff; width: 100%; height: 100%; border-top-left-radius: 10rpx; border-top-right-radius: 10rpx; padding: 30rpx; box-sizing: border-box; } .dialog-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 20rpx; border-bottom: 1rpx solid #ccc; } .dialog-title { font-size: 32rpx; font-weight: normal; text-align: center; flex: 1; } .close-icon { font-size: 36rpx; cursor: pointer; } .radio-group { margin-top: 60rpx; } .radio-item { display: flex; align-items: center; margin-bottom: 10rpx; font-size: 28rpx; } .radio-item radio { transform: scale(0.6); } .audit-status { display: flex; justify-content: space-between; align-items: center; margin-top: 25rpx; padding: 15rpx; padding-top: 30rpx; background-color: rgba(245, 246, 249, 1); border-radius: 15rpx; } .status-label { font-size: 28rpx; } .status-value { display: flex; font-size: 28rpx; } .audit-text { color: #d01212; } .audit-date { color: #666; margin-top: 10rpx; font-family: "PingFangSC-Regular", "PingFang SC", sans-serif; font-weight: 400; font-style: normal; color: #0d0d0d; } .dialog-footer { padding-top: 20rpx; text-align: center; margin-top: 25rpx !important; } /deep/.next-button { width: 80%; padding: 10rpx; background-color: rgba(12, 195, 199, 1) !important; border: none !important; color: #fff !important; border-radius: 15rpx; font-size: 30rpx; } .titleName { margin-top: 40rpx; } .radioName { margin-top: 40rpx; } </style> 把按钮放在一排
    07-14
    <template> <div class="editor-layout"> <!-- 固定头部 --> <header class="app-header"> <button class="back-btn" @click="handleBack"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M19 12H5M12 19l-7-7 7-7"/> </svg> </button> <h1 class="app-title">AI笔记编辑器</h1> <div class="header-right"> <button class="history-btn" @click="toggleHistory"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <circle cx="12" cy="12" r="10"></circle> <polyline points="12 6 12 12 16 14"></polyline> </svg> <span>历史记录</span> </button> <div class="user-avatar" @click="goToProfile"> <div class="avatar-placeholder"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path> <circle cx="12" cy="7" r="4"></circle> </svg> </div> </div> </div> </header> <!-- 固定工具栏 --> <div class="fixed-toolbar"> <Toolbar :editor="editorRef" :defaultConfig="toolbarConfig" /> </div> <!-- 编辑器区域 --> <div class="editor-container"> <Editor v-model="valueHtml" :defaultConfig="editorConfig" @onChange="handleChange" @onCreated="handleCreated" @onDestroyed="handleDestroyed" @onFocus="handleFocus" @onBlur="handleBlur" @customAlert="customAlert" @customPaste="customPaste" /> </div> <!-- 历史记录侧边栏 --> <div class="history-sidebar" :class="{ active: showHistory }"> <div class="sidebar-header"> <h2>历史记录</h2> <button class="close-btn" @click="toggleHistory"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <line x1="18" y1="6" x2="6" y2="18"></line> <line x1="6" y1="6" x2="18" y2="18"></line> </svg> </button> </div> <div class="history-list"> <div v-for="(item, index) in historyItems" :key="index" class="history-item"> <div class="history-title">{{ item.title }}</div> <div class="history-date">{{ item.date }}</div> </div> </div> </div> <!-- 历史记录遮罩 --> <div v-if="showHistory" class="sidebar-mask" @click="toggleHistory"></div> </div> </template> <script setup> import { onBeforeUnmount, ref, shallowRef } from 'vue' import { Editor, Toolbar } from '@wangeditor/editor-for-vue' import '@wangeditor/editor/dist/css/style.css' // 编辑器实例 const editorRef = shallowRef() // 内容 HTML const valueHtml = ref('<h1>欢迎使用AI笔记编辑器</h1><p>这是一个功能强大的富文本编辑器,支持多种格式和功能。</p><p>尝试使用工具栏上的功能来编辑内容!</p>') // 编辑器配置 const editorConfig = { placeholder: '请输入内容...', MENU_CONF: { insertImage: { checkImage(src) { if (src.indexOf("http") !== 0) { return "图片网址必须以 http/https 开头"; } return true; }, }, } } // 工具栏配置 const toolbarConfig = { toolbarKeys: [ 'headerSelect', 'bold', 'italic', 'underline', 'through', 'color', 'bgColor', 'fontSize', 'fontFamily', 'lineHeight', 'bulletedList', 'numberedList', 'todo', 'justifyLeft', 'justifyRight', 'justifyCenter', 'insertLink', 'insertImage', 'insertTable', 'codeBlock', 'blockquote', 'divider', 'emotion', 'undo', 'redo' ] } // 历史记录相关状态 const showHistory = ref(false) const historyItems = ref([ { title: 'AI生成的学习笔记', date: '2023-10-15 14:30' }, { title: '项目会议记录', date: '2023-10-14 09:45' }, { title: '技术方案设计', date: '2023-10-12 16:20' }, { title: '读书笔记 - 人工智能导论', date: '2023-10-10 11:15' }, { title: '周计划安排', date: '2023-10-08 08:30' } ]) // 编辑器回调函数 const handleCreated = (editor) => { editorRef.value = editor console.log("编辑器已创建", editor) } const handleChange = (editor) => { console.log("内容变化:", editor.children) } const handleDestroyed = (editor) => { console.log('编辑器已销毁', editor) } const handleFocus = (editor) => { console.log('编辑器获得焦点', editor) } const handleBlur = (editor) => { console.log('编辑器失去焦点', editor) } const customAlert = (info, type) => { alert(`【系统提示】${type} - ${info}`) } const customPaste = (editor, event, callback) => { console.log('粘贴事件', event) callback(true) // 继续默认的粘贴行为 } // 及时销毁编辑器 onBeforeUnmount(() => { const editor = editorRef.value if (editor == null) return editor.destroy() }) // 头部按钮功能 const handleBack = () => { alert('返回操作') } const toggleHistory = () => { showHistory.value = !showHistory.value } const goToProfile = () => { alert('跳转到个人用户管理界面') } </script> <style> /* 基础样式重置 */ * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } .editor-layout { position: relative; height: 100vh; overflow: hidden; background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%); } /* 固定头部样式 */ .app-header { position: fixed; top: 0; left: 0; right: 0; height: 60px; display: flex; align-items: center; padding: 0 20px; background: #ffffff; box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1); z-index: 1000; transition: all 0.3s ease; } .back-btn { width: 40px; height: 40px; border: none; background: none; cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; } .back-btn:hover { background: #f0f5ff; transform: translateX(-2px); } .back-btn svg { width: 20px; height: 20px; color: #4a6cf7; } .app-title { flex: 1; text-align: center; font-size: 1.4rem; font-weight: 600; color: #1a1a1a; letter-spacing: 0.5px; } .header-right { display: flex; align-items: center; gap: 15px; } .history-btn { display: flex; align-items: center; gap: 6px; padding: 8px 15px; background: #f0f5ff; border: none; border-radius: 20px; color: #4a6cf7; font-weight: 500; font-size: 0.9rem; cursor: pointer; transition: all 0.2s ease; } .history-btn:hover { background: #e1e9ff; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(74, 108, 247, 0.2); } .history-btn svg { width: 18px; height: 18px; } .user-avatar { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 4px 10px rgba(118, 75, 162, 0.3); } .user-avatar:hover { transform: scale(1.05); box-shadow: 0 6px 15px rgba(118, 75, 162, 0.4); } .avatar-placeholder { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.2); } .avatar-placeholder svg { width: 18px; height: 18px; color: white; } /* 固定工具栏样式 */ .fixed-toolbar { position: fixed; top: 60px; /* 在头部下方 */ left: 0; right: 0; z-index: 999; background: white; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); border-bottom: 1px solid #eaeef5; padding: 0 10px; } /* 编辑器容器样式 */ .editor-container { margin-top: 110px; /* 头部高度 + 工具栏高度 */ height: calc(100vh - 110px); overflow-y: auto; padding: 20px; background: white; border-radius: 12px; margin-left: 20px; margin-right: 20px; box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05); } /* 历史记录侧边栏 */ .history-sidebar { position: fixed; top: 0; right: -400px; width: 380px; height: 100vh; background: white; z-index: 2000; box-shadow: -5px 0 25px rgba(0, 0, 0, 0.1); transition: right 0.4s cubic-bezier(0.23, 1, 0.32, 1); display: flex; flex-direction: column; } .history-sidebar.active { right: 0; } .sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid #eee; } .sidebar-header h2 { color: #333; font-weight: 600; } .close-btn { background: none; border: none; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s ease; } .close-btn:hover { background: #f5f7fa; } .close-btn svg { width: 20px; height: 20px; color: #666; } .history-list { flex: 1; overflow-y: auto; padding: 15px; } .history-item { padding: 15px; border-radius: 8px; margin-bottom: 10px; background: #f9fbfd; transition: all 0.2s ease; cursor: pointer; border-left: 3px solid #4a6cf7; } .history-item:hover { background: #edf3ff; transform: translateX(5px); } .history-title { font-weight: 500; color: #1a1a1a; margin-bottom: 5px; } .history-date { font-size: 0.85rem; color: #666; } /* 历史记录遮罩 */ .sidebar-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.4); z-index: 1500; backdrop-filter: blur(2px); } /* 响应式设计 */ @media (max-width: 768px) { .app-header { padding: 0 10px; } .app-title { font-size: 1.1rem; } .history-btn span { display: none; } .editor-container { margin-left: 10px; margin-right: 10px; padding: 15px; } .history-sidebar { width: 85%; } } /* 滚动条美化 */ ::-webkit-scrollbar { width: 8px; } ::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; } ::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; } ::-webkit-scrollbar-thumb:hover { background: #a8a8a8; } </style> 我是说这个编辑器调宽一点,然后滚轮是页面的
    07-26
    <template> <div class="home-container"> <!-- 欢迎信息 --> <div class="welcome-section"> <h1 class="display-4">欢迎来到哇咔咔发饰铺</h1> <p class="lead">这里有各种各样的女士发夹,快来挑选吧!</p> <router-link to="/products" class="btn btn-primary btn-lg">浏览产品</router-link> </div> <!-- 特色推荐 --> <div class="feature-section"> <h2>特色推荐</h2> <div class="feature-items"> <div class="feature-item"> <img src="@/assets/clips1.jpg" alt="经典黑曜石发夹" /> <h3>经典黑曜石发夹</h3> <p>优雅大气,适合多种场合。</p> </div> <div class="feature-item"> <img src="@/assets/clips2.jpg" alt="珍珠白晶发夹" /> <h3>珍珠白晶发夹</h3> <p>清新自然,彰显女性魅力。</p> </div> </div> </div> </div> </template> <script> export default { name: 'Home' }; </script> <style scoped> /* 自定义背景颜色 */ .home-container { width: 100%; height: 100vh; /* 设置容器高度为视口高度 */ background-image: url('@/assets/logo2.jpg'); /* 使用本地图片路径 */ background-size: cover; /* 确保图片覆盖整个容器 */ background-position: center; /* 将图片居中显示 */ background-repeat: no-repeat; /* 防止图片重复 */ display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; /* 文字颜色设为白色以便于阅读 */ position: relative; /* 用于伪元素定位 */ } /* 添加半透明遮罩效果 */ .home-container::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); /* 黑色背景,透明度为 0.5 */ z-index: -1; /* 确保遮罩在内容后面 */ } /* 欢迎信息样式 */ .welcome-section { text-align: center; margin-bottom: 50px; } .display-4 { font-size: 3rem; /* 标题字体大小 */ font-weight: bold; /* 加粗标题 */ color: #ff69b4; /* 标题颜色(粉红色) */ } .lead { font-size: 1.2rem; /* 副标题字体大小 */ margin-bottom: 20px; color: #ffffff; /* 副标题颜色(白色) */ } .btn-primary { background-color: #ff69b4; /* 按钮背景颜色(粉红色) */ border-color: #ff69b4; /* 按钮边框颜色 */ color: #ffffff; /* 按钮文字颜色 */ padding: 10px 20px; /* 按钮内边距 */ font-size: 1rem; /* 按钮字体大小 */ border-radius: 20px; /* 圆角按钮 */ transition: all 0.3s ease; /* 添加平滑过渡效果 */ } .btn-primary:hover { background-color: #ff1493; /* 按钮悬停时的颜色(更深的粉红) */ border-color: #ff1493; /* 按钮悬停时的边框颜色 */ } /* 特色推荐样式 */ .feature-section { width: 80%; background-color: rgba(255, 255, 255, 0.9); /* 半透明白色背景 */ padding: 20px; border-radius: 10px; /* 圆角边框 */ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* 添加阴影效果 */ margin-top: 50px; text-align: center; } .feature-section h2 { font-size: 2rem; color: #333; margin-bottom: 20px; } .feature-items { display: flex; justify-content: space-around; flex-wrap: wrap; } .feature-item { width: calc(33% - 20px); margin: 10px; background-color: #ffffff; border-radius: 10px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); padding: 10px; text-align: center; transition: transform 0.3s ease; /* 添加平滑过渡效果 */ } .feature-item:hover { transform: scale(1.05); /* 鼠标悬停时放大效果 */ } .feature-item img { max-width: 100%; height: auto; border-radius: 10px; margin-bottom: 10px; } .feature-item h3 { font-size: 1.2rem; color: #333; margin-bottom: 5px; } .feature-item p { font-size: 0.9rem; color: #666; } </style>背景图片透明度再调低
    06-09
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值