I want to style my unordered list like this one below
Link to what i want to achive
My structure looks like:
<div class="tabs">
<ul class="tabs__labels">
<li class="0">
<a class="active" href="#">
<img/>
<div>something</div>
</a>
</li>
<li class="1">
<a class="" href="#">
<img/>
<div>something1</div>
</a>
</li>
...
</ul>
</div>
Is it a good idea to name the list classes like 0,1 etc. and style them separately to somehow achive this effect? How to use flexbox to get similar effect? Should i group them into rows?
Would this be a start?
.tabs__labels {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
}
.tabs__labels li {
flex-basis: 45%;
margin: 20px 0;
padding: 0;
}
.tabs__labels li:nth-child(odd) {
display: flex;
justify-content: flex-end;
}
.tabs__labels li:nth-child(even) {
display: flex;
}
.tabs__labels li:nth-child(3),
.tabs__labels li:nth-child(4) {
flex-basis: 35%;
}
.tabs__labels li a {
display: flex;
justify-content: center;
align-items: center;
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid red;
text-decoration: none;
}
.tabs__labels li:nth-child(1)::before {
content: 'some text';
text-decoration: underline;
margin-right: 10px;
}
.tabs__labels li:nth-child(2)::after {
content: 'some text';
text-decoration: underline;
margin-left: 10px;
}
<div class="tabs">
<ul class="tabs__labels">
<li>
<a class="active" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
</ul>
</div>
Related
My first question here and your help would be much appreciated
I have a ul width display: grid inside a div with overflow: hidden.
The ul's purpose is to function as a slidable element, so its width is not explicitly specified, but rather, defined by its contents. Each li element inside the list contains text of variable length, which should not be truncated nor break on a 2nd line.
The li count inside the list may vary, from 4 to up to 12 elements.
My question is how can I create a grid that all its cells have the width of the widest li? (which, in turn, is defined by the longest text)
Please keep in mind that the grid is always going to have 2 rows
Here is a simplified version of what I am trying to accomplish:
.container {
overflow: hidden;
background: #fafafa;
width: 760px;
margin: 0 auto;
padding: 24px;
}
ul {
overflow: auto;
list-style: none;
padding: 0;
display: grid;
grid-gap: 8px;
grid-auto-flow: column;
grid-auto-columns: 1fr;
grid-template-rows: repeat(2, 1fr);
}
li {
border: 1px solid #eee;
border-radius: 20px;
padding-inline: 12px;
display: flex;
gap: 4px;
align-items: center;
}
a {
white-space: nowrap;
}
<div class='container'>
<ul>
<li>
<img src='https://unsplash.it/50/50'>
<a>text 1</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 2</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 3</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Fourth text</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Test 5 is is a huge text and all other cells should follow its size</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 6</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>This is also a large text</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 8</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 9</a>
</li>
</ul>
</div>
.container {
overflow: hidden;
background: #fafafa;
width: 760px;
margin: 0 auto;
padding: 24px;
}
ul {
overflow: auto;
list-style: none;
padding: 0;
display: grid;
grid-gap: 8px;
grid-auto-flow: column;
grid-templates-column: auto auto auto auto;
grid-template-rows: auto auto;
}
li {
border: 1px solid #eee;
border-radius: 20px;
padding-inline: 12px;
display: flex;
gap: 4px;
align-items: center;
}
a {
white-space: nowrap;
}
<div class='container'>
<ul>
<li>
<img src='https://unsplash.it/50/50'>
<a>text 1</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 2</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 3</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Fourth text</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Test 5 is is a huge text and all other cells should follow its size</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 6</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>This is also a large text</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 8</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 9</a>
</li>
</ul>
</div>
.container {
overflow: hidden;
background: #fafafa;
width: 760px;
margin: 0 auto;
padding: 24px;
}
ul {
overflow: auto;
list-style: none;
padding: 0;
display: grid;
grid-gap: 8px;
grid-auto-flow: column;
grid-auto-columns: 1fr;
grid-template-rows: repeat(2, 1fr);
}
li {
border: 1px solid #eee;
border-radius: 20px;
padding-inline: 12px;
display: flex;
gap: 4px;
align-items: center;
}
a {
white-space: nowrap;
}
<div class='container'>
<ul>
<li>
<img src='https://unsplash.it/50/50'>
<a>text 1</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 2</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 3</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Fourth text</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Test 5 is is a huge text and all other cells should follow its size</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 6</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>This is also a large text</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 8</a>
</li>
<li>
<img src='https://unsplash.it/50/50'>
<a>Text 9</a>
</li>
</ul>
</div>
The problem is this image, I want to make it circular, I used border-radius:50% and set equal height and width. I searched for the question and found this one How to make a circular image in css and I tried to make something similar but I used flexbox.
<div className='nav-bar'>
<ul className='nav-links'>
<li className='nav-link'>
<Link >
Home
</Link>
</li>
<li className='nav-link'>
<Link >
Add question
</Link>
</li>
<li className='nav-link'>
<Link >
Leaderboard
</Link>
</li>
</ul>
<ul className='nav-user-sign-out'>
<li className='nav-item'>
<p>Welcome, </p>
</li>
<li className='nav-item'>
<div className='avatar'>
<img src={} alt='' />
</div>
</li>
<li className='nav-item'>
<button className='sign-out'>
Sign out
</button>
</li>
</ul>
</div>;
.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
}
.nav-links {
display: flex;
}
Link {
padding: 10px;
}
.nav-user-sign-out {
display: flex;
align-items: center;
justify-content: space-around;
}
.sign-out {
padding: 10px;
}
.avatar {
width: 30px;
height: 30px;
border-radius: 50%;
overflow: hidden;
}
img {
height: 100%;
width: 100%;
}
Either make height and width of fixed and equal value or if you are using percentage confirm to that image has same width and height.
I just made a codesandbox with your code, and it's working without an issue, maybe the issue is with another CSS class that declared somewhere else, or maybe the object-fit property on the image. I'll put the link to my sandbox here, feel free to go ahead and try it with your code. I added object-fit to the image styles there.
working example
.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
}
.nav-links {
display: flex;
}
Link {
padding: 10px;
}
.nav-user-sign-out {
display: flex;
align-items: center;
justify-content: space-around;
}
.sign-out {
padding: 10px;
}
.avatar {
width: 30px;
height: 30px;
border-radius: 50%;
overflow: hidden;
}
img {
height: 100px;
width: 105px;
border-radius: 50%;
}
<div className='nav-bar'>
<ul className='nav-links'>
<li className='nav-link'>
<Link >
Home
</Link>
</li>
<li className='nav-link'>
<Link >
Add question
</Link>
</li>
<li className='nav-link'>
<Link >
Leaderboard
</Link>
</li>
</ul>
<ul className='nav-user-sign-out'>
<li className='nav-item'>
<p>Welcome, </p>
</li>
<li className='nav-item'>
<div className='avatar'>
<img src="https://media.sproutsocial.com/uploads/2015/02/Facebook_Embed.png" alt=''width ="200" />
</div>
</li>
<li className='nav-item'>
<button className='sign-out'>
Sign out
</button>
</li>
</ul>
</div>
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>
When I applied padding to 'a' elements, there will be gaps top-borders' left and right.I want the top border covers entire line until navbar's right border. How can I solve this problem.
* {
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
}
.wrapper {
display: grid;
grid-template-columns: 1fr 6fr;
}
.navbar {
border-right: gray 3px solid;
padding: 5%;
position: sticky;
top: 0;
height: 100vh;
box-sizing: border-box;
min-width: 300px;
}
#navbar-header {
text-align: center;
margin-bottom: 20px;
}
#navbar-content a {
text-decoration: none;
color: black;
}
#navbar-content a li {
list-style: none;
padding: 5%;
padding-left: 10%;
border-top: gray 1px solid;
}
<div class="wrapper">
<div class="navbar">
<h2 id="navbar-header">JS Documentation</h2>
<ul id="navbar-content">
<a href="#intro">
<li>Introduction</li>
</a>
<a href="#know">
<li>What you should already know</li>
</a>
<a href="#js-java">
<li>JavaScript and Java</li>
</a>
<a href="#hello">
<li>Hello World</li>
</a>
<a href="#var">
<li>Variables</li>
</a>
<a href="#dec-var">
<li>Declaring Variables</li>
</a>
<a href="#var-sco">
<li>Variable Scope</li>
</a>
<a href="#glo-var">
<li>Global Variables</li>
</a>
<a href="#cons">
<li>Constants</li>
</a>
<a href="#data">
<li>Data Types</li>
</a>
<a href="#if-else">
<li>if...else statement</li>
</a>
<a href="#while">
<li>while statement</li>
</a>
<a href="#func">
<li>Function declarations</li>
</a>
<a href="#ref">
<li>Reference</li>
</a>
</ul>
</div>
<div class="contents">
</div>
</div>
When I applied padding to 'a' elements, there will be gaps top-borders' left and right.I want the top border covers entire line until navbar's right border. How can I solve this problem.
Remove the padding-left/right from the navbar and increase the one of the li:
* {
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
}
.wrapper {
display: grid;
grid-template-columns: 1fr 6fr;
}
.navbar {
border-right: gray 3px solid;
padding: 5% 0; /*updated*/
position: sticky;
top: 0;
height: 100vh;
box-sizing: border-box;
min-width: 300px;
}
#navbar-header {
text-align: center;
margin-bottom: 20px;
}
#navbar-content a {
text-decoration: none;
color: black;
}
#navbar-content a li {
list-style: none;
padding: 5% 10%; /*updated*/
border-top: gray 1px solid;
}
<div class="wrapper">
<div class="navbar">
<h2 id="navbar-header">JS Documentation</h2>
<ul id="navbar-content">
<a href="#intro">
<li>Introduction</li>
</a>
<a href="#know">
<li>What you should already know</li>
</a>
<a href="#js-java">
<li>JavaScript and Java</li>
</a>
<a href="#hello">
<li>Hello World</li>
</a>
<a href="#var">
<li>Variables</li>
</a>
<a href="#dec-var">
<li>Declaring Variables</li>
</a>
<a href="#var-sco">
<li>Variable Scope</li>
</a>
<a href="#glo-var">
<li>Global Variables</li>
</a>
<a href="#cons">
<li>Constants</li>
</a>
<a href="#data">
<li>Data Types</li>
</a>
<a href="#if-else">
<li>if...else statement</li>
</a>
<a href="#while">
<li>while statement</li>
</a>
<a href="#func">
<li>Function declarations</li>
</a>
<a href="#ref">
<li>Reference</li>
</a>
</ul>
</div>
<div class="contents">
</div>
</div>
I want to do the exact same thing of what this CSS styling suggests in react native
So how can I convert this CSS to React -native
.grid {
display: flex;
flex-direction: row;
list-style: none;
padding-left: 0;
flex-wrap: wrap;
margin-top: 0;
margin-bottom: 20px;
width: 400px;
}
.grid-item {
flex-grow: 0;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
height: 100px;
background: rgba(0,0,0,0.1);
width: 33%;
}
.grid-item:nth-last-child(-n+3) {
border-bottom: none;
}
.grid-item:nth-child(3n+0) {
border-right: none;
}
.list {
display: flex;
flex-direction: column;
list-style: none;
padding-left: 0;
width: 400px;
}
.list-item {
flex-grow: 0;
border-bottom: 1px solid #000;
height: 60px;
background: rgba(0,0,0,0.1);
flex: 1;
}
.list-item:last-child {
border-bottom: none;
}
<ul class="grid">
<li class="grid-item">
</li>
<li class="grid-item">
</li>
<li class="grid-item">
</li>
<li class="grid-item">
</li>
<li class="grid-item">
</li>
<li class="grid-item">
</li>
<li class="grid-item">
</li>
<li class="grid-item">
</li>
<li class="grid-item">
</li>
</ul>
<ul class="list">
<li class="list-item">
</li>
<li class="list-item">
</li>
<li class="list-item">
</li>
<li class="list-item">
</li>
</ul>
I want to make a Modal which looks like this:
<Modal>
<BrandsGrid />
</Modal>
<Modal>
<ModelsList />
</Modal>
I need to define BrandsGrid and ModelsList and do something exactly similar to that CSS styling in React-native
So example codes will be more helpful for understanding I have referred the docs but couldn't get much help from that
You can use different modules for converting css components to react native. For example:
https://www.npmjs.com/package/css-to-react-native-transform
Another great example:
https://github.com/kristerkari/react-native-css-transformer