18910140161

html-css-center元素之间的空白?-堆栈溢出

顺晟科技

2022-10-19 12:34:16

118

我正试图将文本垂直居中(挠痒痒),你能给我一些建议吗?以防万一。

“显示”按钮应始终位于底部。

并且文本(Tickle)应该位于“搜索”按钮和“显示”按钮之间。

我没有计算机科学背景,这个小应用程序是为了移动。我很感激你的帮助。 谢谢。


顺晟科技:

body {
    margin: 0;
}

.level-buttons {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;
}

.level-button {
    padding: 10px 20px;
}

.search-button {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

#search-button {
    padding: 10px 40%;
}

.show-button {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

#show-button {
    position:absolute;
    bottom: 5%;
    padding: 10px 40%;
}

.word {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

.word-text {
    color: rgb(0, 94, 0);
    font-size: 32px;
}

将它们包装在一个新的div中,并使其成为flex-box。 重构一些重复的代码,就像bellow一样。

将此样式添加到类中

body {
    margin: 0;
}

.level-buttons {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;
}

.level-button {
    padding: 10px 20px;
}

.search-button {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

#search-button {
    padding: 10px 40%;
}

.show-button {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

#show-button {
    position:absolute;
    bottom: 5%;
    padding: 10px 40%;
}

.word {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

.word-text {
    color: rgb(0, 94, 0);
    font-size: 32px;
}

这应该有效。

结果

实现使用以下代码更新您的HTML

body {
    margin: 0;
}

.level-buttons {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;
}

.level-button {
    padding: 10px 20px;
}

.search-button {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

#search-button {
    padding: 10px 40%;
}

.show-button {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

#show-button {
    position:absolute;
    bottom: 5%;
    padding: 10px 40%;
}

.word {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

.word-text {
    color: rgb(0, 94, 0);
    font-size: 32px;
}

和您的CSS下面的

body {
    margin: 0;
}

.level-buttons {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;
}

.level-button {
    padding: 10px 20px;
}

.search-button {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

#search-button {
    padding: 10px 40%;
}

.show-button {
    margin: 20px auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

#show-button {
    position:absolute;
    bottom: 5%;
    padding: 10px 40%;
}

.word {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

.word-text {
    color: rgb(0, 94, 0);
    font-size: 32px;
}

享受!

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航