在div类中右对齐元素 [英] Right align element in div class

查看:117
本文介绍了在div类中右对齐元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Bootstrap 4和



我也尝试了这个解决方案,从 StackOverflow

 < div class =container> 
< div class =asdf>
< p class =d-inline pull-right>一些文字< / p>

这两个解决方案都不会将元素移动到右侧。我做错了什么?

解决方案

我已经移除了类 pull-right 按钮 p 标记中添加$ c> class并添加 text-right 类到 div.container b
$ b

我认为这就是你需要的。 snippetdata-lang =jsdata-hide =falsedata-console =truedata-babel =false>

 < link rel =stylesheethref =https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap。 min.cssintegrity =sha384-rwoIResjU2yc3z8GV / NPeZWAv56rSmLldC3R / AZzGRnGxQQKnKkoFVhFQhNUwEyJcrossorigin =anonymous>< script src =https://code.jquery.com/jquery-3.1.1.slim.min.js integrity =sha384-A7FZj7v + d / sdmMqp / nOQwliLvUsJfDHW + k9Omg / a / EheAdgtzNs3hpfag6Ed950ncrossorigin =anonymous>< / script>< script src =https://cdnjs.cloudflare.com/ajax/libs /tether/1.4.0/js/tether.min.jsintegrity =sha384-DztdAPBWPRXSA / 3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrbcrossorigin =anonymous>< / script>< script src =https://maxcdn.bootstrapcdn。 com / bootstrap / 4.0.0-alpha.6 / js / bootstrap.min.jsintegrity =sha384 -vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk + 02D9phzyeVkE + jo0ieGizqPLForncrossorigin =anonymous>< / script>< div class =container text-right> < p class =d-inline>一些文字< / p> < button type =buttonclass =btn btn-primary d-inline> +< / button>< / div>  


I am using angular 2 with Bootstrap 4 and Angular Material. However, I am having trouble right align the elements inside my container div. I want both my button and text to be aligned to the right hand side

Here is what the code that I have tried to produce the result as shown in the photo

<div class="container">
  <div class="pull-right">
    <p class="d-inline pull-right">Some text</p>
    <button type="button" class="btn btn-primary pull-right">+</button>
  </div>
</div>

I have also tried this solution from StackOverflow

<div class="container">
  <div class="asdf">
    <p class="d-inline pull-right">Some text</p>
    <button type="button" class="btn btn-primary pull-right">+</button>
  </div>
</div>

.asdf {
  margin-left:auto; 
  margin-right:0;
}

Both of these solutions does not move the elements to the right. What am I doing wrong?

解决方案

I've removed the class pull-right class from both the button and the p tag and added text-right class to the div.container.

I think this is what you need.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>



<div class="container text-right">
    <p class="d-inline">Some text</p>
    <button type="button" class="btn btn-primary d-inline">+</button>
</div>

这篇关于在div类中右对齐元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆