gpt4 book ai didi

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

转载 作者:bug小助手 更新时间:2023-10-22 17:34:43 26 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:

Flexbox项目可以使用order属性以任意顺序显示:




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.

注意:李的第二个元素,即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属性允许灵活地按照自定义的视觉顺序排列灵活项,而不管它们在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解决方案可以解决所有问题。

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