简体   繁体   English

我不能让我的按钮内容居中

[英]I can't keep my button content to stay centered

Im workin on a project and whenever the button is clicked it moves along side the text that appears underneath it.我正在处理一个项目,每当单击按钮时,它就会沿着出现在其下方的文本旁边移动。 Ive been working on this for the past few hours messing around and can't seem to figure it out.在过去的几个小时里,我一直在努力解决这个问题,但似乎无法弄清楚。 Im trying to have the button stay centered.我试图让按钮保持居中。 I tried align-items but it doesn't seems to work for me.我试过 align-items 但它似乎对我不起作用。

body {
    margin: 0;
    font-family: "Lato", sans-serif;
}

* {
    box-sizing: border-box;
}

a {
    color: black;
    text-decoration: none;
}

.app {
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    background-color: peachpuff;
}

.error,
.loading {
    margin: 22px;
    text-align: center;
}

.error {
    color: red;
}

.home-buttons-wrapper {
    display: flex;
    justify-content: space-between;

    a {
        border-radius: 5px;
        padding: 10px;
        width: 135px;
        text-align: center;
    }
}

button {
    font-size: 18px;
    padding: 15px 20px;
    margin-top: 40px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 2px 2px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s;
}
button:hover {
    transform: scale(1.125);
}
@keyframes fade {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.fade-animation {
    animation: fade 0.5s;
}

.fortune-text {
    display: flex;
    justify-content: center;

    .h4 {
        align-items: center;
    }
}

Although I can't tell the HTML structure and 'move along side the text' can mean different things, my guess is the items are re-aligning because their parent container's display is set as flex and the text is relatively positioning itself, making the flexbox react.尽管我无法分辨 HTML 结构并且“沿文本旁边移动”可能意味着不同的事情,但我的猜测是这些项目正在重新对齐,因为它们的父容器的display设置为flex并且文本本身相对定位,使得弹性盒反应。

You could try setting the position of your text to absolute or fixed , this should decouple the two elements' positions.您可以尝试将文本的position设置为absolutefixed ,这应该将两个元素的位置解耦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM