I have the following list and want to add another element to list element with Name. So I am adding Primary User but want the new element Primary User styled to the right of the line. What's the best way to do this? Is it awkward doing this to a list item? Thanks.
<div class="panel-heading">Company Details</div>
<ul class="list-group">
<li class="list-group-item"><b>Name:</b> <%= #company.name %><b>Primary User:</b><%= #company.primary %></li>```
One possibility would be to use float right. Don't know if it is the best one and there are probably plenty others, but it will work.
HTML
<div class="panel-heading">Company Details</div>
<ul class="list-group">
<li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
</li>
<li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
</li>
<li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
</li>
</ul>
CSS
.user {
float: right;
}
.list-group {
width: 250px;
}
https://jsfiddle.net/zy7d48ub/
Wrap your code inside this div wrapper and it should work.
<div class = "panel-heading-wrapper" style = "display: flex;">
I find myself using (maybe overusing?) css grid a lot for layouts such as this. It has so much flexibility for fine-tuning the layout. My approach would be:
<div class="panel">
<div class="panel-heading">
Company
</div>
<div class="name">
Name
</div>
<div class="user">
User
</div>
</div>
.panel {
display: grid;
grid-template-columns: 100px 100px;
grid-template-rows: 20px 20px;
grid-template-areas: 'heading heading''name user'
}
.panel-heading {
grid-area: heading;
}
.name {
grid-area: name;
}
.user {
grid-area: user;
}
here's what it looks like on jsfiddle
Related
I'am trying to display messages with the help of 'li' tag line by line .The main motive is to display our messages on right side whereas others on the left side in a react Chat app
but the problems is whenever I try with float left or float right , all the elements come into the same line like this
My react chat styling code is this
{this.state.chats.map(chat => (<div key={chat.timestamp}>
{this.state.user.uid === chat.uid ?(
<li className=" self" style={{listStyleType:"none",overflow:'hidden',marginLeft: 2 +'px',float:'right',display:'inline-block',
backgroundColor:"whitesmoke",margin:2 + "em",padding:13+'px',width:'max-content',borderBottomLeftRadius:11+'px',
borderBottomRightRadius:11+'px',borderTopLeftRadius:11+'px'}}>
<div className="message text-dark">{chat.content} </div>
</li>
):(
<li className="other" style={{listStyleType:"none",overflow:'hidden',marginLeft: 2 +'px',float:'left',display:'inline-block',
backgroundColor:"blanchedalmond",margin:2 + "em",padding:13+'px',width:'max-content',borderBottomLeftRadius:11+'px',
borderBottomRightRadius:11+'px',borderTopRightRadius:11+'px'}}>
<div className="message text-dark">{chat.content}</div>
</li>
)}
</div>
))}
Edit !: after floating individual div
.self {
background: orange;
float: right;
clear: both;
}
.other {
background: blue;
float: left;
clear: both;
}
<ul>
<li class="self">message</li>
<li class="self">message</li>
<li class="self">message</li>
<li class="self">message</li>
<li class="other">message</li>
<li class="other">message</li>
<li class="other">message</li>
<li class="self">message</li>
</ul>
https://developer.mozilla.org/en-US/docs/Web/CSS/clear
Check out the clear property for floated elements.
Flexbox solution:
.left {
display: flex;
justify-content: flex-start;
}
.right {
display: flex;
justify-content: flex-end;
}
<ul>
<li class="left">
Others message
</li>
<li class="right">
Your message
</li>
</ul>
Solution 2
Try <li> take up the whole line, and put float: left/right to the inner <div>
Something like: https://jsfiddle.net/L1g6wx34/
.left {
float: left;
}
.right {
float: right;
}
<ul>
<li>
<div class="left">
Others message
</div>
</li>
<li>
<div class="right">
Your message
</div>
</li>
<li>
<div class="right">
Your message
</div>
</li>
</ul>
I am looking for a way to place two elements next to each other. One element contains a link and the other element two buttons. If it is not possible to fit both elements without a line break, both should wrap at the same time:
big screen:
----------------------------------------------------------------------
https://this-is-a-link.com/with-a-slug c x |
https://this-is-a-link.com/with-a-long-long-long-long-long-slug c x |
----------------------------------------------------------------------
small screen:
-------------------------------------
https://this-is-a-link.com/with- c |
a-slug x |
https://this-is-a-link.com/with- c |
a-long-long-long-long-long-slug x |
-------------------------------------
What I want to avoid is a scenerio where one element would wrap, but the other would not:
-------------------------------------
https://this-is-a-link.com/with- c x |
a-slug |
https://this-is-a-link.com/with- c x |
a-long-long-long-long-long-slug |
-------------------------------------
I want to avoid this also:
-------------------------------------------------------------------
https://this-is-a-link.com/with-a-slug c |
x |
https://this-is-a-link.com/with-a-long-long-long-long-long-slug c |
x |
-------------------------------------------------------------------
The markup currently looks like this, but can be changed if needed
<ol>
<li>
<span class="link">https://this-is-a-link.com/with-a-slug</span>
<span class="buttons">
<button>c</button>
<button>x</button>
</span>
</li>
<li>
<span class="link">https://this-is-a-link.com/with-a-long-long-long-long-long-slug</span>
<span class="buttons">
<button>c</button>
<button>x</button>
</span>
</li>
</ol>
And here is a basic setup in a fiddle.
ol {
background: lightgrey;
max-width: 600px;
list-style-type: none;
}
li {
border: 1px solid black;
}
<ol>
<li>
<span class="link">https://this-is-a-link.com/with-a-slug</span>
<span class="buttons">
<button>c</button>
<button>x</button>
</span>
</li>
<li>
<span class="link">https://this-is-a-link.com/with-a-long-long-long-long-long-slug</span>
<span class="buttons">
<button>c</button>
<button>x</button>
</span>
</li>
</ol>
I tried various things I could think of, like making each li element flex or trying to put the whole list into a grid (trying various minmax() combinations), but I was never able to achieve the effect I would like to see as described above. I have always been running into situations where elements would rather wrap instead of taking the whole space or one element would wrap and the other would refuse to.
Check this: https://jsfiddle.net/6hwaL0zy/
li {
border: 1px solid black;
display: flex;
justify-content: space-between;
}
li .buttons {
text-align: right;
}
I think it fits your requirements but there's a intermedium case that you did not specify (when the second row wraps and the first doesn't)
ol {
background: lightgrey;
max-width: 600px;
list-style-type: none;
}
li {
border: 1px solid black;
}
.parent{
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
<ol>
<li class="parent">
<span class="link">https://this-is-a-link.com/with-a-slug</span>
<span class="buttons">
<button>c</button>
<button>x</button>
</span>
</li>
<li class="parent">
<span class="link">https://this-is-a-link.com/with-a-long-long-long-long-long-slug</span>
<span class="buttons">
<button>c</button>
<button>x</button>
</span>
</li>
</ol>
You can easily do this using bootstrap by making <div class="row"> and put two columns under it like 1 for your link and other for your two buttons.
for e.g:
<div class="row">
<div class="col-md-4">
your link code
</div>
<div class="col-md-4">
your buttons code
</div>
</div>
Add this to your CSS class
.buttons{
display: flex;
justify-content: flex-end;
}
Is it possible to truncate one specific inner span of a label, that contains multiple span elements, so that the label in total does not overflow into the next line?
I have prepared a JSFiddle for it on https://jsfiddle.net/keltik/k18892xe/3/, but for completeness I will also supply a part of the HTML/CSS here:
<html>
<body>
<div class="container">
<!-- First Spectre Accordion -->
<div class="container">
<div class="accordion">
<input id="accordion-1" name="accordion-radio" type="checkbox" hidden="">
<label class="accordion-header c-hand" for="accordion-1">
<i class="fas fa-angle-down"></i>
<span class="headline">some headline that needs to be truncated1, so that everything in the parent 'label' element remains in one line</span>
<span class="spacer"></span>
<span class="date">dont truncate me1</span>
</label>
<div class="accordion-body">
<ul class="menu menu-nav">
<li class="menu-item">Element 1</li>
<li class="menu-item">Element 2</li>
<li class="menu-item">Element 3</li>
</ul>
</div>
</div>
<!-- more accordions, same structure -->
</body>
</html>
The CSS file is like this, on my development machine I am using Scss though:
.container {
max-width: 400px;
}
I am using the spectre.css framework and it is already included in the aforementioned JSFiddle link.
I have already tried out these approaches, but could not get any of them working with label, multiple span elements and the specific spectre.css classes:
https://scottwhittaker.net/flexbox/2017/02/05/flexbox-and-text-truncation.html
https://westerndevs.com/css/Using-Overflow-Ellipsis-in-Inline-Flex/
How to use "text-overflow: ellipsis" with a label element?
I am looking for approaches using HTML/CSS without Javascript, if it is possible.
I would appreciate your help.
You can try the use of white-space:nowrap and flexbox like this:
label {
display: flex;
max-width: 400px;
border: 1px solid;
overflow: hidden;
}
label > span {
white-space: nowrap;
flex-shrink: 0; /*This span will never shrink*/
margin: 0 5px;
}
span.tru {
flex-shrink: 1;/*allow this one to shrink*/
/*Hide the overflow*/
overflow: hidden;
text-overflow: ellipsis;
}
<label>
<span>lorem don't truncate</span>
<span class="tru"> truncate me truncate me truncate me truncate me truncate me v truncate me truncate me truncate me</span>
<span>don't truncate me</span>
</label>
I've got a menu with 3 levels of deepness. It starts with the categories, then the subcategories, and after all, the final links. Some of these links are already in the second or even the first level, but that's not a problem. The menu is working fine.
The problem is that I'm trying to make it look fancy, so I added to each div a class that designates the menu level. You can see the full Angular template here. Mind that these classes are the "lvl0", "lvl1", "lvl2":
<div class="menu-container">
<div class="row header">
<img class="logo" src="../../../assets/menu-header.PNG">
</div>
<div class="row menu-btn">
<div class="inner-menu-btn" (click)="openMenu()">
<span class="menu-span" [#menuStringAnim]="active">MENU</span>
<i class="fa fa-bars menu-icon" [#menuIconAnim]="active"></i>
</div>
</div>
</div>
<div class="menu-list" [#menuListAnim]="active">
<div class="row row-fix lvl0" *ngFor="let category of getCategories()" (click)="openCategory(category)">
<div class="little-menu-bar-toplvl" *ngIf="categoriesNavigator.lvl0 == category.key"></div>
<span class="menu-top-level">{{ category?.title?.toUpperCase() }} </span>
<div *ngIf="categoriesNavigator.lvl0 == category.key">
<br>
<div class="row row-fix lvl1" *ngFor="let subcategory of getSubcategories(category.key)" (click)="openSubcategory(subcategory)">
<div class="little-menu-bar-midlvl"></div>
<span class="menu-second-level">{{ subcategory?.title?.toUpperCase() }} </span>
<div *ngIf="categoriesNavigator.lvl1 == subcategory.key">
<br>
<div class="row row-fix lvl2" *ngFor="let thirdLevel of getThirdLevel(category.key, subcategory.key)" (click)="openUrl(thirdLevel)">
<div class="little-menu-bar-lowlvl" *ngIf="categoriesNavigator.lvl0 == category.key"></div>
<span class="menu-third-level">{{ thirdLevel?.title?.toUpperCase() }} </span>
</div>
</div>
</div>
</div>
</div>
</div>
So these classes are very simple. I'm not very good at CSS (I prefer designing logic rather than designing), and maybe I'm doing some stupid thing here:
.lvl0 :hover{
color: orange;
}
.lvl1 :hover{
color: orange;
}
.lvl2 :hover{
color: orange;
clear: both;
}
So the behavior works nice for first level, but as you can see, all the rows with the second level get highlighted instead of just the one I'm hovering on:
Same happens with the third level.
Do you have any idea on what I'm doing wrong? I'm adding the Angular tag just in case it has something to do with my template code. Thank you!
The problem is that you have applied the style to your div and as the divs are nested, the styles will cascade and turn everything inside it the colour - you can try to apply the styles directly to the spans to avoid this. Also I have removed the space before your hover colon
.lvl0:hover>span { /* leave hover on div but style the span */
color: orange;
}
.lvl1:hover>span {
color: red;
}
.lvl2:hover>span {
color: green;
}
<div class="lvl0">
<span>test 0</span>
<div class="lvl1">
<span>test 1</span>
<div class="lvl2">
<span>test 2</span>
</div>
</div>
</div>
The :hover is basically propagating down to other levels. Do not use CSS on the parent directly. Instead, use it on something like span etc.
Check pen here to solve your issue. In your case, you can have <div> tag too instead of the span which closes there and is basically a sibling of next level.
.lvl:hover {
//common for all
color: orange;
}
I'm currently programming a view, that contains two list elements that can move information between each other. Here's a picture of how it currently looks:
I supposedly have in the page a lot of space to the right of the table "CodigoAGrupador" for the table "Catalogos" to fit in, and it used to do so, but when I added the scrollbars, suddenly, they can only be together vertically, never horizontally.
Here's the CSS code:
#products {
float: left;
width: 500px;
}
#cart {
width: 400px;
right: 0px;
top: 0px;
float: right;
max-height: 600px;
overflow-y:auto;
margin: 2px,2px,2px,2px;
overflow-x: auto;
}
#ListaCodigos{
max-height:600px;
width:500px;
overflow-y:auto;
margin: 2px,2px,2px,2px;
overflow-x: auto;
}
And here's the code that I use for the html view (it contains logic that I use to dynamically create the lists, that part shouldn't be the issue)
<div id="content">
<div id="ListaCodigos">
<h2 class="ui-widget-header">CodigoAgrupador</h2>
<div id="products">
<div id="catalog">
#foreach (CodigoAgrupadorCuentas_CE c in Model.CodigosAgrupadores)
{
if (unchecked(double.Parse(c.CodigoAgrupador) == (int)double.Parse(c.CodigoAgrupador)))
{
<h3>#c.CodigoAgrupador - #c.NombreCuenta</h3>
<div>
<div class="subcatalog">
#foreach (CodigoAgrupadorCuentas_CE c2 in Model.CodigosAgrupadores)
{
if (double.Parse(c2.CodigoAgrupador) > double.Parse(c.CodigoAgrupador) && double.Parse(c2.CodigoAgrupador) < (double.Parse(c.CodigoAgrupador) + 1))
{
<h4>#c2.CodigoAgrupador - #c2.NombreCuenta</h4>
<div>
<div class="SpecificCatalog">
<ol>
<li class="placeholder">Add your items here</li>
</ol>
</div>
</div>
}
}
</div>
<div class="GeneralCatalog">
<ol>
<li class="placeholder">Add your items here</li>
</ol>
</div>
</div>
}
}
</div>
</div>
</div>
<div id="cart">
<h2 class="ui-widget-header">Catalogos</h2>
<div class="ui-widget-content">
#foreach (LedgerChartOfAccounts c in Model.Catalogos)
{
if (c.CodigoAgrupador == null)
{
<ul>
<li class="draggable">#c.GLAccountNumber - #c.GLAccountName </li>
</ul>
}
}
</div>
</div>
<div>
<footer>Inserte los catalogos en el grupo que pertenescan, jale.</footer>
</div>
</div>
It probably is a very simple issue, but I couldn't find any specific answer to my problem and I already have struggled for quite a while. Any help is welcome.
You can just float:left the menu and ListaCodigos to get it to pull up. Make sure that content is wide enough to hold them both on one line however.
However, then after menu div you will want to add a <div style="clear:both"></div>