CSS和JavaScript

CSS

在html中引入CSS

我们需要先在该项目先建立css文件

html引入CSS,在<head></head>中添加<link>标签

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入外部的css -->
    <link rel="stylesheet" href="../css/demo1.css">
</head>
<body>
    <div>哈哈哈</div>
    <div>酷酷酷</div>
</body>
</html>

CSS选择器:选取设置样式的元素(标签)

分类:

1.元素选择器

元素名称(color:red) 如: div{color:red}

调用:<div>hello</div>

2.id选择器

#id属性值(color:red) 如:#name{color:red}

调用:<div id="name">hello</div>

3.类选择器

.class属性值(color:red) 如:.cls{color:red}

调用: <div class="cls">hello</div>

CSS的属性:

border属性

border-style的值

html 复制代码
 #mydiv1
{
    color: red;
    /* 设置字体大小为20px,注意,在css中如果需要加单位,单位不能省略 */
     font-size: 20px;
     border-width: 10px;
     border-style: dashed;
}

结果:

display属性

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入外部CSS文件 -->
    <link rel="stylesheet" type="text/css"  href="../css/demo2.css">
</head>
<body>
    <div>css1</div>
    <div id="mydiv1">css2</div>
    <div class="cla">css3</div>
    <div style="display: none;">css4</div>
    <div style="display: inline;">css5</div>
    <div style="display :inline">css6</div>
    <div style="display: block;">css7</div>
</body>
</html>

javaScript

javascript的引入方式

1.内部脚本:将JS代码定义在HTML页面中,使用<script>标签

2.外部脚本:将JS代码定义在JS文件中,然后引入到HTML页面中

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 在html页面内部引入js -->
    <script>
        //弹窗
        alert("你好呀")
    </script>

    <!-- 引入外部js文件 -->
    <script src="../js/demo1.js"></script>
    <!-- 注意在引入外部文件后,不能再文本中写js代码 -->
</body>
</html>

demo1.js文件

html 复制代码
alert("哈哈哈")

javascript的输出方式

使用window.alert();写入警告框

使用document.write();写入HTML页面

使用console.log();写入浏览器控制台

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        alert("哈哈")
        // 写入html页面
        document.write("赫赫")
        // 写入浏览器控制台
        // f12打开浏览器控制台
        console.log("你好")
    </script>
</body>
</html>
相关推荐
wxin_VXbishe12 分钟前
springboot合肥师范学院实习实训管理系统-计算机毕业设计源码31290
java·spring boot·python·spring·servlet·django·php
ITenderL18 分钟前
Python学习笔记-函数
python·学习笔记
Langchain20 分钟前
不可错过!CMU最新《生成式人工智能大模型》课程:从文本、图像到多模态大模型
人工智能·自然语言处理·langchain·大模型·llm·大语言模型·多模态大模型
zmjia11120 分钟前
全流程Python编程、机器学习与深度学习实践技术应用
python·深度学习·机器学习
龙的爹233331 分钟前
论文翻译 | Generated Knowledge Prompting for Commonsense Reasoning
人工智能·gpt·机器学习·语言模型·自然语言处理·nlp·prompt
龙的爹233332 分钟前
论文翻译 | Model-tuning Via Prompts Makes NLP Models Adversarially Robust
人工智能·gpt·语言模型·自然语言处理·nlp·prompt
方世恩1 小时前
【进阶OpenCV】 (5)--指纹验证
人工智能·opencv·目标检测·计算机视觉
_.Switch1 小时前
Python机器学习:自然语言处理、计算机视觉与强化学习
python·机器学习·计算机视觉·自然语言处理·架构·tensorflow·scikit-learn
JUNAI_Strive_ving1 小时前
番茄小说逆向爬取
javascript·python
彤银浦1 小时前
python学习记录7
python·学习