How can i make my input inline with my chips? - css

I wanted to create custom tags input component.
So my code looks like this
import React from 'react';
import './App.scss';
const App = () => {
return (
<div>
<div className="tags-input">
<ul id="tags">
<li className="tag">
<span className="tag-title">tag 1</span>
<span><i className="fas fa-times-circle tag-close-icon"></i></span>
</li>
<li className="tag">
<span className="tag-title">tag 2 sdsdsdsd</span>
<span><i className="fas fa-times-circle tag-close-icon"></i></span>
</li>
</ul>
<input type="text" />
</div>
</div>
);
}
export default App;
.tags-input {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
min-height: 48px;
width: 480px;
padding: 0 8px;
border-bottom: 1px solid grey;
border-radius: 6px;
&:focus-within {
border-bottom: 1px solid #0052cc !important;
}
input {
flex: 1;
border: none;
height: 46px;
font-size: 14px;
padding: 4px 0 0 0;
&:focus {
outline: transparent;
}
}
}
#tags {
display: flex;
flex-wrap: wrap;
padding: 0;
margin: 8px 0 0 0;
// border:2px solid red !important;
}
.tag {
width: auto;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
padding: 0 8px;
font-size: 14px;
list-style: none;
border-radius: 6px;
margin: 0 8px 8px 0;
background: #0052cc;
.tag-title {
margin-top: 3px;
}
.tag-close-icon {
display: block;
width: 16px;
height: 16px;
line-height: 16px;
text-align: center;
font-size: 14px;
margin-left: 8px;
color: #0052cc;
border-radius: 50%;
background: #fff;
cursor: pointer;
}
}
so far every thing is good.
When i have for exampel two chips and i click on the input to type - input appears next to the last chip.
My problem happens when have multiply chips
for example four of them
const App = () => {
return (
<div>
<div className="tags-input">
<ul id="tags">
<li className="tag">
<span className="tag-title">tag 1</span>
<span><i className="fas fa-times-circle tag-close-icon"></i></span>
</li>
<li className="tag">
<span className="tag-title">tag 2 sdsdsdsd</span>
<span><i className="fas fa-times-circle tag-close-icon"></i></span>
</li>
<li className="tag">
<span className="tag-title">tag 2 sdsdsdsd</span>
<span><i className="fas fa-times-circle tag-close-icon"></i></span>
</li>
<li className="tag">
<span className="tag-title">i should be able to type right from here</span>
<span><i className="fas fa-times-circle tag-close-icon"></i></span>
</li>
</ul>
<input type="text" />
</div>
</div>
);
}
export default App;
in this case when i type in the input, it is under - i can't type next to the last element chip which is i should be able to type right from here
I can only under the last element i should be able to type right from here.
Here is my stackblitz example
https://stackblitz.com/edit/react-ax4zun?file=src%2FApp.js
So i need to type here
https://ibb.co/DbXb752
but my cursor goes actually down
https://ibb.co/SfL09jR

The best approach here would be to move the tags outside of the UL as individual spans, at the moment because they are inside the UL the input will always be pushed onto a new line when there is not enough space.

You should move up your input element and put it into <li> tag

Related

How do I get the Parent container to span the total width of my page

I am using React and this should be a very simple task yet I am stuck. I cannot get the home container to span the width of my page
Here is my Css code, I originally had two Css files one for the Nav and one for the Home section but started playing around trying to figure out where I went wrong. I have basically now stripped my css and code it all the way down still cant figure out why it wont span completely from side to side
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.site-title {
font-size: 2rem;
}
.nav {
background-color: #333;
color: antiquewhite;
display: flex;
justify-content: space-between;
align-items: stretch;
gap: 2rem;
padding: 0 1rem;
}
.nav ul{
display: flex;
gap: 1rem;
padding: 0%;
margin: 0%;
list-style: none;
}
.nav a{
display: flex;
color: inherit;
text-decoration: none;
height: 100%;
align-items: center;
padding: .55rem;
}
.nav li.active {
background-color: #555;
}
.nav li:hover{
background-color: #777;
}
.home-container {
background-color: #111;
}
.home-parent {
display: flex;
align-items: center;
color: aliceblue;
}
My HTML
import Typical from "react-typical";
export default function Home() {
return (
<div className="home-container">
<div className="home-parent">
<div className="profile-details">
<div className="colz">
<div className="colz-icon">
<a href="#">
<i className="fa fa-facebook-square"></i>
</a>
<a href="#">
<i className="fa fa-instagram"></i>
</a>
<a href="#">
<i className="fa fa-youtube-square"></i>
</a>
<a href="#">
<i className="fa fa-twitter"></i>
</a>
</div>
</div>
<div className="Home-details-name">
<span className="primary-text">
{""}
Hello, I'm <span className="highlighted-text">Heather</span>
</span>
</div>
<div className="home-details-role">
<span className="primary-text">
{""}
<h1>
<Typical
loop={Infinity}
steps={[
"Fullstack Dev",
1000,
"Web Design",
1000,
"Data bases",
1000,
"Tech Support",
1000,
]}
/>
</h1>
<span className="home-role-tagline">
Knack for building applications with front and backend
operations
</span>
</span>
</div>
<div className="profile-options">
<button className="btn primary-btn">
{""}
Hire Me{""}
</button>
<a
href="Heather-Christensen.pdf"
download="Heather-Christensen.pdf"
>
<button className="btn highlighted-btn">Get Resume</button>
</a>
</div>
</div>
<div className="profile-picture">
<div className="profile-picture-background"></div>
</div>
</div>
</div>
);
}

Vertically center content inside an inline parent

Trying to create an adaptive post meta for a post card.
The idea is that sometimes the post meta could have more than one category inside and because of that I need somehow to wrap the items, but at the same time to vertically center the li content (like the avatar and icons).
I tried to apply display: inline-flex to the .entry-meta in order to be able to use the align-items: center property but in this case the list items - li's are not anymore wrapping nice like when applying display: inline to li.
1. The display: inline method (not centering items vertically)
This method is wrapping correctly and how I want all the list items but it can't center vertically the content (like the avatar and icons)
article {
max-width: 450px;
background: #eee;
font-family: arial;
font-size: 12px;
text-transform: uppercase;
}
article a {
text-decoration: none;
}
.entry-meta {
list-style: none;
margin: 0;
padding: 0;
}
.entry-meta li {
display: inline;
margin-right: 10px;
background: #ccc;
}
.avatar {
display: inline-block;
width: 25px;
height: 25px;
border-radius: 100%;
background: #FA7059;
}
.icon {
display: inline-block;
width: 13px;
height: 13px;
background: #BE4C4E;
}
<article>
<ul class="entry-meta">
<li class="author">
<div class="avatar">
</div>
<span>By </span>
Admin
</li>
<li class="date">
<span>On </span>
<time>Feb 22, 2019</time>
</li>
<li>
<span>On </span>
2 Comments
</li>
<li class="categories">
<span class="icon">
</span>
Food
Nature
People
Travel
Trends
Business
Sport
Music
Gadgets
Uncategorized
</li>
<li class="tags">
<span class="icon">
</span>
Red
Blue
Green
Yellow
</li>
</ul>
</article>
2. The display: inline-flex method
The category li is not wrapped correctly, it breaks in a new line, but in exchange the content is vertically centered like I need.
article {
max-width: 450px;
background: #eee;
font-family: arial;
font-size: 12px;
text-transform: uppercase;
}
article a {
text-decoration: none;
}
.entry-meta {
list-style: none;
margin: 0;
padding: 0;
display: inline-flex;
flex-wrap: wrap;
align-items: center;
}
.entry-meta li {
margin-right: 10px;
background: #ccc;
display: inline-flex;
flex-wrap: wrap;
align-items: center;
}
.avatar {
display: inline-block;
width: 25px;
height: 25px;
border-radius: 100%;
background: #FA7059;
}
.icon {
display: inline-block;
width: 13px;
height: 13px;
background: #BE4C4E;
}
<article>
<ul class="entry-meta">
<li class="author">
<div class="avatar">
</div>
<span>By </span>
Admin
</li>
<li class="date">
<span>On </span>
<time>Feb 22, 2019</time>
</li>
<li>
<span>On </span>
2 Comments
</li>
<li class="categories">
<span class="icon">
</span>
Food
Nature
People
Travel
Trends
Business
Sport
Music
Gadgets
Uncategorized
</li>
<li class="tags">
<span class="icon">
</span>
Red
Blue
Green
Yellow
</li>
</ul>
</article>
So, in other words, I need somehow to keep the list items to wrap like they are with display: inline but at the same time center vertically the content inside.
P.S. the vertical-align: middle property doesn't really help :)
P.S. the vertical-align: middle property doesn't really help :)
This is actually what you need (applied to .avatar)
article {
max-width: 450px;
background: #eee;
font-family: arial;
font-size: 12px;
text-transform: uppercase;
}
article a {
text-decoration: none;
}
.entry-meta {
list-style: none;
margin: 0;
padding: 0;
}
.entry-meta li {
display: inline;
margin-right: 10px;
background: #ccc;
}
.avatar {
display: inline-block;
width: 25px;
height: 25px;
border-radius: 100%;
background: #FA7059;
vertical-align:middle;
}
.icon {
display: inline-block;
width: 13px;
height: 13px;
background: #BE4C4E;
}
<article>
<ul class="entry-meta">
<li class="author">
<div class="avatar">
</div>
<span>By </span>
Admin
</li>
<li class="date">
<span>On </span>
<time>Feb 22, 2019</time>
</li>
<li>
<span>On </span>
2 Comments
</li>
<li class="categories">
<span class="icon">
</span>
Food
Nature
People
Travel
Trends
Business
Sport
Music
Gadgets
Uncategorized
</li>
<li class="tags">
<span class="icon">
</span>
Red
Blue
Green
Yellow
</li>
</ul>
</article>

Placing elemenents with css?

I want to place image floated left, next to image, floated left one under another would be Authro, Date and Category, than, after this other elements will be floated on right side...
Like this...
https://i.imgur.com/tcKwalP.png
This is what I have so far...
https://jsfiddle.net/fbn9r3y4/
This is html...
<div class="entry-meta">
<span class="entry-image">
<a class="entry-image-a" href="">
<img src="image.jpg" height="48" width="48">
</a>
</span>
<span class="entry-author">
Ester
</span>
<span class="entry-date">September 3, 2019</span>
<span class="entry-category-single">
Music
</span>
<span class="meta-right">
<span class="entry-views"><span class="view-count">998</span> Views</span>
<span class="entry-like">
<span class="sl-wrapper">
<a href="" class="sl-button">
<span class="sl-count">500<em>Likes</em></span>
</a>
<span class="sl-loader"></span>
</span>
</span>
</span>
</div>
This is css...
.entry-meta {
font-family: Arial, sans-serif;
display: block;
align-items: center;
border-top: 1px solid #f3f3f3;
border-bottom: 1px solid #f3f3f3;
padding: 10px 2px;
}
.entry-image {
display: block;
float: left;
}
.entry-author {
display: block;
float: left;
width: 200px;
}
.entry-date {
display: block;
float: left;
width: 200px;
clear: left;
}
.entry-category-single {
display: block;
float: left;
width: 200px;
clear: left;
}
.meta-right {
margin: 0 10px 0 0;
margin-left: auto;
order: 2;
float: right;
}
.entry-like {
min-width: 32px;
line-height: 1;
float: right;
clear: right;
}
.entry-views {
min-width: 32px;
line-height: 1;
float: right;
clear: right;
}
I changed up your markup a little bit and added a wrapping meta-left around the content of the left side. I also simplified your CSS. There were several CSS properties that were invalid or not necessary.
.entry-meta {
font-family: Arial, sans-serif;
border-top: 1px solid #f3f3f3;
border-bottom: 1px solid #f3f3f3;
padding: 10px 2px;
}
.entry-meta::after {
content: '';
clear: both;
display: block;
}
.meta-left {
float: left;
}
.meta-right {
float: right;
margin: 0 10px 0 0;
}
.entry-image {
float: left;
}
.meta-info {
float: left;
margin-left: 10px;
}
.entry-like {
min-width: 32px;
line-height: 1;
}
.entry-views {
min-width: 32px;
line-height: 1;
}
<div class="entry-meta">
<div class="meta-left">
<div class="entry-image">
<a class="entry-image-a" href="">
<img src="https://via.placeholder.com/48" height="48" width="48">
</a>
</div>
<div class="meta-info">
<div class="entry-author">
Ester
</div>
<div class="entry-date">September 3, 2019</div>
<div class="entry-category-single">
Music
</div>
</div>
</div>
<div class="meta-right">
<div class="entry-views"><span class="view-count">998</span> Views</div>
<div class="entry-like">
<span class="sl-wrapper">
<a href="" class="sl-button">
<span class="sl-count">500<em> Likes</em></span>
</a>
<span class="sl-loader"></span>
</span>
</div>
</div>
</div>
Here's a version using display: flex that's even simpler. Same markup.
.entry-meta {
font-family: Arial, sans-serif;
border-top: 1px solid #f3f3f3;
border-bottom: 1px solid #f3f3f3;
padding: 10px 2px;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.meta-left {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
.meta-info {
margin-left: 10px;
}
<div class="entry-meta">
<div class="meta-left">
<div class="entry-image">
<a class="entry-image-a" href="">
<img src="https://via.placeholder.com/48" height="48" width="48">
</a>
</div>
<div class="meta-info">
<div class="entry-author">
Ester
</div>
<div class="entry-date">September 3, 2019</div>
<div class="entry-category-single">
Music
</div>
</div>
</div>
<div class="meta-right">
<div class="entry-views"><span class="view-count">998</span> Views</div>
<div class="entry-like">
<span class="sl-wrapper">
<a href="" class="sl-button">
<span class="sl-count">500<em> Likes</em></span>
</a>
<span class="sl-loader"></span>
</span>
</div>
</div>
</div>
Esteros. Please check this link
https://codepen.io/juricon/pen/QWLOZea
HTML:
<div class="entry-meta">
<span class="entry-image">
<a class="entry-image-a" href="">
<img src="image.jpg" height="48" width="48">
</a>
</span>
<ul class="left-float-list">
<ol>
<a href="" title="" rel="author">
Ester
</a>
</ol>
<ol>
September 3, 2019
</ol>
<ol>
<a href="">
Music
</a>
</ol>
</ul>
<ul class="right-float-list">
<li class="items-reverse">
<span class="entry-views">
<!--do not miss nesting rules <tag><tag1></tag1</tag> -->
998
</span>
<span class="view-count">
Views
</span>
</li>
<li>
<span class="entry-like">
<span class="sl-wrapper"> <!--do not miss nesting rules <tag><tag1></tag1</tag> Also, you don't have in CSS classes like .sl-wrapper .sl-button, .sl-count, sl-loader -->
<a href="" class="sl-button">
<span class="sl-count">
500<em>Likes</em>
</span>
<!-- it is a bad idea to use <em> with not cursive text in one <span>. Use CSS to style your text -->
</a>
<span class="sl-loader">
</span>
</span>
</span>
</li>
<li>
Whatever
</li>
</ul>
CSS:
*{ /*clear styles*/
margin:0;
padding:0;
/*clear styles*/
}
.entry-meta {
font-family: Arial, sans-serif;
display: block;
border-top: 1px solid #f3f3f3;
border-bottom: 1px solid #f3f3f3;
padding: 10px 2px;
}
.entry-image{
float: left;
}
.left-float-list{
float: left;
width: 200px;
list-style:none;
background: green;
margin-left:.4em;
}
.right-float-list{
float: right;
list-style:none;
background: red;
margin-right:1em;
}
.entry-views, .entry-like {
min-width: 32px;
line-height: 1;
}
Esteros, here you will find a great web development free course https://www.freecodecamp.org/ and
https://www.w3schools.com/html/default.asp.
It will help you a lot. Good luck!
P.S.: Use Flexbox instead of "float" and you won't regret.

Multi-line flexbox list with text-overflow: ellipsis

I would like to achieve the attached list style in HTML5/CSS.
The single-line items can easily be done using flexbox (see below). However, I cannot quite figure out how to achieve the double-line items: If I allow wrapping, the "List Item Title" will no longer be truncated (ellipsis)...
Should I use CSS grid? Or is that overkill?
Here is my flexbox-single-line-implementation:
ul {
padding: 0;
border: 1px solid red;
list-style-type: none;
}
li {
display: flex;
margin: 0;
border-bottom: 1px solid gray;
}
div.icon {
flex-shrink: 0;
width: 20px;
height: 20px;
margin: 15px;
background-color: lightcoral;
}
span.title {
flex-grow: 1;
flex-shrink: 1;
margin: 15px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
span.tag {
flex-shrink: 0;
margin: 15px;
}
span.second-line {
margin: 15px;
}
<ul>
<li>
<div class="icon"></div>
<span class="title">List Item Title</span>
<span class="tag">Some tag</span>
</li>
<li>
<div class="icon"></div>
<span class="title">Very Super Long List Item Title With Added Characters to Ensure Truncation</span>
<span class="tag">Some tag</span>
</li>
<li>
<div class="icon"></div>
<span class="title">List Item Title</span>
</li>
</ul>
You can achieve the result by using two child Div's inside li and have separate Flex for both child Div's instead having in li. Find the code below which works for me.
Code:
ul {
padding: 0;
border: 1px solid red;
list-style-type: none;
}
li {
margin: 0;
border-bottom: 1px solid gray;
}
div.icon {
flex-shrink: 0;
width: 20px;
height: 20px;
margin: 15px;
background-color: lightcoral;
}
span.title {
flex-grow: 1;
flex-shrink: 1;
margin: 15px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
span.tag {
flex-shrink: 0;
margin: 15px;
}
span.second-line {
margin: 15px;
}
.mainHeading {
display: flex;
}
.subHeading {
display: block;
}
<ul>
<li>
<div class="mainHeading">
<div class="icon"></div>
<span class="title">List Item Title</span>
<span class="tag">Some tag</span>
</div>
</li>
<li>
<div class="mainHeading">
<div class="icon"></div>
<span class="title">Very Super Long List Item Title With Added Characters to Ensure Truncation</span>
<span class="tag">Some tag</span>
</div>
<div class="subHeading">
<span class="title">List Item Sub Title</span>
<span class="tag">Some another tag</span>
</div>
</li>
<li>
<div class="mainHeading">
<div class="icon"></div>
<span class="title">List Item Title</span>
</div>
</li>
</ul>

Custom button, that doesn't want to work properly when I am switching to another language

I am trying to create a button just like this one. This button already works fine in the English version, but when I switch to french, it breaks. The French text is much longer, and the button breaks into two separate parts. Any ideas how I can create a "responsive" (text size relative) button?
My code:
<div class="row-fluid">
<div class="text-box text-center"><p>View By</p></div>
<div class="btn-group pull-right small-tab" style="padding-right:20px">
<button class="btn dropdown-toggle" data-toggle="dropdown">
<span class="fa fa-bars"></span>
</button>
<ul class="dropdown-menu pull-right">
<li </li>
<li </li>
<li </li>
</ul>
</div>
</div>
.text-box {
display: inline-block;
height: 27px;
min-width: 70px;
border: 1px solid #c2c2c2;
border-radius: 3px 0 0 3px;
font-size: 14px;
padding: 1px 0 0 0;
margin-right: -1px;
text-align: center;
margin-left: 225px;
p {
margin-top: 5px;
}
}
.small-tab {
.btn:first-child {
border-radius: 0px 3px 3px 0px;
}
}
.btn-group.open .btn.dropdown-toggle {
background-color:#1388e2;
}
.btn {
color:#ffffff;
background-color:#46a9f8;
border: none;
}
.btn:hover {
color:#ffffff;
background-color:#128ded;
}

Resources