HTML
又稱flexbox,是為了適應不同螢幕尺寸和顯示設備而生的佈局模式 (en-US)。 針對許多應用而言,不用 floats 的彈性盒子模型會比塊狀模型, 彈性容器的邊緣也不會與內容的邊緣重疊。 Example : <>div id="outerDiv"> <>div id="div1">1 <>/div> <>div id="div2">2 <>/div> <>div id="div3">3 <>/div> <>div id="div4">4 <>/div> <>div id="div5">5 <>/div> <>/div> #outerDiv div { display:inherit;flex:1; justify-content: center; align-items : center;font-size: 20px ; border: 1px solid black; } outerDiv { width: 100%; height:200px; border:3px solid; display:flex; flex-direction:row ; }
align-content:交錯軸為多行時的的整體對齊方式。 align-content 屬性 flex-start | center | flex-end | space-between | space-around | space-evenly
<style> #outside_DIV{ height: 250px;background: #def; display: flex; flex-wrap: wrap; align-content: stretch ; } </style> <div id="outside_DIV"> <div id="div1">01</div> <div id="div2">02</div> <div id="div3">03</div> <div id="div4">04</div> <div id="div5">05</div> </div>
在進入探討之前,先來簡單敘述一下這三者代表的是什麼,有些基本概念, 再來了解或許會比較好理解: align-self:交錯軸個別項目的對齊方式。 align-self屬性: stretch 預設 | flex-start | center | flex-end | baseline <style> #div1 { align-self: flex-start } #div2 { align-self: flex-end } #div3 { align-self: center } #div4 { align-self: stretch } #div5 { align-self: baseline } .outside_DIV{ display: flex ; height: 150px ; background: #def ; } </style>
align-items:當交錯軸只有一行時的對齊方式。 align-items 屬性: stretch 預設 | center | flex-start | flex-end | baseline <>div id="outside_DIV" > <>div id="item1">1<>/div> <>div id="item2">2<>/div> <>div id="item3">3<>/div> <>div id="item4">4<>/div> <>div id="item5">5<>/div> <>/div> #outside_DIV{ height: 200px ; width: 100%px; display: flex ; flex-wrap: wrap; background-color: #8c8c8c; } #outside_DIV div { width: 20%; display: flex; align-items: center; justify-content: stretch ; } align-items: stretch center flex-start flex-end baseline
<style> #div1 { order: 3 } #div2 { order: 1 } #div3 { order: 2 } #div4 { order: 5 } #div5 { order: 4 } </style>
Example : <>div class="Table"> <>div class="Tbody"> <>div class="Tr"> <>div class="td">123<>/div> <>div class="td">456<>/div> <>/div> <>div class="Tr"> <>div class="td">ABC<>/div> <>div class="td">DEF<>/div> <>/div> <>/div> <>/div> <>style> .Table { display:table;border-style:double} .Tbody { display:table-row-group} .Tr { display:table-row} .td { display:table-cell;border-style:double ; padding:0 10px} <>/style>
Example 1 <div class="Table"> <!-- similar <table>--> <div class="tr" > <!-- similar <tr>-----> <!-- similar <td> ------> <div class="td alignCenter verticalAlignTop" > text-align:center;<br>vertical-align:top;</div> <div class="td alignCenter verticalAlignMiddle"> text-align:center;<br>vertical-align:middle;</div> <div class="td alignCenter verticalAlignBottom"> text-align:center;<br>vertical-align: bottom;</div> </div> <div class="tr" > <!-- similar <tr>--> <!-- similar <td> ------> <div class="td alignLeft verticalAlignTop"> text-align:left;<br>vertical-align:top;</div> <div class="td alignCenter verticalAlignMiddle" > text-align: center;<br>vertical-align: middle;</div> <div class="td alignRight verticalAlignBottom " > text-align:right ;<br>vertical-align: bottom;</div> </div> </div> <style> .Table {display:table;width: 100%;font-size: 23px;} div {border: 1px solid #f00;} .tr {display:table-row;height: 200px; } .td {display:table-cell;width:33%;} .alignCenter {text-align:center;} .alignLeft {text-align:left;} .alignRight {text-align:right;} .verticalAlignTop {vertical-align:top;} .verticalAlignMiddle {vertical-align:middle;} .verticalAlignBottom {vertical-align:bottom;} </style>
<>code> 123 code 程式碼<>/code>
執行 document.execCommand('copy') 就可以將當前選取範圍複製到剪貼簿。 <>div id="Mid"> <>input class="Input" value="width" > <>input class="Input" value="height" > <>input class="Input" value="select" > <>input class="Input" value="center" > <>input class="Input" value="button" > <>input class="Input" value="children" > <>input class="Input" value="length" > <>input class="Input" value="alert()" > <>input class="Input" value="nobn" > <>/div> <>br> <>div id="ok">copy to clipboard <>/div> <>script> var Input=document.getElementsByClassName("Input"); for(x=0 ; x < Input.length ;x++){ Input[x].style.width=((Input[x].value.length+1)*8)+'px'; Input[x].title=Input[x].value+" onclick copy to clipboard"; Input[x].readOnly = true;} Mid.addEventListener('click', function(e){ e.target.select() ; document.execCommand('copy') ; navigator.clipboard.readText().then(function(text){ ok.innerHTML=text+" copy to clipboard "; }); }) <>/script>
navigator.clipboard.writeText("copyText") 將文字 copyText 複製到剪貼簿。 navigator.clipboard.readText().then(text => { DP.innerHTML ="剪貼簿中的文本內容 = " + text }) <>input type="text" id="inTxT" value="123456" /> <>button onclick="COPY()" >COPY to clipboard <>/button> <>div id="DP">剪貼簿中的文本內容<>/div> <>script> function COPY(){ navigator.clipboard.writeText(inTxT.value); navigator.clipboard.readText().then(text => { DP.innerHTML ="剪貼簿中的文本內容 = " + text }) } <>/script>
人之初 性本善 性相近 習相遠 苟不教 性乃遷 教之道 貴以專
document.execCommand('copy') 就可以將當前選取範圍複製到剪貼簿。 window.getSelection() 它代表的是目前使用者所選的文本範圍內容。 <>p>人之初 性本善 性相近 習相遠 苟不教 性乃遷 教之道 貴以專<>/p> <>button onclick="COPY()" >copy to clipboard <>/button> <>script> function COPY() { document.execCommand('copy'); var selection = window.getSelection(); alert( selection.toString() ); } <>/script>