About the order and direction of the list in CSS Flexbox
If you list the list with flex, it looks something like this.
12
34
56
How can I arrange this in flex like this?
Is there a way to do it?
14
25
36
By the way, in case of increasing to seven
15
26
37
4
It is like feeling.
.list_number {
display: flex;
flex-wrap: wrap;
}
.list_number > li {
width: 50%
}<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>css flexbox
add a comment |
If you list the list with flex, it looks something like this.
12
34
56
How can I arrange this in flex like this?
Is there a way to do it?
14
25
36
By the way, in case of increasing to seven
15
26
37
4
It is like feeling.
.list_number {
display: flex;
flex-wrap: wrap;
}
.list_number > li {
width: 50%
}<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>css flexbox
4
I think columns is more suitable in this case : developer.mozilla.org/en-US/docs/Web/CSS/columns
– Temani Afif
Jan 19 at 16:06
1
jsfiddle.net/kjusobmd
– VXp
Jan 19 at 17:00
add a comment |
If you list the list with flex, it looks something like this.
12
34
56
How can I arrange this in flex like this?
Is there a way to do it?
14
25
36
By the way, in case of increasing to seven
15
26
37
4
It is like feeling.
.list_number {
display: flex;
flex-wrap: wrap;
}
.list_number > li {
width: 50%
}<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>css flexbox
If you list the list with flex, it looks something like this.
12
34
56
How can I arrange this in flex like this?
Is there a way to do it?
14
25
36
By the way, in case of increasing to seven
15
26
37
4
It is like feeling.
.list_number {
display: flex;
flex-wrap: wrap;
}
.list_number > li {
width: 50%
}<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>.list_number {
display: flex;
flex-wrap: wrap;
}
.list_number > li {
width: 50%
}<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>.list_number {
display: flex;
flex-wrap: wrap;
}
.list_number > li {
width: 50%
}<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>css flexbox
css flexbox
edited Jan 19 at 16:07
Hongarc
2,2601725
2,2601725
asked Jan 19 at 15:57
ccocco
82
82
4
I think columns is more suitable in this case : developer.mozilla.org/en-US/docs/Web/CSS/columns
– Temani Afif
Jan 19 at 16:06
1
jsfiddle.net/kjusobmd
– VXp
Jan 19 at 17:00
add a comment |
4
I think columns is more suitable in this case : developer.mozilla.org/en-US/docs/Web/CSS/columns
– Temani Afif
Jan 19 at 16:06
1
jsfiddle.net/kjusobmd
– VXp
Jan 19 at 17:00
4
4
I think columns is more suitable in this case : developer.mozilla.org/en-US/docs/Web/CSS/columns
– Temani Afif
Jan 19 at 16:06
I think columns is more suitable in this case : developer.mozilla.org/en-US/docs/Web/CSS/columns
– Temani Afif
Jan 19 at 16:06
1
1
jsfiddle.net/kjusobmd
– VXp
Jan 19 at 17:00
jsfiddle.net/kjusobmd
– VXp
Jan 19 at 17:00
add a comment |
3 Answers
3
active
oldest
votes
There are many ways you can achieve this but as @TemaniAfif mentioned in the comments, the easiest method to do this would be to use columns like this:
ul{
columns: 2;
}
Just add that to your css and you can achieve the same thing with just one line of code.
Hope this helps.
This is probably the cleanest and most straightforward CSS-only approach of doing this. +1
– AndrewL64
Jan 19 at 17:42
Oh I did not see his comment , But anyways , Thank you sir
– Thanveer Shah
Jan 19 at 17:48
add a comment |
flex-direction: column and max-height should do the trick.
Please post a complete answer. Show us how your answer works.
– Michael_B
Jan 19 at 18:16
add a comment |
If you are open to a JavaScript approach, you can just retrieve the height of an <li> element (assuming that all the <li> elements are the same height), multiply it into half the number of <li>'s inside your <ul> element and set the height of the ul to that value. (If the number of <li>'s is an odd number, just add the height of one more <li> to the value.)
Also, make sure the parent flex container .list_number has the properties flex-direction: column; and flex-wrap: wrap; so that elements will automatically go the next column when previous elements have filled the height.
Check and run the Code Snippet below for a practical example of what I have described above:
/* JavaScript */
const div = document.querySelector(".list_number");
const lists = document.querySelectorAll(".list_number li");
const height = window.getComputedStyle(lists[0]).height;
div.style.height = (lists.length % 2 == 0) ? (parseInt(height) * lists.length / 2) + "px" : (parseInt(height) * lists.length / 2) + parseInt(height) + "px";/* CSS */
html, body {width: 100%; height: 100%; margin: 0px; padding: 0px;}
.list_number{
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}<!-- HTML -->
<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54268852%2fabout-the-order-and-direction-of-the-list-in-css-flexbox%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are many ways you can achieve this but as @TemaniAfif mentioned in the comments, the easiest method to do this would be to use columns like this:
ul{
columns: 2;
}
Just add that to your css and you can achieve the same thing with just one line of code.
Hope this helps.
This is probably the cleanest and most straightforward CSS-only approach of doing this. +1
– AndrewL64
Jan 19 at 17:42
Oh I did not see his comment , But anyways , Thank you sir
– Thanveer Shah
Jan 19 at 17:48
add a comment |
There are many ways you can achieve this but as @TemaniAfif mentioned in the comments, the easiest method to do this would be to use columns like this:
ul{
columns: 2;
}
Just add that to your css and you can achieve the same thing with just one line of code.
Hope this helps.
This is probably the cleanest and most straightforward CSS-only approach of doing this. +1
– AndrewL64
Jan 19 at 17:42
Oh I did not see his comment , But anyways , Thank you sir
– Thanveer Shah
Jan 19 at 17:48
add a comment |
There are many ways you can achieve this but as @TemaniAfif mentioned in the comments, the easiest method to do this would be to use columns like this:
ul{
columns: 2;
}
Just add that to your css and you can achieve the same thing with just one line of code.
Hope this helps.
There are many ways you can achieve this but as @TemaniAfif mentioned in the comments, the easiest method to do this would be to use columns like this:
ul{
columns: 2;
}
Just add that to your css and you can achieve the same thing with just one line of code.
Hope this helps.
edited Jan 19 at 17:46
AndrewL64
9,69041843
9,69041843
answered Jan 19 at 17:40
Thanveer ShahThanveer Shah
391110
391110
This is probably the cleanest and most straightforward CSS-only approach of doing this. +1
– AndrewL64
Jan 19 at 17:42
Oh I did not see his comment , But anyways , Thank you sir
– Thanveer Shah
Jan 19 at 17:48
add a comment |
This is probably the cleanest and most straightforward CSS-only approach of doing this. +1
– AndrewL64
Jan 19 at 17:42
Oh I did not see his comment , But anyways , Thank you sir
– Thanveer Shah
Jan 19 at 17:48
This is probably the cleanest and most straightforward CSS-only approach of doing this. +1
– AndrewL64
Jan 19 at 17:42
This is probably the cleanest and most straightforward CSS-only approach of doing this. +1
– AndrewL64
Jan 19 at 17:42
Oh I did not see his comment , But anyways , Thank you sir
– Thanveer Shah
Jan 19 at 17:48
Oh I did not see his comment , But anyways , Thank you sir
– Thanveer Shah
Jan 19 at 17:48
add a comment |
flex-direction: column and max-height should do the trick.
Please post a complete answer. Show us how your answer works.
– Michael_B
Jan 19 at 18:16
add a comment |
flex-direction: column and max-height should do the trick.
Please post a complete answer. Show us how your answer works.
– Michael_B
Jan 19 at 18:16
add a comment |
flex-direction: column and max-height should do the trick.
flex-direction: column and max-height should do the trick.
answered Jan 19 at 16:22
BenjaminBenjamin
264
264
Please post a complete answer. Show us how your answer works.
– Michael_B
Jan 19 at 18:16
add a comment |
Please post a complete answer. Show us how your answer works.
– Michael_B
Jan 19 at 18:16
Please post a complete answer. Show us how your answer works.
– Michael_B
Jan 19 at 18:16
Please post a complete answer. Show us how your answer works.
– Michael_B
Jan 19 at 18:16
add a comment |
If you are open to a JavaScript approach, you can just retrieve the height of an <li> element (assuming that all the <li> elements are the same height), multiply it into half the number of <li>'s inside your <ul> element and set the height of the ul to that value. (If the number of <li>'s is an odd number, just add the height of one more <li> to the value.)
Also, make sure the parent flex container .list_number has the properties flex-direction: column; and flex-wrap: wrap; so that elements will automatically go the next column when previous elements have filled the height.
Check and run the Code Snippet below for a practical example of what I have described above:
/* JavaScript */
const div = document.querySelector(".list_number");
const lists = document.querySelectorAll(".list_number li");
const height = window.getComputedStyle(lists[0]).height;
div.style.height = (lists.length % 2 == 0) ? (parseInt(height) * lists.length / 2) + "px" : (parseInt(height) * lists.length / 2) + parseInt(height) + "px";/* CSS */
html, body {width: 100%; height: 100%; margin: 0px; padding: 0px;}
.list_number{
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}<!-- HTML -->
<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>add a comment |
If you are open to a JavaScript approach, you can just retrieve the height of an <li> element (assuming that all the <li> elements are the same height), multiply it into half the number of <li>'s inside your <ul> element and set the height of the ul to that value. (If the number of <li>'s is an odd number, just add the height of one more <li> to the value.)
Also, make sure the parent flex container .list_number has the properties flex-direction: column; and flex-wrap: wrap; so that elements will automatically go the next column when previous elements have filled the height.
Check and run the Code Snippet below for a practical example of what I have described above:
/* JavaScript */
const div = document.querySelector(".list_number");
const lists = document.querySelectorAll(".list_number li");
const height = window.getComputedStyle(lists[0]).height;
div.style.height = (lists.length % 2 == 0) ? (parseInt(height) * lists.length / 2) + "px" : (parseInt(height) * lists.length / 2) + parseInt(height) + "px";/* CSS */
html, body {width: 100%; height: 100%; margin: 0px; padding: 0px;}
.list_number{
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}<!-- HTML -->
<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>add a comment |
If you are open to a JavaScript approach, you can just retrieve the height of an <li> element (assuming that all the <li> elements are the same height), multiply it into half the number of <li>'s inside your <ul> element and set the height of the ul to that value. (If the number of <li>'s is an odd number, just add the height of one more <li> to the value.)
Also, make sure the parent flex container .list_number has the properties flex-direction: column; and flex-wrap: wrap; so that elements will automatically go the next column when previous elements have filled the height.
Check and run the Code Snippet below for a practical example of what I have described above:
/* JavaScript */
const div = document.querySelector(".list_number");
const lists = document.querySelectorAll(".list_number li");
const height = window.getComputedStyle(lists[0]).height;
div.style.height = (lists.length % 2 == 0) ? (parseInt(height) * lists.length / 2) + "px" : (parseInt(height) * lists.length / 2) + parseInt(height) + "px";/* CSS */
html, body {width: 100%; height: 100%; margin: 0px; padding: 0px;}
.list_number{
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}<!-- HTML -->
<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>If you are open to a JavaScript approach, you can just retrieve the height of an <li> element (assuming that all the <li> elements are the same height), multiply it into half the number of <li>'s inside your <ul> element and set the height of the ul to that value. (If the number of <li>'s is an odd number, just add the height of one more <li> to the value.)
Also, make sure the parent flex container .list_number has the properties flex-direction: column; and flex-wrap: wrap; so that elements will automatically go the next column when previous elements have filled the height.
Check and run the Code Snippet below for a practical example of what I have described above:
/* JavaScript */
const div = document.querySelector(".list_number");
const lists = document.querySelectorAll(".list_number li");
const height = window.getComputedStyle(lists[0]).height;
div.style.height = (lists.length % 2 == 0) ? (parseInt(height) * lists.length / 2) + "px" : (parseInt(height) * lists.length / 2) + parseInt(height) + "px";/* CSS */
html, body {width: 100%; height: 100%; margin: 0px; padding: 0px;}
.list_number{
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}<!-- HTML -->
<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>/* JavaScript */
const div = document.querySelector(".list_number");
const lists = document.querySelectorAll(".list_number li");
const height = window.getComputedStyle(lists[0]).height;
div.style.height = (lists.length % 2 == 0) ? (parseInt(height) * lists.length / 2) + "px" : (parseInt(height) * lists.length / 2) + parseInt(height) + "px";/* CSS */
html, body {width: 100%; height: 100%; margin: 0px; padding: 0px;}
.list_number{
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}<!-- HTML -->
<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>/* JavaScript */
const div = document.querySelector(".list_number");
const lists = document.querySelectorAll(".list_number li");
const height = window.getComputedStyle(lists[0]).height;
div.style.height = (lists.length % 2 == 0) ? (parseInt(height) * lists.length / 2) + "px" : (parseInt(height) * lists.length / 2) + parseInt(height) + "px";/* CSS */
html, body {width: 100%; height: 100%; margin: 0px; padding: 0px;}
.list_number{
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}<!-- HTML -->
<ul class="list_number">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>answered Jan 19 at 17:34
AndrewL64AndrewL64
9,69041843
9,69041843
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54268852%2fabout-the-order-and-direction-of-the-list-in-css-flexbox%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
I think columns is more suitable in this case : developer.mozilla.org/en-US/docs/Web/CSS/columns
– Temani Afif
Jan 19 at 16:06
1
jsfiddle.net/kjusobmd
– VXp
Jan 19 at 17:00