<style type=“text/css“>详解

本文介绍了在HTML中应用CSS样式的三种常见方法:内部引用,通过style标签在HTML头部定义样式;外部引用,利用link标签链接外部CSS文件;以及内联引用,直接在HTML元素中定义CSS样式。每种方法的特点和适用场景都有所不同,内部引用方便管理,外部引用保持页面结构清晰,内联引用则适用于特定样式需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

type="text/css"是指定MIME类型,其中:   
  text是指对象为网页中的文本   
  css或是javascript是指当前指定的文本类型...
如果要在HTML文件中应用CSS样式,最常用的有三种方法:

1.内部引用

所谓内部引用就是运用style标签引用在同HTML页内<HEAD></HEAD>部分的css定义。
2.外部引用

外部引用就是用<link>标签引用外部CSS文件中的样式。如欲实现上述效果,可将CSS做成单独文件。不过使用这种方法引用要确保CSS文件和HTML文件的相对路径完整无误,要不然HTML文档是不会找到CSS样式的。

3.内联引用

内联引用其实就是在应用CSS样式的HTML部分直接在所做用的标签上定义CSS样式,这种方法最直接,但是缺点也最明显,最大的问题就是代码繁冗,作用域也仅仅在定义的标签的作用范围
<form action="xxx.jsp" method="post" > <table width="500"> <style> body { display: grid; place-content: center; min-height: 100vh; margin: 20px; font-family: &#39;Microsoft YaHei&#39;, sans-serif; font-size: 16px; } table { border-spacing: 10px; } </style> <tr> <td><b style="font-size: 16px;">性别</b></td> <td> <input type="radio" id="man" name="sex"/> <label for="man"><img src="images/man.jpg"> 男 </label> <input type="radio" id="women" name="sex"/> <label for="women"><img src="images/women.jpg"> 女 </label> </td> </tr> <tr> <td><b>生日</b></td> <td> <select name="year"> <option selected="selected">--请选择年--</option> <option>1990</option> <option>2000</option> <option>2010</option> </select> <select name="month"> <option selected="selected">--请选择月--</option> <option>1</option> <option>2</option> <option>3</option> </select> <select name="day"> <option selected="selected">--请选择日--</option> <option>11</option> <option>12</option> <option>13</option> </select> </td> </tr> <tr> <td><b>所在地区</b></td> <td> <input type="text" value="安徽" name="area"> </td> </tr> <tr> <td><b>婚姻状况</b></td> <td> <input type="radio" name="marital_status" id="spinsterhood"> <label for="spinsterhood"> 未婚 </label> <input type="radio" name="marital_status" id="married"> <label for="married"> 已婚 </label> <input type="radio" name="marital_status" id="divorce"> <label for="divorce"> 离婚 </label> <input type="radio" name="marital_status" id="secret"> <label for="secret">保密</label> </td> </tr> <tr> <td><b>学历</b></td> <td><input type="text" name="edu_bg"></td> </tr> <tr> <td><b>喜欢的类型</b></td> <td> <input type="checkbox" name="like_type" id="wumei"> <label for="wumei"> 妩媚的 </label> <input type="checkbox" name="like_type" id="keai"> <label for="keai"> 可爱的 </label> <input type="checkbox" name="like_type" id="xiaoxianrou"> <label for="xiaoxianrou"> 小鲜肉 </label> <input type="checkbox" name="like_type" id="laolarou"> <label for="laolarou"> 老腊肉 </label> <input type="checkbox" name="like_type" id="douxihuan"> <label for="douxihuan"> 都喜欢 </label> </td> </tr> <tr> <td><b>自我介绍</b></td> <td> <textarea cols="30" rows="10" name="self_introduction"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align: center;"> <input type="submit" value=" 免费注册 "> </td> </tr> </table> </fieldset> </form>
最新发布
04-01
<?php $show_title="$MSG_LOGIN - $OJ_NAME"; ?> <?php include("template/$OJ_TEMPLATE/header.php");?> <div class="ui error message" id="error" hidden></div> <div class="ui middle aligned center aligned grid" style="height: 500px;" > <div class="row"> <div class="column" style="max-width: 450px"> <h2 class="ui image header"> <div class="content" style="margin-bottom: 10px; "> <?php echo $MSG_LOGIN ?> </div> </h2> <form class="ui large form" id="login" action="login.php" method="post" role="form" class="form-horizontal" onSubmit="return jsMd5();" > <div class="ui existing segment"> <div class="field"> <div class="ui left icon input"> <i class="user icon"></i> <input name="user_id" placeholder="<?php echo $MSG_USER_ID ?>" type="text" id="username"> </div> </div> <div class="field"> <div class="ui left icon input"> <i class="lock icon"></i> <input name="password" placeholder="<?php echo $MSG_PASSWORD ?>" type="password" id="password"> </div> </div> <?php if($OJ_VCODE){?> <div class="field"> <div class="ui left icon input"> <i class="lock icon"></i> <input name="vcode" placeholder="<?php echo $MSG_VCODE ?>" type="text" autocomplete=off > <img id="vcode-img" onclick="this.src=&#39;vcode.php?&#39;+Math.random()" height="30px"> </div> </div> <?php }?> <button name="submit" type="submit" class="ui fluid large submit button" ><?php echo $MSG_LOGIN ?></button> 1,1 Top </div> <?php }?> <button name="submit" type="submit" class="ui fluid large submit button" ><?php echo $MSG_LOGIN ?></button> </div> <div class="ui error message"></div> </form> <div class="ui message"> <?php if ($OJ_REGISTER){ ?> <a href="registerpage.php"><?php echo $MSG_REGISTER ?></a>            <?php } ?> </div> </div> </div> </div> <script src="<?php echo $OJ_CDN_URL?>include/md5-min.js"></script> <script> function jsMd5(){ if($("input[name=password]").val()=="") return false; $("input[name=password]").val(hex_md5($("input[name=password]").val())); return true; } </script> <?php if ($OJ_VCODE) { ?> <script> $(document).ready(function () { $("#vcode-img").attr("src", "vcode.php?" + Math.random()); }) </script> <?php } ?> <?php include("template/$OJ_TEMPLATE/footer.php");?>
03-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超翔之逸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值