gpt4 book ai didi

javascript - 防止两个div成为一行

转载 作者:太空宇宙 更新时间:2023-11-04 07:38:51 25 4
gpt4 key购买 nike

我有两个 div 标签。在 style.css 文件中,我为按钮和按钮范围设置了属性。我想要的结果是,当我在 2 个 div 标签中创建 2 个按钮时,它会生成 2 行。但是当我在每个 div 中制作 2 个按钮时,它总是变成一行。我还为按钮和按钮范围设置了 display: block,但仍然没有得到正确的结果。

    .button {
display: block;
border-radius: 4px;
background-color: #f4511e;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 18px;
padding: 15px;
width: 200px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}

.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}

.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
white-space: pre;
}

.button:hover span {
padding-right: 30px;
}

.button:hover span:after {
opacity: 1;
right: 0;
}
button:focus {
outline:0;
}

div {
float: right;
}
<!DOCTYPE html>
<html style=''>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body style="width:550px;">
<div id='message' style="display: none;"></div>
<div id="hdqual"><button class='button'><span>Button 1</span></button></div>
<div id="sdqual"><button class='button'><span>Button 2</span></button></div>
</body>
</html>

最佳答案

.button {
display: block;
border-radius: 4px;
background-color: #f4511e;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 18px;
padding: 15px;
width: 200px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}

.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}

.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
white-space: pre;
}

.button:hover span {
padding-right: 30px;
}

.button:hover span:after {
opacity: 1;
right: 0;
}
button:focus {
outline:0;
}

.outer {
float: right;
}
<html style=''>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body style="width:550px;">
<div id='message' style="display: none;"></div>
<div class="outer">
<div id="hdqual"><button><span>Button 1</span></button></div>
<div id="sdqual"><button><span>Button 2</span></button></div>
</div>
</body>
</html>

如果你在 2 个按钮周围放置一个外部 div 并将其 float 到右侧,它也可以工作。

关于javascript - 防止两个div成为一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48701764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com