You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CSS Left属性不生效 我的世界客户端官网下载按钮定位及背景设置求助

我的世界客户端官网CSS问题修复说明

问题1:position定位属性不生效的修复

你现有代码存在两处导致定位失效的问题:

  • 第一处是CSS语法错误:button 规则未闭合,你写的button { margin: 20px; background-color: black; 后面缺少闭合的},导致后续所有CSS规则解析异常,这是最核心的原因
  • 第二处是布局约束:你给body设置了display: grid + place-content: center,会强制所有子元素居中对齐;同时按钮的position: relative是相对于自身原始位置偏移,如果你要相对于页面全局调整位置,需要将按钮的position属性改为position: absolute,脱离文档流后不受grid布局约束,此时设置left、top等属性即可自由调整位置。

问题2:给按钮添加背景的方法

你现有代码中.custom-btn规则里设置了background: transparent,将按钮背景强制设为透明,所以默认看不到背景。你可以直接修改这行配置,替换为你想要的背景样式即可:

  • 纯色背景示例:background: #ffffff; 即可设置白色默认背景
  • 背景图示例:background: url("你的背景图本地路径") center/cover no-repeat; 即可设置自定义背景图

修改后的完整代码

CSS代码

body {
    background-image: url('GLc.png');
    height: 100vh;
    width: 100vw;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    margin: 0;
    box-sizing: border-box;
    font-family: system-ui, sans-serif;
}

.btn-16 {
    border: none;
    color: #000000;
}
.btn-16:after {
    position: absolute;
    content: "";
    width: 0;
    height: 100%;
    top: 0;
    left: 0;
    direction: rtl;
    z-index: -1;
    box-shadow:
            -7px -7px 20px 0px #fff9,
            -4px -4px 5px 0px #fff9,
            7px 7px 20px 0px #0002,
            4px 4px 5px 0px #0001;
    transition: all 0.3s ease;
}
.btn-16:hover {
    color: #000000;
}
.btn-16:hover:after {
    left: auto;
    right: 0;
    width: 100%;
}
.btn-16:active {
    top: 2px;
}
.frame {
    width: 90%;
    margin: 40px auto;
    text-align: center;
}
button {
    margin: 20px;
    background-color: black;
}
.custom-btn {
    width: 130px;
    height: 40px;
    color: #fff;
    border-radius: 5px;
    padding: 10px 25px;
    font-family: 'Lato', sans-serif;
    font-weight: 500;
    /* 可自行修改为你需要的背景样式 */
    background: #ffffff;
    cursor: pointer;
    transition: all 0.3s ease;
    /* 修改为absolute实现全局定位 */
    position: absolute;
    /* 可自行调整left/right/top/bottom参数放到你想要的位置 */
    right: 100px;
    bottom: 150px;
    display: inline-block;
    box-shadow: inset 2px 2px 2px 0px rgba(255, 255, 255, .5),
    7px 7px 20px 0px rgba(0, 0, 0, .1),
    4px 4px 5px 0px rgba(0, 0, 0, .1);
    outline: none;
}

html {
    block-size: 100%;
    inline-size: 100%;
}

@media (orientation: landscape) {
    body {
        grid-auto-flow: column;
    }
}

HTML代码

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>GlC[v1]</title>
</head>
<body>
<button class="custom-btn btn-16">Download</button>
</body>
</html>

内容的提问来源于stack exchange,提问作者Anika

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 08:54:03