html - How can I hide flex items when it overflows the flex parent? -
html - How can I hide flex items when it overflows the flex parent? -
supposing have flexbox container content may overflow parent container. if item gets larger container amount hidden. if set overflow: hidden
hide overflowed portion of item, not entire item.
consider following:
<nav id="top-nav"> <div id="main-nav-container"> <div class="menu"> <ul> <li><a href="/">item 1</a></li> <li><a href="/">item 2</a></li> <li><a href="/">item 3</a></li> <li><a href="/">item 4</a></li> </ul> </div> <div class="menu"> <ul> <li><a href="/">other 1</a></li> <li><a href="/">other 2</a></li> </ul> </div> </div> </nav>
css:
class="lang-css prettyprint-override">#top-nav, #top-nav div.menu ul li { background-color: #444; } #main-nav-container { margin: 0 auto; max-width: 1200px; padding: 0 40px; display: -webkit-inline-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-box-pack: justify; -moz-justify-content: -moz-space-between; -ms-justify-content: -ms-space-between; justify-content: space-between; } #top-nav div.menu { -webkit-flex: 1; display: -webkit-inline-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; } #top-nav div.menu:last-child { display: -webkit-inline-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-justify-content: flex-end; -webkit-flex-direction: row; flex-direction: row; justify-content: flex-end; } #top-nav div.menu, #top-nav div.menu ul { text-align: left; alignment-baseline: baseline; margin: 0; padding: 0; } #top-nav div.menu ul { list-style: none; } #top-nav div.menu > ul { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; white-space: nowrap; } #top-nav div.menu li { -webkit-flex-shrink: 0; -moz-flex-shrink: 0; -ms-flex-shrink: 0; flex-shrink: 0; margin: 0 position: relative; font-size: 1.1em; cursor: pointer; } #top-nav div.menu ul li { color: #e6e6e6; text-decoration: none; display: block; padding: 7px; }
if window shrinks want "item 4" hide starts become overlapped "other 1".
once accomplish i'd need selector can target hidden.
jsfiddle setup here
a workaround problem add together next css code:
#top-nav div.menu > ul { flex-wrap: wrap; height: 34px; overflow: hidden; }
if want know elements got hidden, should solve problem using javascript/jquery, because cannot know using css.
html css css3 flexbox
Comments
Post a Comment