I have to use the justify-content: center to center the block to come in the center of their parent div. And if the content are more than it needs to be fit in the width, I need to use overflow-x: scroll so that all the blocks come in same line. The problem is some of the starting blocks get hidden using justify-content: center;
Note: I need to have all the content in the center if the number of blocks are limited to 3 or 4 or smaller number.
Please go through this link
.nav-tabs {
overflow-x: scroll;
border: 0;
display: flex;
align-items: stretch;
flex-wrap: nowrap;
justify-content: center;
}
.nav-tabs .nav-item {
width: 20%;
min-width: 198px;
float: left;
display: flex;
align-items: stretch;
text-align: center;
margin-bottom: 0;
}
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
</ul>
The overflow-x CSS property sets what shows when content overflows a block-level element's left and right edges. This may be nothing, a scroll bar, or the overflow content.
To prevent scrolling with this property, just apply the rule overflow: hidden to the body (for the entire page) or a container element. This hides all content beyond the element's border.
To fix this problem use flexbox auto margins, instead of justify-content . With auto margins, an overflowing flex item can be vertically and horizontally centered without losing access to any part of it.
The overflow property specifies what should happen if content overflows an element's box. This property specifies whether to clip content or to add scrollbars when an element's content is too big to fit in a specified area.
So, you may specify whether to show scroll bar, clip the content by using hidden value or overflow the content beyond the boundary of element. Similarly, you may deal with the content by overflow-y property if content overflows top and bottom edges of the block element.
There's a new keyword called safe in the CSS working draft that can be used with justify-content and align-items which will allow "safe" scrolling in case the content overflows And scrolling will work fine. But currently this is only supported by Firefox ( if this info has changed by the time you're reading this, please comment to let me know ).
For example, overflow: scroll hidden would set overflow-x to scroll and overflow-y to hidden. If you only want scrollbars to appear when there is more content than can fit in the box, use overflow: auto. This allows the browser to determine if it should display scrollbars.
Definition and Usage. The overflow-x property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the left and right edges.
I believe that you need wrap the ul
under a container. Please see my codepen here. I also pasted code here.
.nav-container {
width: 100%;
display: flex;
align-items: flex-start;
overflow-x: scroll;
}
.nav-tabs {
display: flex;
align-items: stretch;
flex-wrap: nowrap;
justify-content: center;
}
.nav-tabs .nav-item {
width: 20%;
min-width: 198px;
float: left;
display: flex;
align-items: stretch;
text-align: center;
margin-bottom: 0;
}
<div class="nav-container">
<ul class="nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-1">
<span class="iconWrapper"><i class="fa fa-facebook"></i></span>
<span class="iconText">TAB 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-2">
<span class="iconWrapper"><i class="fa fa-twitter"></i></span>
<span class="iconText">TAB 2</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#tab-3">
<span class="iconWrapper"><i class="fa fa-linkedin"></i></span>
<span class="iconText">TAB 3</span>
</a>
</li>
</ul>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With