// HTML:
<h1 class="title">
</h1>
// CSS:
.blue {
color: blue;
font-size: 24px;
}
JavaScript:
createElement,動態新增一個元素
setAttribute,動態設定str的屬性與值
// 新增一個宣告變數名稱: str,並增加標籤元素為: <em>
var str = document.createElement('em');
// 替 str 掛上一段文字:'富邦悍將'
str.textContent = '富邦悍將';
// 替 str 設定屬性,更動內容為'class','blue'
str.setAttribute('class','blue');
預期這串文字的效果會吃到 css 的藍色以及大小為:24效果。
上面已經完成了:新增 em 標籤、textContent、透過屬性設定吃樣式
最後的步驟就是將設定好的 str 掛在你想要的節點上,也就是 .title
document.querySelector('.title').appendChild(str);
<h1 class="title">
<em>中信兄弟</em>
</h1>
Learn More →
JavaScript - DOM 元素
使目標元素透明度改變 opacity 可設定範圍: 0 ~ 1.0 // 0 為完全透明。 <h1>標題測試</h1> h1 { display: inline-block; background: red; }
Dec 10, 2022border-collapse: 假設我有個表格長這樣: <table> <tr> <th>標題一</th> <th>標題二</th> <th>標題三</th> </tr>
Dec 10, 2022在 CSS 製作時,可以被編輯的項目樣式: 以此 HTML ul 做範例: <ul> <li>2008:團團圓圓到台灣</li> <li>2013:圓仔出生</li> <li>還沒有其他熊貓</li> </ul>
Dec 10, 2022什麼是 default value 指 HTML Tag 本身具備的 CSS 效果: <h1>,本身的文字大小就比較大,font-size 就非常明顯。 <div>,本身具備 - display:block;等。 透過 box-model 瀏覽並且觀察 Tag 本身的 default styling
Dec 10, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up