CSS float inside the list avoid unwanted padding - html

In my list element I want to place the control buttons aside, from the left of the list item text. In order to do that I use a property float: left;, it does the job, but when there are more than one line in a list, every new line has a padding of a size of the previous floating block:
The list is based on Vue.js & Bootstrap.
My CSS/HTML code:
<ul class="items">
<transition-group name="item">
<li v-for="item in items" :key="item.id" mode="out-in">
<span>
{{item.properties.NAME}}
</span>
<span style="float: left;">
<span class="fa fa-wrench"></span>Update
<span class="fa fa-trash-o"></span>Delete
</span>
</li>
</transition-group>
</ul>
How to display buttons inside the list on the right/left side of the list just one under the other?
The final result should be something like that:
Item #1_____________________________________Update___Delete
Item #2_____________________________________Update___Delete

Your issue should be solved by resetting or clearing the float that you’ve created. As you’re using bootstrap you can simply add the class clearfix to your li element that you have added float to. This will add a pseudo after element which will reset the flat after the element.
The final code snippet:
<ul class="items">
<transition-group name="item">
<li v-for="item in items" :key="item.id" mode="out-in" style="padding-bottom:10px;" clearfix>
{{item.properties.NAME}}
<span style="float: left;">
<span class="fa fa-wrench"></span>עדכן
<span class="fa fa-trash-o"></span>מחק
</span>
</li>
</transition-group>
</ul>

Try style="clear:left;". If that doesn't work, you would actually do the float or the clear left on the 'li' element, not on the span containing the buttons. This way each 'li' containing the buttons will contain the buttons themselves.
Try something to this affect below. Since there is not a JS Fiddle, editing code for what your needs are harder to edit.
<ul class="items">
<transition-group name="item">
<li v-for="item in items" :key="item.id" mode="out-in" style="float:left; clear:left; width:100%; display:block">
<span>
{{item.properties.NAME}}
</span>
<span>
<a href="#" class="btn btn-success btn-xs" #click="edit_item(item)">
<span class="fa fa-wrench"></span>Update</a>
<span class="fa fa-trash-o"></span>Delete
</span>
</li>
</transition-group>
</ul>
Kind of like this. Quick and dirty. Except on the elements, instead of inline styling, highly recommend CSS.
https://jsfiddle.net/y1x53zx2/1/

Related

<span> not starting where it starts where I want it to on new line

In the image you can see that if the title of the sidebar link is too long it goes to the next line. However it starts where the icon is located and not where the start of the span is. How would I style the class "side-nav-item" to where it will format where Administrator when it is shifted to the new line it starts where Give is.
<li class="side-nav-item">
<a data-bs-toggle="collapse" href="#userAccess" aria-expanded="false" aria-controls="userAccess"
class="side-nav-link">
<i class="uil-layer-group"></i>
<span>User Access</span>
<span class="menu-arrow"></span>
</a>
<div class="collapse" id="userAccess" data-bs-parent="#accordion">
<ul>
<li class="side-nav-item">
<a href="/task/add-location-access" class="side-nav-link">
<i class="uil-shield-check"></i>
<span> Give user access - Administrator</span>
</a>
</li>
<li class="side-nav-item">
<a href="/task/remove-location-access" class="side-nav-link">
<i class="uil-shield-slash"></i>
<span> Remove</span>
</a>
</li>
</ul>
</div>
</li>
Style <span> inside <a></a> as an inline-block. The behaviour you are seeing is expected from inline elements like <span> and <i>. Checkout concepts of inline elements, block elements and 'display' property in CSS. I am assuming you are new to HTML and CSS, so I suggest you begin with a good hands on video tutorial.
try this ,
<span
style="width:400px;text-align:start;height:max-content;"
>
Give user access - Administrator
</span>

Tab-Index for absolutely positioned elements in layout

Tab Index for Absolute-Position Elements
For the time being, lets assume I wrote the code below:
<header class="header hap" [ngClass]="authority">
<div class="header-inner">
<div class="header-identity">
<a id="theLogo" class="logo" [routerLink]="[links.home]" title="Navigate to Home">
<img src="assets/logo-white.svg" alt="Logo">
</a>
<span class="client-logo" *ngIf="user.brandingImage && !user.isTheAdmin()">
<img class="brandingImage" [src]="user.brandingImage" [alt]="user.brandingName" onerror="this.style.display='none'">
</span>
[ more links ]
</div>
<nav class="main-nav for authenticated" [ngClass]="{'active':showMenu, 'app-only':!isCurrPageAdminApp()}">
<button class="menu" (click)="toggleMenu()">Menu</button>
<div class="main-nav-flyout" *ngIf="showMenu">
<div class="nav-header">
<ul>
<li>
<a id="main-nav-profile" [routerLink]="['/profile']"><span class="icon icon-user2"></span> My Profile</a>
</li>
[ more dropdown items ]
</ul>
<a id="main-nav-close" class="close"(click)="onClickMenuClose()"><span class="icon-cross"></span></a>
</div>
<div class="nav-body">
<ul *ngIf="isCurrPageAdminApp()" class="main-nav-list">
<li class="current-app">Administrative Tools</li>
<li><a id="main-nav-xAdmin" *ngIf="user.isTheAdmin()" [routerLink]="['admin/x']">X Admin</a></li>
[ more links ]
<li>
<span>Reports</span>
<ul>
<li class="user-status"><a id="main-nav-userStatusReport" [routerLink]="['admin/reports/userStatus']">User Status</a></li>
[ more links ]
</ul>
</li>
</ul>
<ul class="app-list" *ngIf="user.userApplications">
<li *ngIf="showTheLink()">
<a id="app-list-type" [routerLink]="['/']">
...
</a>
</li>
[ more links ]
<li *ngFor="let application of user?.userApplications">
<a id="app-list-{{application.abbreviation}}" *ngIf="!isAdminApp(application)" (click)="onClickMenuItem(application)">
{{ application.title }}
</a>
</li>
</ul>
</div>
</div>
</nav>
<nav class="user-nav for authenticated" role="menu">
<span *ngIf="user.brandingName" class="user-location">{{user.brandingName}}</span>
<span *ngIf="user.brandingName" class="pipe">|</span>
<a id="user-nav-profile" class="user-name" [routerLink]="['/profile']">
<span class="name">{{user?.firstName}} {{user?.lastName}}</span>
</a>
<a id="user-nav-logout" class="logout" [routerLink]="['/', 'logout']">Log out</a>
</nav>
</div>
</header>
Issue
Various elements -- probably .header-inner > * -- are styled using position: absolute;, so the tabindex-order is skewed for elements which are declared later in the markup but positioned geometrically earlier in the layout.
Question
Is there a way to force the tabindex to be, say, all natural indices (0) except for 2 items that need to be switched -- in a scalable way while not having to implement tabindex for every new item in the layout?
The short answer is no, it's not possible to switch only two elements without at least adding tabindex to every element in the flow that has to be focused before those two elements.
All elements with positive tabindex will be focused first in an incremental way, or in their source order if they have the same value, and all elements with default value or zero will be focused last.
So if you have 6 focusable elements and you want to have elements 5 and 6 to be focused after elements 1 and 2, you need something like this:
<input type="text" tabindex="1">1</input>
<input type="text" tabindex="1">2</input>
<input type="text">3</input>
<input type="text">4</input>
<input type="text" tabindex="1">5</input>
<input type="text" tabindex="1">6</input>
In general having the source order match the flow is the easiest way to make it work.
There is one particular case that is simpler. If the elements you want to move happen to be the first elements that need focus on your page, then in that particular case you can put the tabindex only on those elements.
For instance, if we wanted elements 5 and 6 be the first elements on the page, and everything else after them, all you need to do is this:
<input type="text">1</input>
<input type="text">2</input>
<input type="text">3</input>
<input type="text">4</input>
<input type="text" tabindex="1">5</input>
<input type="text" tabindex="1">6</input>
So in general, if the elements you want to change order are in the header, and they are the first things that should be focusable on your page, it should be easy to rearrange them and let the rest of the page flow naturally.
If the elements had to be last you are out of luck, you should either:
Put them last in the markup so they flow naturally
Remove them from the flow with tabindex=-1 and let the user focus manually

How to find a span (has other html elements) with specific text

I am trying to find the list item based on the contents in the span.
I tried using //li/a[contains(., 'Business')]
It is working for unique items, But here, it gives a list because it is matching more than one.
I want to ignore the inner span and only focus on the span text to identify the li. How can i achieve it?
<li style="display: list-item;">
<a href="#">
<span class="avoidwrap">
<span class="icomoon-cube3">
</span>
Business
</span>
</a>
</li>
<li style="display: list-item;">
<a href="#">
<span class="avoidwrap">
<span class="icomoon-cube3">
</span>
Business Something
</span>
</a>
</li>
The answer given by splash58 in comments worked,
//li/a/span[normalize-space(.)='Business']

dropdown-menu to take whole width of body - bootstrap

I am trying to make the horizontal dropdown menu to take the whole width of the body. The dropdown-menu should start from the left in the following fiddle.
FIDDLE HERE
The Sub List 1 should start from the Logo+Text area and should flow till the li continues.
HTML:
<div class="container">
<div class="row">
<div class="col-md-12">
<div>
<span>Logo+Text</span>
</div>
<div class="btn-group" style="margin-left: 200px">
Lists
<ul class="dropdown-menu" role="menu">
<li>
Sub List 1
</li>
<li>
Sub List 2
</li>
<li>
Sub List 3
</li>
<li>
Sub List 4
</li>
<li>
Sub List 5
</li>
</ul>
</div>
</div>
</div>
</div>
Just use position: initial;to the parent class btn-group. if not working, then use !important.
View my demo on JSFIDDLE
Good practice is: Add a new class has_dropdown to btn-group. Then style by has_dropdown class. Try as my demo.
One way to do this would be to move your style="margin-left: 200px" CSS declarations to the dropdown-toggle anchor item, instead of the btn-group. That way, your container and consequently, your dropdown menu remains aligned to your logo while the trigger gets pushed to the right.

CSS: how to make two sections at the same line?

I'm trying to make these wo sections at the same line where the <ul> section at right and the <span> section, but, I can't find how.
PS: I use here bootstrap.
<ul class="pagination pagination-sm">
<li class="disabled">«</li>
<li class="active">1 <span class="sr-only">(current)</span></li>
<li>2 </li>
<li>3 </li>
<li>4 </li>
<li>5 </li>
<li>»</li>
</ul>
<span>
<span class="glyphicon glyphicon-plus"></span><span style="margin-left:10px;margin-right:6px;">Nouveau</span> |
<span style="margin-left:5px;"><span class="glyphicon glyphicon-arrow-up"></span><span style="margin-left:10px;"></span></span>|
<span style="margin-left: 5px;"><span class="glyphicon glyphicon-arrow-down"></span><span style="margin-left:10px;"></span></span>
</span>
Any suggestion, please ?
Thanks a lot !
Something like this would work:
EXAMPLE HERE
.pagination.pagination-sm + span {
vertical-align:top;
display:inline-block;
margin:25px 0 25px 10px;
}
Make the adjacent span element inline-block, align it to the top and add margins to match the .pagination element. This assumes that the markup will remain the same.
Try adding divisions around the two parts, and floating the two divisions next to each other. Here's a jsfiddle. See the CSS to see how to float.
<div class="cont-1">
... pagination code ...
</div>
<div class="cont-2">
... span and anchor codes ...
</div>
At the end of the code, make sure to clear your floats.
<div class="clear"></div>