无法使用Flexbox对div进行右对齐

时间:2019-09-03 10:55:39

标签: css forms flexbox bootstrap-modal

我继承了我很欣赏的一个非常混乱的模态和形式,出于这个问题的目的,我将其简化为最基本的结构。

我一直在研究各种Flexbox教程和有关S.O的问题。然而,到目前为止,似乎还不容易完成对笔记和复选框进行右对齐的简单任务。

<div id="flexTest-modal" class="modal-fade-flexTestModal" data-keyboard="false" tabindex="-1" data-backdrop="static" role="dialog" aria-hidden="false" aria-labelledby="flexTest-modal-title" aria-describedby="flexTest-modal-content">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body pull-left" id="flexTest-modal-content">
                <div class="form-body">
                    <form method="POST" id="flexTestForm" action="${SampleAction}">
                        <ol class="nobullet">
                             <li><label class="label flexTestOption" for="${TestValue}"><input type="radio" name="RadioInputName" value="${TestValue}" id="${TestValue}" />    Test Value</label></li>
                        </ol>
                             <div class="to-right-justify" id="right-justified-id">
                                 <h5 for="flexTestNotes">Notes</h5>
                                 <label class="switch" class="pull-right"><input type="checkbox" id="togBtn" class="right-block"><div class="slider round" ><span class="on">On</span><span class="off">Off</span></div></label>
                             </div>
                </div>
                     <div class="modal-footer">
                     </div>
                    </form>
            </div>
        </div>
    </div>
 </div>

    .form-body {
  display: flex;
  flex-direction: row;

}

.to-right-justify  {
  justify-content: space-between;
  float: right;
}

JSFiddle:https://jsfiddle.net/kilo1981/qzhofsdk/25/

我需要列出项目:“测试值”保持左对齐(目前还可以)。但是,我需要与列表项处于同一级别的“注释”标题,仅需右对齐,并在“注释”标题下方选择打开/关闭复选框。

1 个答案:

答案 0 :(得分:0)

form {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.to-right-justify {
  justify-content: space-between;
  float: right;
}
<div id="flexTest-modal" class="modal-fade-flexTestModal" data-keyboard="false" tabindex="-1" data-backdrop="static" role="dialog" aria-hidden="false" aria-labelledby="flexTest-modal-title" aria-describedby="flexTest-modal-content">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body pull-left" id="flexTest-modal-content">
        <form method="POST" id="flexTestForm" action="${SampleAction}">
          <ol class="nobullet">
            <li><label class="label flexTestOption" for="${TestValue}"><input type="radio" name="RadioInputName" value="${TestValue}" id="${TestValue}" />    Test Value</label></li>
          </ol>
          <div class="to-right-justify" id="right-justified-id">
            <h5 for="flexTestNotes">Notes</h5>
            <label class="switch" class="pull-right"><input type="checkbox" id="togBtn" class="right-block"><div class="slider round" ><span class="on">On</span><span class="off">Off</span></div></label>
          </div>
          <div class="modal-footer">
          </div>
        </form>
      </div>
    </div>
  </div>
</div>