Ben Beri
Ben Beri

Reputation: 1201

Best way to align multiple components in bootstrap card header in a row on left and right

img

There is a my card header. I have the leads count on the left, and on the right I have a filters button and a search bar.

Filters button has to be close to the search bar, while both of them are floating to the right, unlike the leads count which stays on the left.

<div class="card-header">
    <div class="row">
        <div class="col-lg-8 col-md-6 col-sm-4" style="padding-top: 8px;">
            <span class="panel-title"><span class="fa fa-users"></span> Leads: {{$count}}</span>
        </div>
        <div class="col-lg-2 col-md-2 col-sm-4">
            <button class="btn btn-primary" data-toggle="modal" data-target="#countryModal"><i class="fa fa-gear"></i> Filters</button>
        </div>
        <div class="col-lg-2 col-md-4 col-sm-4">
            <form role="search" method="get" action="{{ route('customers')}}">
                <div class="input-group">
                    @foreach(request()->query() as $key => $value)
                        @if($key == "page")
                            @continue
                        @endif
                        <input type="hidden" name="{{$key}}" value="{{$value}}">
                    @endforeach
                    <input type="text" name="search" class="form-control" placeholder="Search...">
                    <div class="input-group-btn">
                        <button class="btn btn-primary"><i class="fa fa-search"></i></button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

There is my HTML/Blade template code for my card header.

I used the bootstrap#row class with col-x-y to split the whole header into 3 parts, where the left part is the big part that will hold in a big margin so the small parts which are the filter + search bar will be on the right.

I have a feeling that this is wrong to do, not just because it looks bad.

What is the right way?

I can't simply do float left and float right because it breaks the align, and it will jump out of the header box.

Upvotes: 0

Views: 2244

Answers (1)

Alaksandar Jesus Gene
Alaksandar Jesus Gene

Reputation: 6887

What about this structure.. Did not see the output in full screen, but here is the jsfiddle link http://jsfiddle.net/0u61qtms/8/

<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <div class="card card-default">
                <div class="card-header">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>Lead: 1</div>
                        <div>
                            <button class="btn btn-primary d-inline-block mr-4">Filter</button>
                            <div class="form-group d-inline-block">
                                <input type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Upvotes: 1

Related Questions