怎么给html标签写css样式

如题所述

1、直接使用行内样式,即在html标签上使用style

<div style="width:100px;height:100px;background:red;">div内容</div>

2、先定义css样式,再给html的class属性赋值

<style>
.content{
    width:100px;
    height:100px;
    background:red;
}
</style>

<div class="content">
    div测试内容
</div>

总结:两种方式效果是一致的,只是第二种方式可进行重用,只要html元素class属性相同即可

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-08-04
<style>
.a{hegith:30px;}
</style>
<div class="a"></div>
等同于
<div class="a" style="height:30px;"></div>

相似回答