Left, center and right align elements with flex and different width [duplicate] - html

This question already has answers here:
Center a flex item in a row when there are a different number of items on each side
(5 answers)
Closed 5 years ago.
JSFiddle
The point is to make left ul with max-width align left, center block without specified width be always centered (content of this ul may vary) and right ul be always floated to right with max-width in my top navbar.
The main problem is that when I specify widths for ul's flex properties dont't work as I expect: 3rd ul must be aligned to right while the 2nd should take as much space as posible in one line. It's ok with alignment but 3rd ul takes too much space (more than needed) and visually isn't floated to right. If a specify it's width to fix this center aligmnment of 2nd ul won't work. All elements have different width, as far as I know flex can handle only elements with equal width.
However, I guess this is a right bahaviour for flex.
HTML
<nav class="nav_wrapper" role="navigation">
<ul class="nav navbar-nav navbar-left">
<li data-item-id="nav-profile-menu">
<a id="menu_toggle"><i class="fa fa-bars"></i></a>
</li>
</ul>
<ul class="nav navbar-nav navbar-center">
<li data-item-id="nav-profile-menu">
<a class="summary" data-toggle="tooltip" title="" data-placement="bottom" data-original-title="usd">
<span class="summary-item">USD</span>
<span>
<i class="fa fa-arrow-circle-o-down red hidden-sm hidden-xs" aria-hidden="true"></i>
99 <span class="small-text hidden-sm hidden-xs">-0,0474</span>
</span>
</a>
</li>
<li data-item-id="nav-profile-menu">
<a class="summary">
<span class="summary-item">Brent</span>
<span>
<i class="fa fa-arrow-circle-o-down red hidden-sm hidden-xs" aria-hidden="true"></i>
99 <span class="small-text hidden-sm hidden-xs">-0,86%</span>
</span>
</a>
</li>
<li data-item-id="nav-profile-menu" class="hidden-xs">
<a class="summary">
<span class="summary-item">Ni</span>
<span>
<i class="fa fa-arrow-circle-o-up green hidden-sm hidden-xs" aria-hidden="true"></i>
105,00 <span class="small-text hidden-sm hidden-xs">1,29%</span>
</span>
</a>
</li>
<li data-item-id="nav-profile-menu" class="hidden-xs">
<a class="summary">
<span class="summary-item">Al</span>
<span>
<i class="fa fa-arrow-circle-o-up green hidden-sm hidden-xs" aria-hidden="true"></i>
2131,50 <span class="small-text hidden-sm hidden-xs">0,35%</span>
</span>
</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-auth">
<li data-item-id="nav-profile-menu">
<span>reg</span> <i class="fa fa-user-plus"></i><span></span>
</li>
<li data-item-id="nav-profile-menu" data-toggle="tooltip" title="" data-placement="bottom">
<span>auth</span> <i class="fa fa-sign-in"></i>
</li>
</ul></nav>

why you don't use flex + absolute and u use float?
Much cleaner and no need for clear after floats.
.nav_wrapper {
position: relative;
display: flex;
justify-content: center;
}
.navbar-left {
position: absolute;
left: 0;
}
.navbar-auth {
position: absolute;
right: 0;
}
and you can remove the width of ul

Related

Reduce Border bottom length

Hi I want to know that whether can i reduce length of border bottom. I have a div and i have given border-bottom: 2px to that div i want to reduce the length of border. Is this possible.
I have this nav-bar and i have given css to its div want to reduce length of border. How can i do that.
This is my html
<div class="row">
<div class="col-sm-12 col-xs-12 col-lg-12 col-md-12 welcome">
<ul class="nav navbar-nav navbar-nav-primary">
<li class="active">
<a href="#one" data-toggle="tab">
<i class="fa fa-map-marker" aria-hidden="true"></i> <span class="li-text">Location</span>
</a>
</li>
<li>
<a href="#two" data-toggle="tab">
<i class="fa fa-heartbeat" aria-hidden="true"></i> <span class="li-text">Heartbeats</span>
</a>
</li>
<li>
<a href="#three" data-toggle="tab">
<i class="fa fa-power-off" aria-hidden="true"></i>
<span class="li-text">Reboots</span>
</a>
</li>
<li>
<a href="#four" data-toggle="tab">
<i class="fa fa-compress" aria-hidden="true"></i>
<span class="li-text">Reconnects</span>
</a>
</li>
<li>
<a href="#five" data-toggle="tab">
<i class="fa fa-battery-full" aria-hidden="true"></i>
<span class="li-text">Charge</span>
</a>
</li>
</ul>
</div>
This is my CSS
.welcome {
border-bottom: 2px solid #bcbcbc;
margin-left: 10px;
}
Move the welcome class into the ul tag and it should do what you want :)
remove the border-bottom css from the class welcome
and use this;
ul.nav.navbar-nav.navbar-nav-primary {
border-bottom: 2px solid #ddd;
}
.welcome {
margin-left: 10px;
}
You can use this for set height and width for set length
.welcome{
width:1000px;
border-bottom:1px solid magenta;
height:100px;
}

How do I fix my lists so I don't have to toggle twice before the icon updates?

Basically what happens is when I load my page and then drop down either my outer collapsible menu (the .admin) or the nested collapsible menu (.unitsofstudy), it does not update the glyphicon I have set using the :after selector unless I toggle it twice.
Would anyone be able to take a look and see if they can spot where I have screwed this up; I have been at this for a few hours now trying to fix but with no success. If any more info is needed let me know.
HTML:
<div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
<ul class="nav menu" id="navmenu-sidebar">
<!-- Admin dropdown -->
<li>
<a class="admin" data-toggle="collapse" href="#admin"><i class="fa fa-tasks" style="margin-right: 16px;"></i>Admin</a>
<ul id="admin" class="nav collapse">
<li>
<a class="unitsofstudy" data-toggle="collapse" href="#unitsofstudy"> <i class="fa fa-book" style="margin-right: 12px;"></i>Units of Study</a>
<ul id="unitsofstudy" class="nav collapse">
<li>
<i class="fa fa-book" style="margin-right: 8px;"></i> View Units
</li>
<li>
<i class="fa fa-plus" style="margin-right: 10px;"></i> Create Unit Offerings
</li>
<li>
<i class="fa fa-plus" style="margin-right: 10px;"></i> Register Units
</li>
<li>
<i class="fa fa-plus" style="margin-right: 10px;"></i> Register Semesters
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
My CSS:
.admin:after, .unitsofstudy:after {
font-family: 'Glyphicons Halflings';
content: "\e114";
float: right;
color: grey;
}
.admin.collapsed:after, .unitsofstudy.collapsed:after {
content: "\e080";
}
You need to give your anchors an initial class of .collapsed
<li>
<a class="admin collapsed" data-toggle="collapse" href="#admin">
<i class="fa fa-tasks" style="margin-right: 16px;"></i>Admin
</a>
</li>
So class both admin and unitsofstudy to let bootstrap know the initial state of the menu is collapsed
Working example
http://codepen.io/jcoulterdesign/pen/6443069430f54e0b635e726c2cb9da02

Put "plus" picture near menu item [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
How to put "plus" picture near menu item ? Here is the link
move the <span class="collapse"> within the <a> tag
then to prevent the link from firing, within the function for collapse simply put
e.preventDefault; or return false;
If you are worried about their distance? look if the elements have width, if yes try to reduce it use display:inline-block, and changing width to min-width.you can wrap the text in a span and add little right margin if needed.
Your elements with class expand and collapse have an absolute positionning with top: 0; right: 0; That means its distance from the top and right edges (from its parent element) are 0 pixels.
What I would personally do in this case (not at all what would be recommended by CSS experts) would be removing the right rule from the class and add an inline style="left: ##px"inside each span.
On my screen, what works best is this combination :
<li class=" level0 nav-2 active level-top m-dropdown menu-style-dropdown parent">
<a href="http://45.55.85.113/products.html" class="level-top">
<span> <span class="category_icon fa fa-tags"></span>SHOP</span>
</a><span class="expand" style="left: 55px"><i class="fa fa-minus-circle"></i></span>
<ul class="level0" style="display: block;">
<li class=" level1 item classic nav-2-1 first parent">
<a href="http://45.55.85.113/products/furniture.html">
<span> <span class="category_icon fa fa-key"></span>Furniture</span>
</a><span class="collapse" style="left: 100px"><i class="fa fa-plus-circle"></i></span>
<ul class="level1">
<li class=" level2 nav-2-1-1 first">
<a href="http://45.55.85.113/products/furniture/patio-furniture.html">
<span>Patio Furniture</span>
</a>
</li>
<li class=" level2 nav-2-1-2">
<a href="http://45.55.85.113/products/furniture/cafe-chairs-and-barstools.html">
<span>Cafe Chairs and Barstools</span>
</a>
</li>
<li class=" level2 nav-2-1-3 last">
<a href="http://45.55.85.113/products/furniture/chairs-seating.html">
<span>Chairs & Seating</span>
</a>
</li>
</ul>
</li>
<li class=" level1 item classic nav-2-2 parent">
<a href="http://45.55.85.113/products/furniture-fixings.html">
<span>Furniture Fixings</span>
</a><span class="collapse" style="left: 135px"><i class="fa fa-plus-circle"></i></span>
<ul class="level1">
<li class=" level2 nav-2-2-4 first">
<a href="http://45.55.85.113/products/furniture-fixings/connectors.html">
<span>Connectors</span>
</a>
</li>
<li class=" level2 nav-2-2-5 last">
<a href="http://45.55.85.113/products/furniture-fixings/insert-nuts.html">
<span>Insert Nuts</span>
</a>
</li>
</ul>
</li>
<li class=" level1 item classic nav-2-3 last">
<a href="http://45.55.85.113/products/electrical.html">
<span>ELECTRICAL</span>
</a>
</li>
</ul>
</li>
or for short :
left: 55px;
left: 100px;
left: 135px;
respectively for Shop, Furniture and Furniture Fixing

Why I can't set width for nav tabs

I have navigation in div size col-md-4 , and I have 6 tabs, I can't to aline all tabs.
I can aline when I change font-size of text tabs, thats not good solution for me.
I tried to set width for each tabs, but not working.
How can I set width for some tabs to be small but second to be bigger.
Also i have padding when I hover on the end of navbar
http://i.imgur.com/9Px4qqk.png
<nav class="row">
<ul class="nav nav-tabs">
<li class="tab1"> <span class="glyphicon glyphicon-user"></span> Name &nbsp &nbsp<span class="glyphicon glyphicon-chevron-down"></span> </li>
<li><span class="glyphicon glyphicon-flag"></span>Text Link </li>
<li> <span class="glyphicon glyphicon-envelope"></span> Message </li>
<li> <span class="glyphicon glyphicon-oil"></span>10 </li>
<li class="tab5"><span class="glyphicon glyphicon-asterisk"></span> </li>
<li><span class="glyphicon glyphicon-home"></span> </li>
</ul>
</div>
CSS
.nav-tabs li .tab5{
width:4%;
}
Your selector is wrong, you have to do this:
.nav-tabs li.tab5 {
width: 4%;
}
The class .tab5 is on the li tag, therefore you have to connect them.
Working Example
UPDATE
If you want to fit all in one row, try playing with the padding, like this:
.nav>li>a {
padding: 10px 3px;
}
Updated Example

Bootstrap list with badges: put icon right to the badge

I have a Twitter Bootstrap list with badges, and I have also added a delete icon I currently have two problems:
The badge is automatically situated to the right of the list row, and I want the delete icon to be after and not before the badge (I think it would look better that way). I guess I'm going to need to redefine the badge style, but don't know how to do that.
The delete icon is not vertically aligned correctly, and I haven't found the way to fix it either.
HTML:
<div class="panel-body">
<ul id="mylist" class="list-group">
<li id="item1" href="#" class="list-group-item">Item1 <span id="badge" class="badge">5</span>
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i>
</li>
<li id="item2" href="#" class="list-group-item">Item2 <span id="badge" class="badge">-10</span>
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i>
</li>
</ul>
</div>
Here is a JSFiddle with a small example of my situation.
Any help?
The bootstrap elements like pull-right have the property as:
float : right
Under this property, the Document Object Model is reversed. Like:
<span>First</span><i>Second</i>
would be displayed as: (Note Only Displayed as - DOM is still same.)
<i>Second</i><span>First</span>
Ans your Solution is JSFiddle is: http://jsfiddle.net/r77wkzcg/5/ (Updated)
In right Alignment, the point of connection is right. So, the first element in the DOM gets the priority to attach to the right. Explained here: http://jsfiddle.net/tpahadi/rrrr3wq3/1/
For your items use:
<li id="item1" href="#" class="list-group-item">Item1
<div class="pull-right">
<span id="badge" class="badge" style="float:left;">5</span>
<i class="fa fa-remove fa-2x" style="color: red;"></i>
</div>
</li>
Just put the icon after the badge, it depends of html elements order :
<li id="item1" href="#" class="list-group-item">
Item1
<span id="badge" class="badge">5</span> <!-- first -->
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i> <!-- second -->
</li>
And for the vertical centering of the delete icon, you can shift top the icon with a negative margin top (it's not clean but it work, just use a precise selector to avoid overriding all bootstrap elements)
See this fiddle
Put the fa-remove icon span first..
<div class="panel-body">
<ul id="mylist" class="list-group">
<li id="item1" href="#" class="list-group-item">
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i>Item1 <span id="badge" class="badge">5</span>
</li>
<li id="item2" href="#" class="list-group-item">
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i>Item2 <span id="badge" class="badge">-10</span>
</li>
</ul>
</div>
http://bootply.com/8wySK2DPfw