如何在右侧显示多个按钮?

时间:2019-10-17 16:43:27

标签: javascript html css

我不知道为什么我的代码没有在右侧显示多个按钮。

在这里

.btn1 {
  background-color: #yellow;
  color: white;
  margin-right: 1px;
  float: right;
  border: none;
}

.test {
  position: relative;
  display: flex;
  margin-right: 1px;
  background-color: blue;
}
<!DOCTYPE html>
<html>

<body>
  <div class="test">
    <button class="btn1">Info</button>

    <div> write something here </div>

    <button class="btn1">Info 2</button>
    <div> write something here </div>
  </div>

</body>

</html>

预期结果。假设下面是屏幕

----------------------------------- |

        |Info| |Info 2|

----------------------------------- |

3 个答案:

答案 0 :(得分:0)

.btn1 {
  background-color: #yellow;
  color: white;
  margin-right: 1px;
  float: right;
  border: none;
  order:1;
}

答案 1 :(得分:0)

您的意思是这样的吗?您不清楚write something here文本在哪里。但是,这需要2个按钮,并将它们与条形图的右侧对齐。

.btn1 {
  background-color: #yellow;
  color: white;
  margin-right:1px;
  border: 0px;
  outline: none;
}
.test {
  position: relative;
  display: block;
  background-color:blue;
  text-align: right;
}
<div class="test">
     <button class="btn1">Info</button>

     <button class="btn1">Info 2</button>
  </div>
<div> write something here </div>
     <div> write something here </div>

答案 2 :(得分:0)

.test {
  display:flex;
  background:gray;
  align-items:center;
}

.child1 {
  flex-grow:1;
}
.child {
  padding-right:1rem;
}
<div class="test">

    <div class="child1">
    
          <div> write something here </div>
          <div> write something here </div>
          
    </div>
    
    <div class="child2">
    
          <button class="btn1">Info</button>
          <button class="btn1">Info 2</button>
          
    </div>

     
     
  </div>

相关问题