简体   繁体   English

引导样式未按预期工作

[英]Bootstrap Styling is not working as expected

In my current ASP.Net core I am trying to do the boot strap styling for search component on the page.在我当前的 ASP.Net 核心中,我正在尝试为页面上的搜索组件进行引导样式设置。 I want the UI to look like我希望 UI 看起来像

在此处输入图像描述

where the label/input box and the Search button to appear in the middle of the screen and the Create New To show in the same row but to appear right side of the screen其中标签/输入框和“搜索”按钮出现在屏幕中间,“新建”显示在同一行但出现在屏幕右侧

I have tried like below我试过如下

<div class="center">
    <form asp-action="Index" method="get">
        <div class="row">
            <div class="col-lg-12">
                <div class="row mb-3">
                    <div class="col-lg-4 col-md-2 form-check-inline mr-0">
                        <label class="col-auto" for="holiday"> Find by Holiday </label>
                        <input type="text" class="form-control" name="SearchString" value="@ViewData["CurrentFilter"]" />
                    </div>
                    <div class="col-lg-4 col-md-2  form-check-inline mr-0">
                        <input type="submit" value="Search" class="btn btn-info" />
                        <a class="btn btn-link" asp-action="Index">Back to Full List</a>
                    </div>
                    <div class="col-lg-4 col-md-2  form-check-inline mr-0" style="text-align:right">
                        <a class="btn btn-info" asp-action="Create">Create New</a>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

And the UI shows up like below UI 如下所示

在此处输入图像描述

Can anyone help say what is that I am missing why all the things appear so close, I tried adding the style="text-align:right" so the Create new will appear towards the right谁能帮忙说一下我错过了什么,为什么所有的东西都显得如此接近,我尝试添加style="text-align:right"以便 Create new 将出现在右侧

***** EDIT ***** ***** 编辑 *****

在此处输入图像描述

You could try this way to implement accordingly as per your expectations like below:您可以尝试以这种方式根据您的期望进行相应的实施,如下所示:

Asp.net Submit Form With CSS

<div class="center">
    <form asp-action="Index" method="get">
        <div class="row">
            <div class="col-md-12">
                <div class="col-md-2">
                    <label class="col-auto" for="holiday" style="margin-top:10px;"> Find by Holiday </label>
                </div>
                <div class="col-md-3" style="margin-left: -50px;" >
                    <input type="text" class="form-control" name="SearchString" value="@ViewData["CurrentFilter"]" />
                </div>
                <div class="col-md-1">
                    <input type="submit" value="Search" class="btn btn-info" />
                </div>
                <div class="col-md-3">
                    <a class="btn btn-link" asp-action="Index">Back to Full List</a>
                </div>
                <div class="col-md-2">
                    <a class="btn btn-info" asp-action="Create">Create New</a>
                </div>
                <div class="col-md-1"></div>
            </div>
        </div>
    </form>
</div>

Output

在此处输入图像描述

Note: You could set your CSS in different class file. Note:您可以在不同的 class 文件中设置您的CSS I have shown you how could you achieve that using inline CSS snippet.我已经向您展示了如何使用内联CSS片段来实现这一点。 You could use separate file as well.您也可以使用单独的文件。 But this is the right and convenient way to do what you are trying to.但这是做你想做的事情的正确和方便的方法。

try adding ml-auto on the 'Create New' button尝试在“新建”按钮上添加ml-auto

My first guess is caused by your class 'col-md-2'.我的第一个猜测是由您的 class 'col-md-2' 引起的。 You can change all of 'col-md-2' to 'col-md-4' to test.您可以将所有 'col-md-2' 更改为 'col-md-4' 进行测试。

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

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