gpt4 book ai didi

Switch order of specific list items? [closed](是否切换特定列表项的顺序?[已关闭])

转载 作者:bug小助手 更新时间:2023-10-24 19:04:12 25 4
gpt4 key购买 nike




Is there a way to switch the display order of specific list items? For example, with the following list, can the order of the second and third items be switched when displayed?

有没有办法切换特定列表项的显示顺序?例如,在下面的列表中,第二项和第三项在显示时是否可以切换顺序?


The list:

名单如下:


 <ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>

How I want it displayed:

我希望它如何显示:



  • A

  • C

  • B


更多回答

only with css ? (see tag)

只有css吗?(请参阅标签)

Why do you want to do such a thing?

你为什么要做这样的事情?

You can easily change the display order of the elements with CSS, but not the HTML order. Do you just want to change the display order?

您可以使用CSS轻松更改元素的显示顺序,但不能更改HTML顺序。是否只想更改显示顺序?

Its on wordpress plugin that's why.

它在WordPress插件上,这就是为什么。

优秀答案推荐

Flexbox items can be displayed in an arbitrary order by using the order property:

通过使用Order属性,可以按任意顺序显示Flexbox项:




ul {
display: flex;
flex-direction: column;
}

li:nth-child(2) {
order: 2;
}

li:nth-child(3) {
order: 1;
}

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>





You can simply do it by using below 2 steps:

您只需使用以下两个步骤即可完成:



  1. ul {display : flex; flex-direction: column;} this will make list in column.



  2. As you want to change order of only second child you can use
    li:nth-child(2) { order: 2;} this will change order of B to third and C to second.




Note: Second Element of li which is B will render at last as we have not assigned order to it.

注:Li的第二个元素是B,因为我们没有给它分配顺序,所以最后将呈现它。


Thanks...

谢谢..。




ul {
display: flex;
flex-direction: column;
}

li:nth-child(2) {
order: 2;
}

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>





The order property in Flexbox grants the flexibility to arrange flex items in a customized visual order, irrespective of their original placement in the HTML structure.

Flexbox中的Order属性提供了以自定义视觉顺序排列Flex项的灵活性,而不考虑它们在HTML结构中的原始位置。




ul {
display: flex;
flex-direction: column;
}

li:nth-child(2) {
order: -1; /* Reverse the order of the second child */
}

li:nth-child(3) {
order: -2; /* Reverse the order of the third child */
}

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>




更多回答

I think OP wants css only answer.

我认为OP只想要css的答案。

The ugly css solution won't work if the text is too long. I think css only support for 1 height. But js solution can solve everything.

如果文本太长,难看的css解决方案将不起作用。我认为css只支持1个高度。但js解决方案可以解决所有问题。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com