Terrance00
Terrance00

Reputation: 1678

Bootstrap 4 flex-row Sizing

Problem:

I'm building a complex (if you can call it that) ListGroup in bootstrap v4.

The .flex-row div has some unexplained space at the bottom, and I need to get rid of it.

What I've Tried:

Setting widths explicitly with (w-XX) and setting align-items style seems to work, but I feel like I'm missing something and I want it done right.

PS: Even if the above is the right way to fix it, I still want to understand that pesky whitespace and why it is there.

PSS: I'm new at the flexbox styling so don't leave out "obvious" things.

Screenshots:

alt text

alt text

Snippet:

<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>
<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">

<div class="row">
  <div class="list-group col-12">
    <div class="list-group-item flex-column d-flex" style="align-items:unset;">
      <h4 class="m-2 list-group-item-heading"><span class="fa fa-fw fa-user"></span>Title Of Person</h4>
      <div class="d-flex flex-row">
        <div class="flex-column w-50">
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Job Title:</strong>
              </div>
              <div class="w-50">
                Job Title
              </div>
            </div>
            <hr/>
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Company Name:</strong>
              </div>
              <div class="w-50">
                Comp Name
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Language Preference:</strong>
              </div>
              <div class="w-50">
                ENG
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Birthday:</strong>
              </div>
              <div class="w-50">
                11/11/1990
              </div>
            </div>
            <hr />
          </div>
        </div>
        <div class="flex-column w-50">
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Mobile:</strong>
              </div>
              <div class="w-50">
                0123456789
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>E-Mail:</strong>
              </div>
              <div class="w-50">
                [email protected]
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Telephone:</strong>
              </div>
              <div class="w-50">
                0123456789
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Fax:</strong>
              </div>
              <div class="w-50">
                0123456789
              </div>
            </div>
            <hr />
          </div>
        </div>
      </div>
      <div class="m-2">
        <button class="btn btn-outline-primary">
                            <span class="fa fa-fw fa-edit"></span>Edit
                        </button>
        <button class="btn btn-outline-danger">
                            <span class="fa fa-fw fa-remove"></span>Remove
                        </button>
      </div>
    </div>

    }
  </div>

Upvotes: 1

Views: 866

Answers (2)

Carol Skelly
Carol Skelly

Reputation: 362380

The mystery white-space at the bottom is because the list-group-item has flex-flow: row wrap. Just use the flex-nowrap class to prevent this...

https://www.codeply.com/go/Hqseq6OTQd

<div class="list-group-item flex-column d-flex flex-nowrap align-items-stretch">
  ...
</div>

Also, the flex-column in the inner columns isn't doing anything unless you also include d-flex to make it display:flex. Perhaps it's not necessary.

Upvotes: 1

Vadim Ovchinnikov
Vadim Ovchinnikov

Reputation: 14012

This unwanted space comes from hr's margin-top. Set hr's margin-top to 0 and this space will be removed.

hr {
  margin-top: 0 !important;
}
<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>
<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">

<div class="row">
  <div class="list-group col-12">
    <div class="list-group-item flex-column d-flex" style="align-items:unset;">
      <h4 class="m-2 list-group-item-heading"><span class="fa fa-fw fa-user"></span>Title Of Person</h4>
      <div class="d-flex flex-row">
        <div class="flex-column w-50">
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Job Title:</strong>
              </div>
              <div class="w-50">
                Job Title
              </div>
            </div>
            <hr/>
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Company Name:</strong>
              </div>
              <div class="w-50">
                Comp Name
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Language Preference:</strong>
              </div>
              <div class="w-50">
                ENG
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Birthday:</strong>
              </div>
              <div class="w-50">
                11/11/1990
              </div>
            </div>
            <hr />
          </div>
        </div>
        <div class="flex-column w-50">
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Mobile:</strong>
              </div>
              <div class="w-50">
                0123456789
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>E-Mail:</strong>
              </div>
              <div class="w-50">
                [email protected]
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Telephone:</strong>
              </div>
              <div class="w-50">
                0123456789
              </div>
            </div>
            <hr />
          </div>
          <div class="m-2">
            <div class="flex-row d-flex">
              <div class="w-50">
                <strong>Fax:</strong>
              </div>
              <div class="w-50">
                0123456789
              </div>
            </div>
            <hr />
          </div>
        </div>
      </div>
      <div class="m-2">
        <button class="btn btn-outline-primary">
                            <span class="fa fa-fw fa-edit"></span>Edit
                        </button>
        <button class="btn btn-outline-danger">
                            <span class="fa fa-fw fa-remove"></span>Remove
                        </button>
      </div>
    </div>

    }
  </div>

Upvotes: 2

Related Questions