第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何反轉html中元素的流動

如何反轉html中元素的流動

哆啦的時光機 2023-03-03 15:53:07
我怎樣才能做到這一點<div>   <p>A</p>   <p>B</p>   <p>C</p> </div>我期望的結果C乙A我怎樣才能做到這一點?
查看完整描述

2 回答

?
四季花海

TA貢獻1811條經驗 獲得超5個贊

Use flexbox :

.wrapper{

display :flex;

flex-direction: column-reverse;

}

<div class='wrapper'>

  <p>A</p>

  <p>B</p>

  <p>C</p>

</div>


查看完整回答
反對 回復 2023-03-03
?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

使用 CSS

您可以通過指定顯示來反向排序項目flex。


div {

  display: flex;

  flex-direction: column-reverse;

}

<div>

  <p>A</p>

  <p>B</p>

  <p>C</p>

</div>

或者,您可以通過沿方向軸翻轉子元素來轉換子元素。翻轉整個div,然后p在 div 內翻轉每個。雖然這有效,但應該避免使用flex. 注意:轉換元素后,選擇會變得非常不穩(wěn)定。


div, p {

  transform: scale(1, -1);

}

<div>

  <p>A</p>

  <p>B</p>

  <p>C</p>

</div>

使用 JavaScript

您也可以在 JavaScript 中使用一個函數(shù)來執(zhí)行此操作,該函數(shù)遍歷節(jié)點childNodes并將它們插入到第一個子節(jié)點之前。


/**

 * @describe Reverses the child nodes of a node in-place.

 * @param {Node} node - The parent of the child nodes to be reversed

 */

const reverseChildNodes = node => {

  for (let i = 1; i < node.childNodes.length; i++) {

    node.insertBefore(node.childNodes[i], node.firstChild);

  }

}


if (Element.prototype.reverseChildren === undefined) {

  Element.prototype.reverseChildren = function() {

    reverseChildNodes(this);

  };

}


// Global function

reverseChildNodes(document.querySelector('.section:first-child'));


// Prototype method on Node object

[...document.querySelectorAll('.section')].pop().reverseChildren();

.section { border: thin solid grey; margin: 0.25em; padding: 0.25em; }

<div class="section">

  <p>A</p>

  <p>B</p>

  <p>C</p>

</div>


<div class="section">

  <p>A</p>

  <p>B</p>

  <p>C</p>

</div>


查看完整回答
反對 回復 2023-03-03
  • 2 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號