简体   繁体   English

如何使用bootsrap将div放置在表单右上角之外?

[英]How to place a div outside the upper right corner of my form using bootsrap?

I got a form, and it displays some detail text about stuff in my application. 我得到了一个表单,它显示了有关应用程序中内容的一些详细文本。 Outside this form, I have a "add new item" button, which the user can click on to go to a new page to add a new item. 在此表单之外,我有一个“添加新项”按钮,用户可以单击该按钮进入新页面以添加新项。

This button is now placed on the upper left side corner outside of the form, and I'd like to move it to the other side (the right upper corner of the form). 现在,此按钮位于表单外部的左上角,我想将其移到另一侧(表单的右上角)。

In this case my button is the <router-link> since I'm using Vue.js, and the routing works fine, and it styles as a button. 在这种情况下,由于我使用的是Vue.js,因此我的按钮是<router-link> ,并且路由工作正常,并且样式类似于按钮。

I use bootstrap-4 in my vue.js application with css-only property. 我在vue.js应用程序中使用具有css-only属性的bootstrap-4。

I've tried "float: right; ", and adding 我尝试过“ float:right;”,然后添加

<div class="row"> <div class="col"></div></div>

to "force" the button to move through columns, but it doesen't work. “强制”按钮在列中移动,但是不起作用。

So this is how my code looks like now: 这就是我的代码现在的样子:

<div class="container-fluid">
   <div class="details">
     <div class="d-flex justify-content-md-center">
       <div class="row">
       <div class="col create-new-item-button">
         <div class="">
           <router-link
             class="btn btn-primary"
             style="margin-bottom: 30px"
             :to="{ name: 'Create new item' }"
           >Create new item </router-link>
         </div>
       </div>
     </div>
       <form>
<p>Text in my form and other stuff</p>
</form>
</div>
</div>
</div>

My css (other than bootstrap's own): 我的css(除了bootstrap自己的):

.details {
  width: 100%;
  position: relative;
}

form {
  background-color: white;
  margin-top: 30px;
  margin-bottom: 30px;
  padding-bottom: 50px;
border-style: solid;
border-color: black; 

}

.create-new-item-button {
  float: right;
}

What should I do to move it to make it to the upper right corner, outside the form? 我应该怎么做才能将其移动到表格外部的右上角?

if you want to put it outside .details try to give it position: absolute; 如果您想将其放置在.details之外, .details尝试赋予其position: absolute; left: 100%;

You can use position: absolute; right: 0; 您可以使用position: absolute; right: 0; position: absolute; right: 0; to the div with the class row on your custom css, just like this example: https://codepen.io/anon/pen/gNXxxb 到带有自定义CSS上的类行的div,就像下面的示例一样: https : //codepen.io/anon/pen/gNXxxb

I just added the "my-custom-class" to the row and edited it on the css 我刚刚在行中添加了“我的自定义类”,并在CSS上对其进行了编辑

You can easily achieve what you want by wrapping the button with anything displayed as block , eg, <p /> , <div /> and make its text-align:right; 您可以通过将按钮包装成任何显示为block的内容 (例如<p /><div />并将其设置为text-align:right;来轻松实现所需的功能text-align:right; . No floating, no absolute positioning needed. 无需浮动,无需绝对定位。

<div class="container-fluid">
    <div class="details">
        <p class="text-right">
            <router-link
              class="btn btn-primary"
              style="margin-bottom: 30px"
              :to="{ name: 'Create new item' }"
            >Create new item </router-link>
        </p>
        <form>
            <p>Text in my form and other stuff</p>
        </form>
    </div>
</div>

Ok, so the solution came to this: 好的,解决方案就这样了:

I took your advice and figured stuff out. 我接受了您的建议,并弄清楚了。 So, I moved the entire section of the button (column and everything) and placed it under the </form >` tag. 因此,我移动了按钮的整个部分(列和所有内容),并将其放置在</form >标签下。

Now it looks like this: 现在看起来像这样:

 <div class="container-fluid">
    <div class="details">
      <div class="d-flex justify-content-md-center">
        <form>
<p> Text in my form and other stuff</p>
     </form>
</div>
</div>
</div>
         <div class="d-flex flex-row-reverse">
            <div class="col ml-auto p-2 ">
                <router-link
                  class="btn btn-primary"
                  style="margin-bottom: 30px"
                  :to="{ name: 'Create new item' }"
                >Create new item</router-link>

            </div>
          </div>
      </div>

Thank you all for your help! 谢谢大家的帮助!

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

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