Two auto width flexbox columns with only one that wraps - html

I have two auto width flexbox columns displayed inline. I expect to have dynamic content in the columns so I am trying to figure out a way to wrap only the first column which contains the menu items.
I know I can wrap both of them using the "flex-wrap" class on the "d-flex" div but I only want to wrap the first auto width column while keeping the two columns inline of each other.
I am using Bootstrap 4 CSS which already contains the flexbox classes I am using, please see an example on the fiddle I've provided.
My desired result would be something like this image example:
https://jsfiddle.net/j9v70qvy/
<div id="header-middle">
<div class="container">
<div class="row align-items-center">
<div class="header-middle-mobile-menu-outer col col-auto hidden-md-up">
<a class="header-middle-mobile-menu-toggle">
<i class="fa fa-bars"></i>
</a>
</div>
<div class="logo-outer col col-auto">
<div class="logo-image">
<a href="#">
<img src="https://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0ahUKEwiamcGxuM3VAhUTwWMKHVWaBgMQjRwIBw&url=http%3A%2F%2Fwww.freepik.com%2Ffree-vector%2Flogo-sample-text_701628.htm&psig=AFQjCNEHXsgvhjDI__g4Vk4GETXnCeRu6A&ust=1502481095339508">
</a>
</div>
</div>
<div class="d-flex col pl-0 pr-0 align-items-center justify-content-end justify-content-md-start">
<div class="flex-wrap header-middle-menu-outer col col-auto hidden-sm-down">
<nav class="header-middle-menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Blog</li>
<li>Sample Page</li>
<li>Terms and Conditions</li>
<li>Privacy Policy</li>
</ul>
</nav>
</div>
<div class="header-middle-social-media-icons-outer col col-auto">
<nav class="header-middle-social-media-icons text-center icons-circle icons-sm">
<ul class="social-media-icons">
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-instagram"></i></li>
<li><i class="fa fa-youtube"></i></li>
<li><i class="fa fa-envelope"></i></li>
</ul>
</nav>
</div>
</div>
</div>
</div>

Okay, I think I finally figured out what the deal is. The Bootstrap defaults for some classes you have are different from what you want in this case.
You need to override the default styling for .col-auto on .header-middle-menu-outer. It is the flex-shrink value of 0 in the shorthand flex property that is killing you. Since the columns aren't allowed to shrink, you're getting things pushed off the side of the screen, and no wrapping is happening.
The default flex styling will suffice for .header-middle-menu-outer, so you can just use this in your CSS:
.header-middle-menu-outer.col {
flex: initial;
}
That will set things back to the default of flex: 0 1 auto, which will mean that the left column will be allowed to shrink while the right column will continue not shrinking. So the left column will wrap, and the right won't.
I would say you could simply strip away the col-auto class (which you may do anyway), but then you'd fall back to the styling for .col, which also includes the same problematic style: flex: 0 0 auto. So unless you want to remove that class too, you'll probably have to use an overriding style in your CSS either way.
Updated fiddle.
As a side note, I'd recommend you re-visit which classes you include on each element. If you inspect things in your browser console, you'll see that you have a lot of competing styles being applied by those classes, which aren't helping you out any. For example, .d-flex contains both justify-content-end and justify-content-md-start, which do exactly the opposite thing. But in this case, I believe you need neither. In the fiddle I linked above, if you delete both those classes, the layout doesn't change at all.
Also, the classes col-auto and col are very similar. In the case above for .header-middle-menu-outer, even though removing col-auto won't fix your problem, you might do it anyway because I'm not sure that class is really adding anything at this point.
I suspect there are many classes you could eliminate and then if there is a certain style rule for one of those removed classes that you want to include, just drop that in your stylesheet as a one-off.

Related

<li> in the bottom of sidebar

Image of the sidebar
Hello, how I can put the "Déconnexion" element at the bottom of the sidebar, whatever the screen size of the user.
My code looks like that :
<div class="sidebar">
<div class="profil">
<div class="photo-profil">
<img src="img/users_pdp/zenitsu.jpg" alt="photo-profil">
</div>
<div class="nom">
<span>User</span>
</div>
</div>
<ul class="nav-links">
<li>Ma liste</li>
<li class="genres-li"><a>Genres <span class="arrow_carrot-down"></span></a>
</li>
<li>Films</li>
<li>Séries</li>
<li>Animes</li>
<li>Mon compte</li>
<li class="sign-out"><i class="fa fa-sign-out" aria-hidden="true"></i> Déconnexion</li>
</ul>
</div>
Looking from your image, it looks like you have absolute position for your sidebar.
Since you need the nav-list to take up entirety of the available space, you can make use of flex.
Make your sidebar as a display:flex, with flex-direction: column to retain the layout.
add flex: 1 to your nav-links to make it use of available space.
Change display property of nav-links to flex and direction as column
Add margin-top: auto to your sign-out to move it to the bottom.
Here is a working codepen example.

Align btn-block buttons with bootstrap

I've since yesterday a bootstrap bug that I don't understand.
I put 2 buttons in a div with a flex display and an align-items-center but the second one is lower than the first one and I can't make the adjustment to correct it.
My code:
<div class="d-flex justify-content-center align-items-center mt-1">
<i class="fas fa-cart-arrow-down"></i>
<i class="fas fa-store"></i>
</div>
My result:
This is due to the class .btn-block. As per bootstrap's documentation:
Create block level buttons—those that span the full width of a parent—by adding .btn-block.
And to space out multiple block buttons vertically, _buttons.scss in bootstrap has:
.btn-block+.btn-block {
margin-top: .5rem;
}
So in your code, margin top is getting applied to the second button's btn-block class.
<i class="fas fa-store"></i>
You can either add below style to second button or modify class names depending on your requirement.
margin-top: 0;
Bootstrap is designed so that consecutive btn-block's stack vertically which is not happening because of the flex container. Instead of using btn-block inside the flex parent, use flex-grow-1...
<div class="d-flex justify-content-center align-items-center mt-1">
<i class="fas fa-cart-arrow-down"></i>
<i class="fas fa-store"></i>
</div>
https://codeply.com/p/gtjiTMOt76

Margin effecting center aligned items in flexbox row

I'm pretty new when it comes to flexbox but it seems a lot of properties work the same way.
However, when it comes to align items center I'm used to the way inline-block handles margins where it creates a space within the whole row even if it's on a specific element.
With flexbox it seems to only move that element off the axis. Fiddle attached, let me know if I am doing something wrong here. Using bootstrap css with only a few other styles to show what's going on.
https://jsfiddle.net/fv1gm67f/3/
<div id="header-top">
<div class="container">
<div class="row flex-wrap align-items-center">
<div class="header-top-social-media-icons-outer col col-auto">
<nav class="header-top-social-media-icons text-center icons-circle icons-sm">
<ul class="social-media-icons">
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-instagram"></i></li>
<li><i class="fa fa-youtube"></i></li>
<li><i class="fa fa-envelope"></i></li>
</ul>
</nav>
</div>
<div class="header-top-menu-outer col col-auto">
<nav class="header-top-menu">
<ul id="menu-header-top-menu" class="menu">
<li>My Account</li>
<li>Sample Page</li>
<li>Blog Posts</li>
</ul>
</nav>
</div>
</div>
</div>
If i understood you correctly. You want to keep the 2 columns aligned vertically automatically. I think you can achieve this with the property align-self:baseline. Please add the following css class to your fiddle and you will see that whether you give margin bottom or top to the icons col, the right column will align itself based on that margin and keep in line.
.col-auto{
align-self:baseline;
}
Hope this answers your question.
[EDIT For More Explaination]
As per your comment you are correct that align-self is for items within flexbox. If you notice then your .flex-wrap class is putting display:flex on main container with has 2 columns child as flex items. And then you have display:flex on the inner nav ul as well which is nested. You needed to set the align-self to baseline for the parent flexbox in order for the 2 col items to align to each other.
Here is a very good article with complete guide to flexbox.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Hope this explanation gives more info to others as well.
Happy Coding :)
Give your social media icons a margin of 0.
.social-media-icons li {
margin-bottom:0px;
}
As Russell Alan alluded to, it is a box model issue. The padding-top and padding-bottom on the ul.social-media-icons element is throwing the y axis off. The li elements also have a margin-bottom that adds to the issue. The following CSS should fix the issue:
CSS
/*This is so you can get a visual on exactly what the boxes are doing*/
.col-auto {
background-color: #CCC;
border: solid 1px #000;
}
ul.social-media-icons {
padding-top: 0;
padding-bottom: 0;
}
.social-media-icons li {
margin-bottom: 0;
}
jsFiddle
Ultimately, however, I think it might be best to set a min-height on the .row.flex-wrap children.
display: inline-block; margin-bottom: Npx does not affect the centering of other display: inline-block elements within a common parent element.
https://jsfiddle.net/dkoadaya/
I modified your fiddle above to center some inline-block elements and show that the behavior is the same.

Bootstrap - Display Image in Top Bar

I've searched the forums, but couldn't find the exact problem.
I'm using bootstrap on a template, and I'm trying to add an image in the top bar ('topbar' - not the navigational bar).
For some reason, the image is never shown.
Here's the code (all the rest besides the image works fine):
<section id="topbar">
<div class="container">
<div class="row">
<div class="col-sm-12 topbar-base no-padding">
<!--Top Bar Block-->
<div class="col-sm-8 col-md-6 topbar-block left text-left">
<ul>
<li><i class="fa fa-clock-o"></i>Mon - Sat: 09.00 - 19.00</li>
<li>Company inc.</li>
<li>**<img src="flag.png" alt="" height="27px" />**</li>
<li><i class="fa fa-phone"></i>+1 929 425 3919 </li>
<li><i class="fa fa-envelope"></i>info#company.com </li>
</ul>
</div>
<!--Top Bar block-->
<div class="col-sm-4 col-md-4 col-md-offset-2 topbar-block text-right">
<ul class="social">
<li><i class="fa fa-facebook"></i> </li>
</ul>
</div>
</div>
</div>
</div>
Thank you very much in advance. I've tried a lot of things, but can't seem to get it to work.
Much appreciated,
Lance
It's probably because the value of the height attribute of your image is 27px. It should be just 27.
From the html5 specification:
The attributes, if specified, must have values that are valid non-negative integers.
By the way, this should preferably stored in a css file.
There is also other errors, like the href attribute href="tel:+1 929 425 3919" which is not valid. Use an html validator to get rid of those errors.
The img tag inside "topbar-block" is referencing an image "flag.png" in the same directory as your .html file is. So make sure the image is in the same folder. The code seems correct otherwise.

twitter bootstrap margin-left -20px issue

I'm having an issue using twitter bootstrap on my webpage http://scrapp.site90.com/ . Header is wrapped in container and has .row around it, but seems that because of margin-left: -20px this row cannot align with other content. Is it possible to fix it? I tried to change value of margin-left, but then layout gets really messed up.
Instead of using the span* you could use pull-left on the H1..
<div class="row">
<h1 class="pull-left">Take a look at our work to see what we mean</h1>
<div>
<ul class="social inline pull-right">
<li>..</li>
</ul>
</div>
</div>