简体   繁体   English

bootstrap和input-groups:如何使输入变宽,wnen input-group-addon隐藏?

[英]bootstrap and input-groups: how to make input wider wnen input-group-addon is hidden?

I have a code similar to original Bootstrap example: 我有一个类似于原始Bootstrap示例的代码:

<div class="input-group">
  <input type="text" class="form-control" aria-describedby="basic-addon2">
  <span class="input-group-addon" id="basic-addon2">@example.com</span>
</div>

That will render this: 这将导致:

这将导致:

According to my user story, sometimes I do not need that button on the right. 根据我的用户故事,有时我不需要右侧的按钮。 If I attach to span with class "input-group-addon" an angular expression such as ng-show='showButtonOnTheRight' , and set that to false, the effect is that button will disappear, and input line will be still truncated at same position, and its corners will be not round. 如果我使用“ input-group-addon”类将span附加到ng-show ='showButtonOnTheRight'之类的角度表达式,并将其设置为false,则效果是该按钮将消失,并且输入行仍将被截断位置,并且其角不会圆。

I would like to achieve that effect that when I set showButtonOnTheRight=false , input changes so that the field looks like a regular bootsrap input, that is, takes full width and has round corners. 我想实现这种效果,当我设置showButtonOnTheRight = false时 ,输入会发生变化,以使该字段看起来像常规的bootsrap输入,即采用全角并具有圆角。 I do not want to use substitute different input, because I attach validation flags to given input's ID, so it is very much desirable to keep. 我不想使用替代输入,因为我将验证标志附加到给定输入的ID,因此非常需要保留。

A much cleaner way (and staying within angular only) is to simply also toggle the input class based on the show: 一种更简洁的方法(并且仅保持在角度范围内)是仅根据显示切换输入类:

<div ng-class="{ 'input-group': show }">

Here's the jsFiddle for it: http://jsfiddle.net/Lb7p538k/ 这是它的jsFiddle: http : //jsfiddle.net/Lb7p538k/

You can achieve this by adding the following css for .input-group 您可以通过为.input-group添加以下CSS来实现此目的

.input-group{
    width: 100%;
    border-radius: 5px;
    overflow: hidden;
}

JSFiddle 的jsfiddle

I used ng-if and @Aakash mentioned CSS to show text box depending upon the showButtonOnTheRight flag 我使用ng-if和@Aakash提到的CSS根据showButtonOnTheRight标志显示文本框

Here is my plunker link 这是我的朋克链接

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

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