Would create a list of items and align icon at the right.
<ul class=" list">
<li *ngFor="let group of groupList">
<div class="list-item"><span>{{ group.name }} (ID {{group.code}} ) </span></div>
<div class="trash-icon">
<img src="assets/img/icon_trash.png" height="20" width="20"/>
</div>
</li>
</ul>
In CSS:
.list-item {
width: 300px;
display : inline-block;
}
.trash-icon {
float: right;
}
.trash-icon::after {
clear: both;
}
The first line is aligned correctly, however, the following lines are indented.
Here's a screenshot:
When I replace float by right align:
Use the flexbox display for that.
<ul class="list">
<li *ngFor="let group of groupList">
<div class="list-item"><span>{{ group.name }} (ID {{group.code}} ) </span></div>
<div class="trash-icon"><img src="assets/img/icon_trash.png" height="20" width="20"/></div>
</li>
</ul>
Your styles
ul.list li {
display: flex;
justify-content: center;
}
ul.list li div.list-item {
flex: 1 1 auto;
}
ul.list li div.trash-icon {
flex: 0 0 20px;
}
have you tried to replace .trash-icon float with text-align
The answer to the original question
You don't really need ::after pseudoclass when you want to clear floated items, you can just do the following:
.trash-icon {
float: right;
clear: both;
}
And here is the example:
.list-item {
width: 300px;
display : inline-block;
}
.trash-icon {
float: right;
clear: both;
}
<li>
<div class="list-item">
<span>SPAN 1</span>
</div>
<div class="trash-icon">
<img src="https://cdn3.iconfinder.com/data/icons/free-social-icons/67/rss_circle_color-256.png" height="20" width="20"/>
</div>
</li>
<li>
<div class="list-item">
<span>SPAN 2</span>
</div>
<div class="trash-icon">
<img src="https://cdn3.iconfinder.com/data/icons/free-social-icons/67/rss_circle_color-256.png" height="20" width="20"/>
</div>
</li>
<li>
<div class="list-item">
<span>SPAN 3</span>
</div>
<div class="trash-icon">
<img src="https://cdn3.iconfinder.com/data/icons/free-social-icons/67/rss_circle_color-256.png" height="20" width="20"/>
</div>
</li>
Related
<div class="flex-container">
<div class="flex-row">
<li class="org-li" v-for="o in orgs">
<div class="flex-item">
<button v-b-modal.link_printer #click="click_org(o.id)" class="org-btn">
<img class="org-img" :src="`http://localhost:8080/orgs/org_pictures/${o.img}`" alt=""/>
</button>
</div>
<li class="printer-li" v-for="p in printers[o.id]">
<div class="flex-item">
<button variant="outline-primary" class="printer-btn" v-bind:org_id="`${o.id}`" v-bind:printer_id="`${p.id}`" #click="onClick(o.id, p.id, p.serial_number)" >
<img class="printer-img" :src="`http://localhost:8080/printers/printer_pictures/${p.img}`" alt=""/>
</button>
</div>
</li>
</li>
</div>
</div>
I want the org-img to be 55px x 55px and I want the printer-img to be 25px x 25px. Each org-btn and printer-btn should be centered vertically on the screen.
I have been having difficulties with the printer-img being slightly offset from being vertically aligned.
you can do it that way. This adds the CSS styles to your component's block. The .org-img and .printer-img styles will define the width and height of the images, and the .flex-item style will center the buttons within the div elements that contain them. And the .flex-container will wrap the content inside on overflow.
You can make adjustments as needed to match your component's specific structure and class naming.
<template>
<div class="flex-container">
<div class="flex-row">
<li class="org-li" v-for="o in orgs">
<div class="flex-item">
<button v-b-modal.link_printer #click="click_org(o.id)" class="org-btn">
<img class="org-img" :src="`http://localhost:8080/orgs/org_pictures/${o.img}`" alt=""/>
</button>
</div>
<li class="printer-li" v-for="p in printers[o.id]">
<div class="flex-item">
<button variant="outline-primary" class="printer-btn" v-bind:org_id="`${o.id}`" v-bind:printer_id="`${p.id}`" #click="onClick(o.id, p.id, p.serial_number)" >
<img class="printer-img" :src="`http://localhost:8080/printers/printer_pictures/${p.img}`" alt=""/>
</button>
</div>
</li>
</li>
</div>
</div>
</template>
<style>
.org-img {
width: 55px;
height: 55px;
}
.printer-img {
width: 25px;
height: 25px;
}
.flex-item {
display: flex;
align-items: center;
justify-content: center;
}
.flex-container {
display: flex;
flex-wrap: wrap;
}
</style>
I have a lot of links in a navbar. Most of the links are positioned to the left. I want to position some of the links to the right (right-side-login-cart). The part that is giving me trouble is that I can get the links to the right, but then cannot get the links to vertically align.
I've tried a bunch of different things to get it to work. For instance, I have float:right;, used transform to translate Y, and tried to used vertical align.
Some different attempts:
HTML
<div class="links-at-top">
<div class="links-div">
<a href="/">
<img src="example.com/img">
</a>
Link1
Link2
</div>
<div class="right-side">
<div class="positioning">
<a id="right-link-1">RightLink1</a>
<a id="right-link-2">RightLink2</a>
</div>
</div>
</div>
Attempt 1:
CSS:
.right-side {
padding-right: 50px;
display: inline-block;
}
.positioning {
position: absolute;
right: 0;
transform: translateY(-50%);
}
Attempt 2:
CSS:
.right-side {
padding-right: 50px;
display: inline-block;
}
.positioning {
vertical-align: middle;
}
Add your .right-side div into the same div as your other links so that they'll be on the same line. Then you can just float right.
.links-div {
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="links-at-top">
<div class="links-div">
<div>
Link1
Link2
</div>
<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png" alt="" />
<div>
<a id="right-link-1">RightLink1</a>
<a id="right-link-2">RightLink2</a>
</div>
</div>
</div>
You can consider using flex-box
.links-at-top{
display: flex;
justify-content:space-between;
align-items:center;
}
<div class="links-at-top">
<div class="links-div">
Link1
Link2
</div>
<div class="right-side">
<div class="positioning">
<a id="right-link-1">RightLink1</a>
<a id="right-link-2">RightLink2</a>
</div>
</div>
</div>
make .links-div and .right-side both display:inline-block, and float the right-side to right.
<div class="links-at-top">
<div class="links-div">
Link1
Link2
</div>
<div class="right-side">
<ul class="positioning">
<li> <a id="right-link-1">RightLink1</a></li>
<li> <a id="right-link-2">RightLink2</a></li>
</ul>
</div>
.right-side {
display: inline-block;
float:right;
}
.links-div{
display:inline-block;
}
Lets say I have the following:
<div class="card">
<ul class="list-group list-group-flush ">
<li class="list-group-item" style="border: none;">
<strong>Something</strong> : 12333434
</li>
<li class="list-group-item" style="border: none">
<strong>Something else</strong>: 2837487248723847283
</li>
<li class="list-group-item" style="border: none">
<strong>Some other stuff</strong>: 123442342423423
</li>
</ul>
</div>
Above looks like the following in browser:
However ideally I want it to look like the following (ignore the font change. I only care about the alignment):
Meaning the left side gets aligned to the right while the right side text gets aligned to the left.
How can I achieve this in bootstrap?
Using inline-block this can be achieved.By default strong is inline.
strong{
display:inline-block;
width:200px;
text-align:right;
}
Here is the fiddle link
Something like this would work, but requires set widths:
HTML:
<div class="card text-center">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="list-group-item-fixed">
<strong class="list-group-left">Something:</strong>
<span class="list-group-right">12333434</span>
</div>
</li>
<li class="list-group-item">
<div class="list-group-item-fixed">
<strong class="list-group-left">Something else:</strong>
<span class="list-group-right">2837487248723847283</span>
</div>
</li>
<li class="list-group-item">
<div class="list-group-item-fixed">
<strong class="list-group-left">Some other stuff:</strong>
<span class="list-group-right">123442342423423</span>
</div>
</li>
</ul>
</div>
CSS:
.list-group-item-fixed {
width: auto;
}
.list-group-left {
text-align: right;
width: 150px;
font-weight: bold;
display: inline-block;
}
.list-group-right {
text-align: left;
width: 200px;
display: inline-block;
}
Fiddle: https://jsfiddle.net/6nxtyv7b/
However, if you don't need a list, a simple table would suffice, and wouldn't need set widths:
HTML:
<div class="text-center">
<table class="table table-borderless table-centralised">
<tbody>
<tr>
<th>Something:</th>
<td>12333434</td>
</tr>
<tr>
<th>Something else:</th>
<td>2837487248723847283</td>
</tr>
<tr>
<th>Some other stuff:</th>
<td>123442342423423</td>
</tr>
</tbody>
</table>
</div>
CSS:
.table-centralised {
width: 0 auto;
}
.table-centralised th {
text-align: right;
width: auto;
}
.table-centralised td {
text-align: left;
width: auto;
}
Fiddle: https://jsfiddle.net/m06ek73u/
The text representing each image is currently located to the right of the image. I want the text to be centered underneath its corresponding image, how do I achieve this?
Please note that I applied display: inline-bock on the list items, so they are in a row.
#footer1 {
float: left;
width: 100%;
border: 10px solid #e3e3e3;
}
#footer1>ul>li {
padding: 0 8px;
display: inline-block;
}
#footer1 a:hover img {
border: 1px solid #5cadff;
text-decoration: none;
box-shadow: 5px 5px 2px 2px #5cadff;
}
#footer1 img {
border: 1px solid transparent;
margin-left: 110px;
}
<div id="footer1">
<h2> SOURCES </h2>
<ul>
<li>
<a href="https://www.wikipedea.com" title="wikipedia">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
w
</li>
<li>
<a href="https://www.google.com" title="google">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Google
</li>
<li>
<a href="https://www.youtube.com" title="youtube">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Youtube
</li>
<li>
<a href="https://www.nlm.nih.gov/" title="Nih.gov">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Nih
</li>
<li>
<a href="https://www.medindia.net" title="MedIndia.net">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
MedIndia
</li>
</ul>
</div>
I was able to do this without any changes to your existing HTML by doing this:
li{
display:inline-block;
text-align:center;
width:70px;
}
li img{
margin:0 10px;
}
The text-align centers all text and child elements inside the li. The width needs to be large enough that no caption will be too large to fit in that width. (If a caption won't fit in the allotted width, then the centering is wrecked.)
I added the left and right margin to the image for a little bit of future-proofing in case you later want to include a very short caption in your list. With that margin, even a very short caption will be forced to the next line (instead of next to the image) since 50 px image width + 10 margin on each side leaves no room for text.
Edited for float, keeps these inline and overflows if doesn't fit on page.
<style>
.container {
clear: both;
}
ul li {
width: 50px;
float: left;
text-align: center
}
ul li a {
text-decoration: none;
}
</style>
<div class="container">
<ul>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
</ul>
</div>
Please try this
HTML:
<div id="footer1">
<h2> SOURCES </h2>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
</div>
CSS:
div.item {
vertical-align: top;
display: inline-block;
text-align: center;
width: 120px;
}
img {
width: 100px;
height: 100px;
background-color: grey;
}
.caption {
display: block;
}
DEMO
I am trying to make my list items all the same width. I've tried setting the widths in the css and nothing changes. Can anyone figure this out?
Here is an image to show what I am talking about:
HTML:
<body>
<div class="content-wrapper" id="container">
<header>logo
<nav>navigation</nav>
</header>
<div class="clear-fix"></div>
<div id="body">
<section class="main-content">
<section class="leftPane">
<h2>Categories</h2>
</section>
<section class="rightPane">
<div class="checkout">
<h1>Checkout</h1>
<ul class="steps">
<li><a href="http://localhost:59213/Cart">
<div id="step0" class="arrow_box_grey">
Shopping Cart</div>
</a>
</li>
<li><a href="http://localhost:59213/Cart/Student">
<div id="step1" class="arrow_box_grey">
Student</div>
</a>
</li>
<li><a href="http://localhost:59213/Cart/Delivery">
<div id="step2" class="arrow_box_grey">
Delivery</div>
</a>
</li>
<li>
<div id="step3" class="arrow_box_green">Payment</div>
</li>
<li>
<div id="step4" class="arrow_box_blue">Finish</div>
</li>
</ul>
</div>
</section>
<div class="clear-fix"></div>
</section>
</div>
</div>
And here if my fiddle with the code: http://jsfiddle.net/M74Em/
You need to change this style:
.main-content .checkout ul.steps li div {
display: inline;
width: 1000px;
}
You can't set widths for inline elements so try this:
.main-content .checkout ul.steps li div {
display: inline-block;
width: 100px;
}
Example
From twBootstrap, applied to <ul>'s (demo):
.ul-justified {
display: table;
width: 100%;
table-layout: fixed;
border-collapse: collapse;
}
.ul-justified > li {
display: table-cell;
float: none;
width: 1%;
}
and slap .ul-justified to any ul-list you want aligned, and you get equal width <li>'s automatically fit parent ul's width.