I am trying to implement a list where the user can select an element. I can select items but the "active" class is not removed from the previous ones. If I click in all of them, then all will be selected.
I am developing using twitter bootstrap and angular
<ul class="list-group" id="list-opponents">
<li *ngFor="let opponent of model.availableOpponents; let first = first" [class.active]="first" id="{{ opponent.id }}" data-toggle="list" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
<span class="mr-3">{{ opponent.name }}</span>
<img class="figure-img img-fluid rounded" src="{{opponent.photoUrl}}" />
</li>
</ul>
the produced html is the following:
<ul _ngcontent-c1="" class="list-group" id="list-opponents">
<!--bindings={ "ng-reflect-ng-for-of": "[object Object],[object Object"}-->
<li _ngcontent-c1="" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center active" data-toggle="list" id="1">
<span _ngcontent-c1="" class="mr-3">Me</span>
<img _ngcontent-c1="" class="figure-img img-fluid rounded" src="../../../assets/ana.JPG">
</li>
<li _ngcontent-c1="" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center" data-toggle="list" id="2">
<span _ngcontent-c1="" class="mr-3">You</span>
<img _ngcontent-c1="" class="figure-img img-fluid rounded" src="../../../assets/tininha.JPG">
</li>
</ul>
UPDATE: you can find a jsfidle here: https://jsfiddle.net/Bonomi/Lkz161er/7/
I figured out what the problem is. I can't use the ul li elements, I solved the problem using div and a:
<div class="list-group" id="list-opponents">
<a *ngFor="let opponent of model.availableOpponents; let first = first" [class.active]="first" id="{{ opponent.id }}" data-toggle="list" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
<span class="mr-3">{{ opponent.name }}</span>
<img class="figure-img img-fluid rounded" src="{{opponent.photoUrl}}" />
</a>
</div>
It works now.
Related
I am trying to fix these photos to be a tiny more centered. Maybe shift down a little and to the left. I am using all bootstrap and do not have any css attached to this. It is all working within the ul tags. Any help appreciated.
Page Screen Shot
<ul>
<li>
<a href="https://example.com" class="dropdown-header">
<strong>Example</strong><br />
<span class="megasubheader">| NEWS AND CONTENT </span>
</a>
</li>
<li class="dropdown-divider"></li>
<li class="list-group">
<a href="https://example.com" class="list-group-item mt-2" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<img id="imgsrc1" width="75px" height="75px" class="rounded mx-2">
<span id="Htitle1" style="font-size: 14px"></span>
</div>
</a>
<a href="https://example.com" class="list-group-item mt-2" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<img id="imgsrc2" width="75px" height="75px" class="rounded mx-2">
<span id="Htitle2" style="font-size: 14px"></span>
</div>
</a>
<a href="https://example.com" class="list-group-item mt-2" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<img id="imgsrc3" width="75px" height="75px" class="rounded mx-2">
<span id="Htitle3" style="font-size: 14px"></span>
</div>
</a>
</li>
</ul>
Use my-auto on your img element.
Would this help your situation ?
<div class="d-flex w-100 justify-content-between flex-row align-items-center">
<img id="imgsrc3" width="75px" height="75px" class="rounded me-2">
<span id="Htitle3" style="font-size: 14px"></span>
</div>
More over bootstrap spacing:
https://getbootstrap.com/docs/5.0/utilities/spacing/
I saw that your text is long, so that has an effect too on it, with less text for me it works fine. hope this helps.
After changing the size of my button with btn-sm, it has got misaligned with respect to the rest of the social icon buttons on my navbar. How would I recenter it?
I'm also using Angular 8 to manage the backend of my website (maybe that changes something in this case?); and my top navbar is of class navbar navbar-expand navbar-light bg-light flex-column flex-md-row.
<nav class="navbar navbar-expand navbar-light bg-light flex-column flex-md-row">
<a
class="navbar-brand mr-0 mr-md-2"
routerLink="/">
{{ title }}
</a>
<div class="navbar-nav-scroll">
<ul class="navbar-nav bd-navbar-nav flex-row">
<li
class="nav-item"
*ngFor="let itemNavbar of itemsNavbar">
<a
[routerLink]="itemNavbar['page']"
[routerLinkActiveOptions]="{exact: true}"
routerLinkActive="active"
class="nav-link p-2">
{{ itemNavbar[langNavbar] }}
</a>
</li>
</ul>
</div>
<ul class="navbar-nav ml-md-auto">
<li
class="nav-item"
*ngFor="let socialIcon of socialIcons">
<a
class="nav-link"
href="{{ socialIcon.link }}">
<i [ngClass]="socialIcon.icon"></i>
</a>
</li>
<div class="col-md">
<div ngbDropdown class="d-flex">
<button
class="btn btn-outline-secondary btn-sm"
id="dropdownBasic1"
ngbDropdownToggle>
{{ upperCaseFirstLetter(langNavbar) }}
</button>
<div
ngbDropdownMenu
aria-labelledby="dropdownBasic1">
<a
ngbDropdownItem
class="langToggle"
*ngFor="let language of languages"
(click)="onChangeLanguage(language)">
{{ upperCaseFirstLetter(language) }}
</a>
</div>
</div>
</div>
</ul>
</nav>
I couldn't really solve the problem, but one way to adjust the positioning of this button would be by adding more margin or padding to it. For example, mt will add margin to the top of the button, hopefully you will hit a big enough margin. In my case, I ended up using:
<a class="btn btn-outline-secondary btn-sm d-inline-block ml-2 mt-1 mr-3">
...
The number for each margin and padding is a multiplier for the $spacer variable found in node_modules/bootstrap/scss/_variables.scss. The $spacer variable has a 1rem measurement by default.
Whenever I've to use a long section name inside a container with a list for a small column (col-2). My text is getting beneath my fontawesome icon as shown below. Thanks in advance!
PFB the HTML code:
<ul class="js-scroll-nav list-group list-group-transparent list-group-flush list-group-borderless py-3 px-3">
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#online">
<i class="fas fa-play-circle fa-lg"></i> List Item Apple Strudel
</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#discourses"><i class="fas fa-play-circle fa-lg"></i> List Item PumpkinStrudel
</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#disciple"><i class="fas fa-play-circle fa-lg"></i> List Item BerryStrudel</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#yogic"><i class="fas fa-play-circle fa-lg"></i> List Item CokeStrudel</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#events"><i class="fas fa-play-circle fa-lg"></i> List Item DoritosStrudel</a>
</li>
</ul>
How can I leave space below fontawesome icon so that my text on the second line populates exactly below from where my first text starts as shown below:
Don't use for spacing. Use padding/margin as appropriate.
What we want to do here is set the a element to have position:relative and the icon to be positioned absolutely within it. Then in the a element we set the left padding appropriately to indent the text.
Adjust the values below to taste. Perhaps add your own classes instead of overriding bootstrap classes directly.
a.list-group-item-action {
position: relative;
padding-left: 30px;
}
.list-group-item-action i.fas {
position: absolute;
left: 10px;
}
.list-group {
width:30%;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<ul class="js-scroll-nav list-group list-group-transparent list-group-flush list-group-borderless py-3 px-3">
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#online">
<i class="fas fa-play-circle fa-lg"></i>List Item Apple Strudel
</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#discourses"><i class="fas fa-play-circle fa-lg"></i>List Item PumpkinStrudel
</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#disciple"><i class="fas fa-play-circle fa-lg"></i>List Item BerryStrudel</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#yogic"><i class="fas fa-play-circle fa-lg"></i>List Item CokeStrudel</a>
</li>
<li>
<a class="list-group-item list-group-item-action font-weight-medium mb-0 mb-md-2" href="#events"><i class="fas fa-play-circle fa-lg"></i>List Item DoritosStrudel</a>
</li>
</ul>
I store my navigation in a separate nav.blade.php file and use #include('includes.nav') to show the navigation in each page. This works great but I lose the ability to highlight the current pages.
This was resolved here beautifully.
I have a second navigation which doesn't use the bootstrap default active function, so I thought I'd address this here.
Page structure
I have a folder called user_admin with it's own bootstrap navigation stored in a file called nav_user_admin.blade.php.
This is then called into each page using #include('includes.nav_user_admin').
I include this in the head
#if(Request::is('route-name')) active #endif
Nav design
Each tab has bg-secondary with text-light. How would I then show bg-white and remove the text-light function when page active?
<div class="list-group list-group-flush ">
<a class="nav-link #if(Request::is('home')) active #endif" href="home" id="corner1" class="list-group-item d-flex justify-content-between align-items-center list-group-item-light list-group-item-action ">Dashboard</a>
<a class="nav-link #if(Request::is('groups')) active #endif" href="groups" class="bg-secondary text-light list-group-item d-flex justify-content-between align-items-center list-group-item-light list-group-item-action">Groups I've Created<span class="badge badge-light badge-pill">3</span></a>
<a class="nav-link #if(Request::is('')) active #endif" href="" class="bg-secondary text-light list-group-item d-flex justify-content-between align-items-center list-group-item-light list-group-item-action">Groups I've Joined<span class="badge badge-light badge-pill">8</span></a>
<a class="nav-link #if(Request::is('settings')) active #endif" href="settings" class="bg-secondary text-light list-group-item d-flex justify-content-between align-items-center list-group-item-light list-group-item-action">Account Settings</a>
<a class="nav-link #if(Request::is('profile_settings')) active #endif" href="profile_settings" class="bg-secondary text-light list-group-item d-flex justify-content-between align-items-center list-group-item-light list-group-item-action">Profile Settings</a>
</div>
The problem
Doing the above gives me a navigation with all tabs bg-secondary and all text blue? There is no difference between active and non active tabs.
Could be done like this
<a class="nav-link list-group-item d-flex justify-content-between align-items-center list-group-item-light list-group-item-action #if(Request::is('settings')) bg-white #else bg-secondary text-light #endif" href="settings">Account Settings</a>
Maybe I haven't styled it properly as you want but.
#if(Request::is('settings')) the classes you want when it is active #else the classes when it is not active #endif"
How can I float a fontawesome icon to the right and still have it vertically middle aligned? I've tried using ml-auto and Flexbox, but it's not working.
Here's my code:
<ul class="list-group flex-column">
<li class="list-group-item py-2 d-flex justify-content-start">
<a href="#">
<img src="https://placehold.it/40x40" height="40" class="mr-4">
<span>Text Here</span>
<i class="fa fa-angle-right ml-auto" aria-hidden="true"></i>
</a>
</li>
</ul>
Can someone help me out? Thanks!
Use the flex and sizing helper classes to make the link a flex parent with 2 children - the content you want on the left, and the content on the right. Use .justify-content-between, .align-items-center to separate the content so the arrow is on the right and centered vertically.
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="list-group flex-column">
<li class="list-group-item py-2 d-flex">
<a href="#" class="d-flex w-100 justify-content-between align-items-center">
<span>
<img src="https://placehold.it/40x40" height="40" class="mr-4">
<span>Text Here</span>
</span>
<i class="fa fa-angle-right ml-auto" aria-hidden="true"></i>
</a>
</li>
</ul>
Try with this structure:
<ul class="list-group">
<li class="list-group-item">
<a class="w-100 d-flex align-items-center py-2" href="#">
<img src="https://placehold.it/40x40" height="40" class="mr-4">
<span>Text Here</span>
<i class="fa fa-angle-right ml-auto" aria-hidden="true"></i>
</a>
</li>
</ul>
Click here to see it working in jsfiddle.
Your <a> tag doesn't fill the entire parent, so you can't see the effect of ml-auto on the icon. Also d-flex must be in the a tag, not in li.