Below if an example of flexible item which you mentioned in the comment.
.button
is not immediate to parent having display:flex
, hence it won't be flexible. As you can check in the snippet.
If you remove the div with class button
, the <button>
will stretch itself, and will be considered flexible.
.header {
display: flex;
flex-direction: row;
background-color: skyblue;
}
.header .title {
text-align: center;
flex: 1;
}
.header .dropdown {
padding-left: 20px;
flex: 1;
margin-top: 20px;
}
.header .button {
flex: 1;
background-color: red;
border: none;
color: white;
padding: 20px;
text-decoration: none;
font-size: 18px;
margin: 4px 2px;
border-radius: 50%;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<div class="header">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Sort by Group
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">All Contacts</a></li>
<li><a href="#">Family</a></li>
<li><a href="#">Work</a></li>
</ul>
</div>
<div class="title">
<h2>All Contacts</h2>
</div>
<div id="addbutton">
<button class="button pull-right">+</button>
</div>
</div>
While here you will see that, property is assigned to id addbutton
, and it will work fine
.header {
display: flex;
flex-direction: row;
background-color: skyblue;
}
.header .title {
text-align: center;
flex: 1;
}
.header .dropdown {
padding-left: 20px;
flex: 1;
margin-top: 20px;
}
.header #addbutton {
flex: 1;
}
.header .button {
flex: 1;
background-color: red;
border: none;
color: white;
padding: 20px;
text-decoration: none;
font-size: 18px;
margin: 4px 2px;
border-radius: 50%;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<div class="header">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Sort by Group
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">All Contacts</a></li>
<li><a href="#">Family</a></li>
<li><a href="#">Work</a></li>
</ul>
</div>
<div class="title">
<h2>All Contacts</h2>
</div>
<div id="addbutton">
<button class="button pull-right">+</button>
</div>
</div>