css3中的outline,box-shadow和user-select总结

本文介绍了CSS中outline和box-shadow属性的应用技巧,包括如何使用outline突出元素边界而不影响布局,以及利用box-shadow实现圆角效果。同时探讨了user-select属性在用户交互中的作用。

1.outline属性

适用于:所有元素

继承性:无

取值:outline-color \ outline-style \ outline-width

outline画在border的外面outlines相关属性不占据布局空间,不会影响元素的尺寸;

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>outline测试</title>
    <style>
        .container{
            width:100px;
            height:100px;
            outline:5px solid red;
            border:2px solid blue;
        }
    </style>
</head>
<body>
<div class="container">
    注意外边框的红色轮廓
</div>
</body>
</html>

2.box-shadow属性

box-shadow: v-shadow  h-shadow  blur  spread  color  inset


如果需要设置outline的圆角可以通过box-shadow间接实现,代码如下

<style>
   .div{
        border-radius: 1px;
        box-shadow: 0 0 0 30px #cd0000;
   }
</style>
上述代码
box-shadow 中的30px 就是将1px的圆角扩展30px

3.user-select属性

none:文本不能被选择

text:可以选择文本

all:当所有内容作为一个整体时可以被选择。如果双击或者在上下文上点击子元素,那么被选择的部分将是以该子元素向上回溯的最高祖先元素。

element:可以选择文本,但选择范围受元素边界的约束


<style>
.test{padding:10px;-webkit-user-select:none;-moz-user-select:none;-o-user-select:none;user-select:none;background:#eee;}
</style>
</head>
<body>
<div class="test" onselectstart="return false;" unselectable="on">选择我试试,你会发现怎么也选择不到我,哈哈哈哈</div>
</body>



<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>圣遗物属性发送 - 逍遥网络</title> <style> :root { --primary-color: #4CAF50; --primary-hover: #45a049; --secondary-color: #f8f9fa; --text-color: #333; --light-text: #6c757d; --border-color: #ced4da; --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); --transition: all 0.3s ease; --error-color: #dc3545; --warning-color: #ffc107; --info-color: #17a2b8; --purple-color: #6f42c1; } * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, rgba(245, 247, 250, 0.9) 0%, rgba(195, 207, 226, 0.9) 100%); color: var(--text-color); line-height: 1.6; display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 20px; } .container { width: 100%; max-width: 1100px; background-color: rgba(255, 255, 255, 0.95); border-radius: 10px; box-shadow: var(--box-shadow); padding: 20px; } .header { text-align: center; margin-bottom: 20px; } h1 { color: var(--text-color); margin-bottom: 10px; font-weight: 600; text-shadow: 1px 1px 2px rgba(0,0,0,0.1); } .nav-tabs { display: flex; background: var(--secondary-color); border-radius: 8px; padding: 5px; margin-bottom: 20px; flex-wrap: wrap; } .nav-tab { flex: 1; padding: 12px 20px; text-align: center; background: none; border: none; cursor: pointer; border-radius: 6px; transition: var(--transition); font-weight: 500; min-width: 120px; } .nav-tab.active { background: var(--primary-color); color: white; } .tab-content { display: none; } .tab-content.active { display: block; } form { background-color: rgba(255, 255, 255, 0.9); padding: 30px; border-radius: 10px; box-shadow: var(--box-shadow); transition: var(--transition); } form:hover { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15); } .form-group { margin-bottom: 20px; } label { display: block; margin-bottom: 8px; font-weight: 500; color: var(--text-color); } input[type="text"], input[type="password"], input[type="number"], select { width: 100%; padding: 12px 15px; border: 1px solid var(--border-color); border-radius: 6px; font-size: 16px; transition: var(--transition); background-color: var(--secondary-color); } input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus, select:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2); } .attribute_entry { background-color: rgba(248, 249, 250, 0.8); padding: 15px; border-radius: 6px; margin-bottom: 15px; border: 1px dashed var(--border-color); position: relative; } .attribute_entry label { display: inline-block; margin-right: 10px; margin-bottom: 0; } .attribute_entry select, .attribute_entry input[type="number"] { width: auto; min-width: 200px; margin-right: 10px; } .remove_attribute { background-color: var(--error-color); color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer; font-size: 14px; transition: var(--transition); } .remove_attribute:hover { background-color: #c82333; } .btn { padding: 12px 24px; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; transition: var(--transition); font-weight: 500; margin: 5px; } .btn-primary { background-color: var(--primary-color); color: white; } .btn-primary:hover { background-color: var(--primary-hover); } .btn-info { background-color: var(--info-color); color: white; } .btn-info:hover { background-color: #138496; } .btn-warning { background-color: var(--warning-color); color: var(--text-color); } .btn-warning:hover { background-color: #e0a800; } .btn-purple { background-color: var(--purple-color); color: white; } .btn-purple:hover { background-color: #5a359a; } input[type="submit"] { width: 100%; padding: 15px; background-color: var(--primary-color); color: white; border: none; border-radius: 6px; font-size: 18px; font-weight: 500; cursor: pointer; transition: var(--transition); margin-top: 20px; } input[type="submit"]:hover { background-color: var(--primary-hover); transform: translateY(-2px); } .inputBox { text-align: center; margin-top: 20px; } .inputBox a { color: var(--primary-color); text-decoration: none; font-weight: 500; transition: var(--transition); } .inputBox a:hover { text-decoration: underline; color: var(--primary-hover); } #divMsg { text-align: center; margin-top: 15px; color: var(--light-text); font-size: 14px; } .note { font-size: 14px; color: var(--light-text); margin-top: 5px; font-style: italic; } .sdk-result { margin-top: 20px; padding: 15px; border-radius: 6px; text-align: center; display: none; } .sdk-result.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .sdk-result.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } .sdk-code { font-family: &#39;Courier New&#39;, monospace; font-size: 18px; font-weight: bold; background: #2c3e50; color: white; padding: 10px; border-radius: 4px; margin: 10px 0; letter-spacing: 1px; } .sdk-codes-list { max-height: 300px; overflow-y: auto; margin: 15px 0; padding: 10px; background: #f8f9fa; border-radius: 6px; border: 1px solid var(--border-color); } .sdk-code-item { padding: 8px; margin: 5px 0; background: white; border-radius: 4px; border-left: 4px solid var(--primary-color); } .table-container { overflow-x: auto; margin-top: 20px; background: white; border-radius: 8px; box-shadow: var(--box-shadow); } table { width: 100%; border-collapse: collapse; } th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border-color); } th { background: var(--secondary-color); font-weight: 600; } .status-used { color: var(--error-color); font-weight: bold; } .status-unused { color: var(--primary-color); font-weight: bold; } .batch-controls { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; } .batch-count { width: 100px; } .form-actions { display: flex; gap: 10px; margin-top: 20px; } .form-actions .btn { flex: 1; } @media (max-width: 768px) { form { padding: 20px; } .nav-tab { min-width: 100px; padding: 10px 15px; font-size: 14px; } .attribute_entry select, .attribute_entry input[type="number"] { width: 100%; margin-bottom: 10px; } .attribute_entry label { display: block; margin-bottom: 5px; } .form-actions { flex-direction: column; } .batch-controls { flex-direction: column; align-items: stretch; } .batch-count { width: 100%; } } </style> </head> <body> <div class="container"> <div class="header"> <h1>圣遗物兑换系统</h1> <div class="inputBox"> </div> </div> <!-- 兑换CDK标签页 --> <div id="sdk" class="tab-content active"> <form id="redeemForm"> <div class="form-group"> <label for="redeem_uid">UID:</label> <input type="text" id="redeem_uid" name="uid" required placeholder="请输入您的UID"> </div> <div class="form-group"> <label for="sdk_code">CDK兑换码:</label> <input type="text" id="sdk_code" name="sdk_code" required placeholder="请输入12位CDK兑换码"> <div class="note">请输入12位大写字母数字组成的CDK码</div> </div> <input type="hidden" name="action" value="redeem_sdk"> <input type="submit" value="兑换装备" class="btn btn-primary"> </form> <div id="divMsg">BY 逍遥网络 2025</div> <div id="redeemResult" class="sdk-result"></div> </div> </div> <script> // 标签页切换 function switchTab(tabName) { // 隐藏所有标签内容 document.querySelectorAll(&#39;.tab-content&#39;).forEach(tab => { tab.classList.remove(&#39;active&#39;); }); // 移除所有标签的激活状态 document.querySelectorAll(&#39;.nav-tab&#39;).forEach(tab => { tab.classList.remove(&#39;active&#39;); }); // 显示选中的标签内容 document.getElementById(tabName).classList.add(&#39;active&#39;); // 激活选中的标签 event.target.classList.add(&#39;active&#39;); // 如果是管理标签页,自动加载SDK列表 if (tabName === &#39;manage&#39;) { loadSDKList(); } } // 加载物品数据 function loadItems() { fetch(&#39;syxywl.cn-syw.txt&#39;) .then(response => response.text()) .then(data => { const lines = data.split(&#39;\n&#39;); const selects = document.querySelectorAll(&#39;#item_id, #sdk_item_id, #batch_item_id&#39;); selects.forEach(select => { // 清空现有选项(保留第一个提示选项) while (select.options.length > 1) { select.remove(1); } lines.forEach(line => { if (line.trim() !== &#39;&#39;) { const [value, text] = line.split(&#39;:&#39;); const option = document.createElement(&#39;option&#39;); option.value = value; option.textContent = text; select.appendChild(option); } }); }); }) .catch(error => console.error(&#39;加载物品数据失败:&#39;, error)); } // 加载主属性数据 function loadMainProps() { fetch(&#39;sx1-zsx.txt&#39;) .then(response => response.text()) .then(data => { const lines = data.split(&#39;\n&#39;); const selects = document.querySelectorAll(&#39;#mainPropId, #sdk_mainPropId, #batch_mainPropId&#39;); selects.forEach(select => { // 清空现有选项(保留第一个提示选项) while (select.options.length > 1) { select.remove(1); } lines.forEach(line => { if (line.trim() !== &#39;&#39;) { const [value, text] = line.split(&#39;:&#39;); const option = document.createElement(&#39;option&#39;); option.value = value; option.textContent = text; select.appendChild(option); } }); }); }) .catch(error => console.error(&#39;加载主属性数据失败:&#39;, error)); } // 加载属性数据 function loadAttributes() { fetch(&#39;sx2-fsx.txt&#39;) .then(response => response.text()) .then(data => { const lines = data.split(&#39;\n&#39;); const selects = document.querySelectorAll(&#39;.attr-select&#39;); selects.forEach(select => { // 清空现有选项(保留第一个提示选项) while (select.options.length > 1) { select.remove(1); } lines.forEach(line => { if (line.trim() !== &#39;&#39;) { const [value, text] = line.split(&#39;:&#39;); const option = document.createElement(&#39;option&#39;); option.value = value; option.textContent = text; select.appendChild(option); } }); }); }) .catch(error => console.error(&#39;加载属性数据失败:&#39;, error)); } // 页面加载完成后初始化数据 document.addEventListener(&#39;DOMContentLoaded&#39;, function() { loadItems(); loadMainProps(); loadAttributes(); // 绑定表单提交事件 document.getElementById(&#39;redeemForm&#39;).addEventListener(&#39;submit&#39;, handleRedeemSubmit); }); // 处理兑换SDK表单提交 function handleRedeemSubmit(e) { e.preventDefault(); const formData = new FormData(this); fetch(&#39;send_item.php&#39;, { method: &#39;POST&#39;, body: formData }) .then(response => response.json()) .then(data => { const resultDiv = document.getElementById(&#39;redeemResult&#39;); resultDiv.className = &#39;sdk-result &#39; + (data.success ? &#39;success&#39; : &#39;error&#39;); resultDiv.textContent = data.message; resultDiv.style.display = &#39;block&#39;; if (data.success) { this.reset(); setTimeout(() => { resultDiv.style.display = &#39;none&#39;; }, 5000); } }) .catch(error => { console.error(&#39;Error:&#39;, error); const resultDiv = document.getElementById(&#39;redeemResult&#39;); resultDiv.className = &#39;sdk-result error&#39;; resultDiv.textContent = &#39;网络错误,请重试&#39;; resultDiv.style.display = &#39;block&#39;; }); } </script> </body> </html> 优化显示UI 适配手机电脑平板
最新发布
11-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值