CSS display list in columns - html

I have a list which is made by Vue.js
Here is my code:
<ul>
<li
v-for="category in item.children"
:key="category.id"
class="menu-item"
>
<nuxt-link
:to="
localePath(
`/category/${category.slug}/${category.id}`
)
"
>
<h5>{{ category.lang[0].name }}</h5>
</nuxt-link>
<ul class="mega-menu__list">
<li
v-for="subItem in category.children"
:key="subItem.id"
>
<nuxt-link
:to="
localePath(
`/category/${subItem.slug}/${subItem.id}`
)
"
>
{{ subItem.lang[0].name }}
</nuxt-link>
</li>
</ul>
</li>
</ul>
But I want it to display like this which child is in the same column:
Any help is appreciated.

* {
font-family: "Arial";
font-size: 15px;
margin: 0;
padding: 0;
}
section {
display: flex;
flex-direction: column;
flex-wrap: wrap;
width: 450px;
height: 800px;
margin: 0 auto;
}
div {
display: flex;
flex-direction: column;
padding: 15px 30px;
}
h5 {
margin-bottom: 20px;
text-transform: uppercase;
}
ul {
list-style: none;
}
li {
line-height: 30px;
}
<section>
<div>
<h5>shop by concern</h5>
<ul>
<li>Pores</li>
<li>Whitening</li>
<li>Fine Lines & Wrinkles</li>
<li>Hydrating</li>
<li>Dark Spots</li>
<li>Anti-Aging</li>
<li>Acne & Blemishes</li>
</ul>
</div>
<div>
<h5>others</h5>
<ul>
<li>Tools & Accessories</li>
<li>Beauty Supplements</li>
</ul>
</div>
<div>
<h5>skincare package</h5>
</div>
<div>
<h5>treatment</h5>
<ul>
<li>T-Zone &vert; Blackhead</li>
<li>Ampoule</li>
<li>Acne &vert; Blemishes</li>
<li>Serum</li>
<li>Pore Care</li>
<li>Lip Care</li>
<li>Eye Care</li>
</ul>
</div>
<div>
<h5>cleanser & exfoliator</h5>
<ul>
<li>Scrub & Exfoliator</li>
<li>Face Wash & Cleansers</li>
<li>Soap</li>
</ul>
</div>
<div>
<h5>sun care</h5>
</div>
<div>
<h5>moisturizer</h5>
<ul>
<li>Mist Spray</li>
<li>Cream</li>
<li>Moisturizer / Lotion</li>
</ul>
</div>
<div>
<h5>toner</h5>
</div>
</section>
See in my example, that if you have enough height (css), a menu will try to get there, if not, it will go to the right (because it has space to go there because of flex-wrap: wrap. Play with each CSS property in section and div, and you will understand more.
You can see more about flex here. And if you want to try out grid, here.

Related

How can I solve the problem with Inline for couple elements

<style>
.footer h3 {
width: fit-content;
margin: 15px 30px;
display: inline;
}
.footermenu nav {
display: inline;
}
</style>
<body>
<footer class="footer">
<h3>© ALL RIGHTS RESERVED </h3>
<nav class="footermenu">
<ul>
<li>ABOUT US</li>
<li>MORE ABOUT</li>
</ul>
</nav>
</footer>
</body>
community! I'm doing basic training on WebDev and ran into a problem with inline positioning.
I created a footer with H3 and nav (ul>li*2). I want H3 to be positioned on the left and li anywhere, but on the same line as H3, in principle (haven't questioned the position relative to the center of the page yet).
Solved the problem through display: inline;, but for each element, but could not find a more elegant solution and without duplication
.class footer {
display: inline;
}
.class h3 {
display: inline;
}
and so on.
Please help me find a competent and elegant solution. Thank you!
<footer class="footer">
<h3>© ALL RIGHTS RESERVED </h3>
<nav class="footermenu">
<ul>
<li>ABOUT US</li>
<li>MORE ABOUT</li>
</ul>
</nav>
</footer>
.footer h3 {
width: fit-content;
margin: 15px 30px;
display: inline;
}
.footermenu nav {
display: inline;
}
Try to use flex in order to set the position of elements
footer {display: flex;}
More info here
As said #KristiK, flex is a good way.
But you have a wrong.
.footermenu nav doesn't have sense in your code. It points to nav elements inside .footermenu. So these are appropriate selectors for styling to nav in your code:
nav or .footermenu or nav.footermenu.
<style>
.footer h3 {
width: fit-content;
margin: 15px 30px;
}
ul {
margin-top: 20px;
display: flex;
}
a {
padding-left: 20px;
}
</style>
<body>
<footer class="footer" style="display: flex">
<h3>© ALL RIGHTS RESERVED </h3>
<nav class="footermenu">
<ul style="list-style: none;">
<li>ABOUT US</li>
<li>MORE ABOUT</li>
</ul>
</nav>
</footer>
</body>

Space items in inline list

How do I create enough space between the items in the following list so that users of mobile devices don't click on the wrong link. Note that the list is horizontal. Note also that the list can wrap so the issue is both in the vertical and horizontal planes.
ul#menu li {
display:inline;
}
<ul id="menu">
<li>Ant</li>
<li>Bear</li>
<li>Cat</li>
<li>Dog</li>
<li>Elf</li>
<li>Fish</li>
<li>Gorilla</li>
<li>Hourse</li>
<li>Indigo</li>
<li>Japan</li>
<li>Knight</li>
<li>Laos</li>
<li>Mouse</li>
<li>Nigeria</li>
<li>Orange</li>
<li>Pony</li>
<li>Queen</li>
<li>Rat</li>
<li>Stoat</li>
<li>Tiger</li>
<li>Uganda</li>
<li>Vermont</li>
<li>Wales</li>
<li>Xray</li>
<li>York</li>
<li>Zambia</li>
</ul>
You can use flexbox layout model, and then margin-right, margin-bottom.
ul#menu {
list-style: none;
display: flex;
flex-wrap: wrap;
}
ul#menu li {
margin-right: 15px;
margin-bottom: 15px;
}
<ul id="menu">
<li>Ant</li>
<li>Bear</li>
<li>Cat</li>
<li>Dog</li>
<li>Elf</li>
<li>Fish</li>
<li>Gorilla</li>
<li>Hourse</li>
<li>Indigo</li>
<li>Japan</li>
<li>Knight</li>
<li>Laos</li>
<li>Mouse</li>
<li>Nigeria</li>
<li>Orange</li>
<li>Pony</li>
<li>Queen</li>
<li>Rat</li>
<li>Stoat</li>
<li>Tiger</li>
<li>Uganda</li>
<li>Vermont</li>
<li>Wales</li>
<li>Xray</li>
<li>York</li>
<li>Zambia</li>
</ul>
Try adding margin: 5px or line-height: 200%. First moves it horizontally, next vertically.
ul#menu {
display: flex;
flex-flow: row wrap;
border: 1px solid grey;
}
ul#menu li {
margin: 10px;
list-style-type: none;
background: lightgrey;
padding: 5px 10px;
}
<ul id="menu">
<li>Ant</li>
<li>Bear</li>
<li>Cat</li>
<li>Dog</li>
<li>Elf</li>
<li>Fish</li>
<li>Gorilla</li>
<li>Hourse</li>
<li>Indigo</li>
<li>Japan</li>
<li>Knight</li>
<li>Laos</li>
<li>Mouse</li>
<li>Nigeria</li>
<li>Orange</li>
<li>Pony</li>
<li>Queen</li>
<li>Rat</li>
<li>Stoat</li>
<li>Tiger</li>
<li>Uganda</li>
<li>Vermont</li>
<li>Wales</li>
<li>Xray</li>
<li>York</li>
<li>Zambia</li>
</ul>

Adaptative width with flexbox and flex-grow

I'm trying to set up a menu bar with the
following template
I'm trying this with FlexBox but I can't figure out what's wrong. Here's the HTML :
<nav>
<ul>
<li id="navleft">
<img src="images/logo.png" alt="logo wikihow">
</li>
<li class="navothers">
<img src="images/contribuye.png" alt="contribuye">
<p>CONTRIBUYE</p>
</li>
<li class="navothers">
<img src="images/explora.png" alt="explora">
<p>EXPLORA</p>
</li>
<li class="navothers">
<img src="images/entrar.png" alt="entrar">
<p>ENTRAR</p>
</li>
<li class="navothers"><img src="images/mensajes.png" alt="mensajes">
<p>MENSAJES</p>
</li>
</ul>
</nav>
And I apply the following styles in CSS :
nav {
padding: 0 30% 0 30%;
}
nav ul {
display:flex;
justify-content:center;
align-items:center;
background-color: #93B874;
}
#navleft{
flex-grow:32;
flex-shrink:1;
}
#navleft img{
width: 144px;
vertical-align:center
}
.navothers{
flex-grow:1;
flex-shrink:4;
}
I get the following result
My problem is that all the elements in the right part (with the "navothers" class) dont have the same width ! They just adapt depending on the size of the text they have.
I may have mixed a lot of things, what have I done wrong ?
Your flex-grow value for #navleft is too big, and your container is too small. Your items can't grow they don't have enough room. Try this :
CSS :
nav {
padding: 0 10% 0 10%; // imho it's a strange way to center your nav. Reduced to show you that you're lacking room.
}
nav ul {
display: flex;
justify-content: center;
align-items: center;
background-color: #93B874;
}
#navleft {
flex: 2; // You may tune this one but keep room for your other items !
}
#navleft img {
width: 144px;
vertical-align: center
}
.navothers {
flex: 1;
border: solid 1px #000;
}
HTML :
<nav>
<ul>
<li id="navleft">
<img src="images/logo.png" alt="logo wikihow">
</li>
<li class="navothers">
<img src="images/contribuye.png" alt="contribuye">
<p>CONTRIBUYE</p>
</li>
<li class="navothers">
<img src="images/explora.png" alt="explora">
<p>EXPLORA</p>
</li>
<li class="navothers">
<img src="images/entrar.png" alt="entrar">
<p>ENTRAR</p>
</li>
<li class="navothers">
<img src="images/mensajes.png" alt="mensajes">
<p>MENSAJES</p>
</li>
</ul>
</nav>
https://jsfiddle.net/me7t2hv3/

Trying to have header and unordered list on same line

I feel like an idiot asking this and I've scoured the internet looking for some answer and didn't seem to find anything.
All I'm trying to do is have my header element and my unordered list on the same line without cancelling the specific margins both of them contain.
h3 {
text-align: left;
margin: 40px 0px 0px 40px;
}
ul {
text-align: right;
}
ul li {
list-style: none;
display: inline;
margin: 0px 20px 0px 0px;
}
<body>
<h3 id="header"> Darius Spady </h3>
<ul>
<li> About </li>
<li> Projects </li>
<li> Contact </li>
</ul>
</body>
Any help would be appreciated! Thank you!
I would introduce a parent element and use display: flex; justify-content: space-between; to put them on the same line, separated by the available white space. You can use align-items to vertically align them as well.
* {margin:0;padding:0;}
ul li {
list-style: none;
display: inline;
margin: 0px 20px 0px 0px;
}
h3 {
margin: 40px 0px 0px 40px;
}
.flex {
display: flex;
justify-content: space-between;
align-items: baseline;
}
<header class="flex">
<h3 id="header"> Darius Spady </h3>
<ul>
<li> About </li>
<li> Projects </li>
<li> Contact </li>
</ul>
</header>
You may consider using Bootstrap and will be really simple to accomplish what you need.
<!-- Using Bootstrap -->
<div class="row">
<div class="col-md-4">
<h3>Darius Spady</h3>
</div>
<div class="col-md-4">
<ul class="list-group">
<li class="list-group-item">About</li>
<li class="list-group-item">Projects</li>
<li class="list-group-item">Contact</li>
</ul>
</div>
</div>
or you can use tables so don't need to play with styles...
<!-- HTML only -->
<table>
<tr>
<td>
<h3>Darius Spady</h3>
</td>
<td>
<ul>
<li> About </li>
<li> Projects </li>
<li> Contact </li>
</ul>
</td>
</tr>
</table>

How to center a nav bar?

I am having troouble centering my nav bar to the middle of my page. I have not done any css as of yet.
HTML
<div class = "menu-wrap">
<nav class = "navMenu">
<ul class = "ulMenu">
<li>Home</li>
<li>
Products<span class="arrow">▼</span>
<ul>
<li>#</li>
<li>#</li>
</ul>
</li>
<li>Contact Us</li>
<li>About </li>
</ul>
</nav>
You need to add some CSS to specify the class properties, which will define the properties of the elements you have defined as members of those classes.
Something like this
#menu-wrap {
width:750px;
margin:0 auto;
list-style:none;
}
You can refer to this tutorial
Add align= "center"
<div class = "menu-wrap" align="center">
So in order to align layout elements. You'll want to use CSS. Hopefully this will get you started:
When making a horizontal nav element, we usually use the float or display:inline properties to force the individual links on one line. To center the whole nav element you could give it a width as I've done here, which allows us to set its margin to auto which horizontally centers the whole div.
nav ul li{
list-style:none;
float:left;
margin:5px;
}
nav{
height:50px;
display:table;
background:#eee;
margin:auto;
}
<div class = "menu-wrap">
<nav class = "navMenu">
<ul class = "ulMenu">
<li>Home</li>
<li>
Products<span class="arrow">▼</span>
<ul>
<li>#</li>
<li>#</li>
</ul>
</li>
<li>Contact Us</li>
<li>About </li>
</ul>
</nav>
Still, it looks horrible. With a little more CSS styles, you can turn this menu into something great.
.ul {
display: -webkit-flex;
display: flex;
-webkit-justify-content: center;
justify-content: center;
-webkit-align-items: center;
align-items: center;
width: 100%;
height: auto;
background-color: lightgrey;
}
.li {
background-color: white;
padding: 0.5rem;
margin: 0.5rem;
-webkit-align-self: center;
align-self: center;
}
a .li:hover {
color: #000000;
background-color: lightgreen;
cursor: pointer;
}
<div class = "menu-wrap">
<div class="ul">
<a><div class="li">Home</div></a>
<a><div class="li">Products</div></a>
<a><div class="li">Contact Us</div></a>
<a><div class="li">About</div></a>
</div>
</div>