简体   繁体   English

如何在下拉Bootstrap旁边放置箭头图像

[英]How can I position an arrow image next to dropdown Bootstrap

I am trying to position an image of arrow pointing downwards next to a dropdown select box. 我正在尝试在下拉选择框旁边放置向下箭头的图像。 I am using Bootstrap 3.0 css. 我正在使用Bootstrap 3.0 CSS。

With the following markup I am able to achieve what I am after but is not responsive (ie when I see it on chrome with mobile mode) the image is shoved below the dropdown. 使用以下标记,我可以实现我想要的功能,但没有响应(即当我在移动模式下的chrome上看到它),图像被拖到下拉列表下方。

My markup is below: 我的标记如下:

<div class="form-group">
            <label class="col-md-4 control-label">Package</label>
            <div class="col-md-3">
                    <select class="form-control" id="selPackage" ng-model="package"
                            ng-options="package.Name for package in packages"
                            >
                        <option value=""></option>
                    </select>

                {{package.Description}}
            </div>
            <div class="col-md-1 pull-left" style="margin-left:-20px;">
                <img src="./assets/bottom-arrow.png" class="img-responsive" style="width:40px;height: 40px;">

            </div>

        </div>

这就是Chrome / FireFox中的样子

But in Mobile mode it looks like this: 但是在移动模式下,它看起来像这样:

在此处输入图片说明

Could you please highlight the issue here? 您能在这里强调一下这个问题吗?

Not sure of the arrow - but the issue you are describing is simply that you have not set any xs or sm classes on the markup and so the bootstrap default is to display the columns as full rows at the smaller viewports (because you have not specified what to display them at). 不确定箭头-但是您要描述的问题只是您没有在标记上设置任何xs或sm类,因此引导程序默认为在较小的视口中将列显示为完整行(因为尚未指定)显示它们的位置)。

You will need to experiment to get the right layout for your needs - but it will have to include col-xs-X and col-sm-X classes in there. 您将需要进行实验以获取适合您需求的布局-但其中必须包含col-xs-X和col-sm-X类。 Also note that you have nested divs in there - so that the inner col-md-3 is actually 3 columns of the parent column. 还要注意,您在其中嵌套了div-这样内部col-md-3实际上是父列的3列。

<div class="form-group">
   <label class="col-xs-8 col-sm-10 col-md-4 control-label">Package</label>
      <div class="col-xs-8 col-sm-10 col-md-3">
         <select class="form-control" id="selPackage" ng-model="package" ng-options="package.Name for package in packages">
             <option value=""></option>
          </select>
           {{package.Description}}
        </div>
        <div class="col-xs-4 col-sm-2 col-md-1 pull-left" style="margin-left:-20px;">
         <img src="./assets/bottom-arrow.png" class="img-responsive" style="width:40px;height: 40px;">
  </div>

Don't use inline styling, put your CSS into a separate file and then include media queries to change the position at different viewports. 不要使用内联样式,将CSS放在单独的文件中,然后包含媒体查询以更改不同视口的位置。 That way you can control what different screen sizes will see depending on the size of the page. 这样,您可以控制根据页面尺寸看到的不同屏幕尺寸。 Bootstrap has a lot of responsive elements built-in too like the grid system . Bootstrap也内置了许多响应元素,例如网格系统

So in this instance, add a class onto your div around the arrow to target that and the image within it like this to move it around where you like, however you can also make use of the grid system to change the width of the select box and the arrow as well. 因此,在这种情况下,将一个类添加到箭头周围的div上,以该对象为目标,并以其中的图像将其移动到您喜欢的位置,但是您也可以利用网格系统来更改选择框的宽度和箭头。

<div class="form-group">

    <label class="col-md-4 control-label">Package</label>

    <div class="col-sm-3 col-md-3">
        <select class="form-control" id="selPackage" ng-model="package" ng-options="package.Name for package in packages">
            <option value=""></option>
        </select>
        {{package.Description}}
    </div>

    <div class="col-sm-1 col-md-1 pull-left select-arrow" style="margin-left:-20px;">
        <img src="./assets/bottom-arrow.png" class="img-responsive" style="width:40px;height: 40px;">
    </div>

</div>

I've added a class of select-arrow to the div around the arrow image and also add the col-sm class to both divs which will alter the width on small devices like mobiles. 我在箭头图像周围的div中添加了一个选择箭头类,并且还在两个div中添加了col-sm类,这将改变诸如移动设备之类的小型设备的宽度。 Take a look at the grid options which explains what class you can use and when. 看一下网格选项 ,它说明了可以使用什么类以及何时使用。

网格选项

Image of the Grid Options from the Bootstrap docs. Bootstrap文档中的Grid Options图像。

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

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