求大神帮忙用 js 给div加属性

求大神帮忙用 js 给div加属性,第1张

container = document.createElement('div')

container.style.width = 800 + "px"// 宽度

container.style.height = 600 + "px"// 高度

document.body.appendChild(container)

大概3种 只限于DIV+CSS

1. <div style="width:100pxheight:100pxbackground:red">这是第一种方法</div>

2.<style>.test{width:100pxheight:100pxbackground:green}</style>

<div class="test">这是第二种方法</div>

或者这样写

<style>#test{width:100pxheight:100pxbackground:green}</style>

<div id="test">这是第二种方法</div>

PS: ID不能重复使用 就是说一个页面上只能用一个同名ID 而CLASS不限制

3.引用外部文件

<link href="css/style.css" rel="stylesheet" type="text/css" />

<div class="test">这是第三种方法</div>

和方法二相似


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11675484.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存