HTML和CSS入门

 2023-09-06 阅读 21 评论 0

摘要:常用块标签 标题标签 <h1> <h2> 段落标签<p> 通用块容器标签 <div> 常用内连元素标签 超链接<a> 图片 <img> 换行<br> 常用字符实体 <: &lt; > :&gt; 空格 : &nbsp; HTML注释<!-- 注释 --> CSS载入方式 内

常用块标签

标题标签 <h1> <h2>

段落标签<p>

通用块容器标签 <div>

常用内连元素标签

超链接<a>

图片 <img>

换行<br>

常用字符实体

<: &lt;

> :&gt;

空格 : &nbsp;

HTML注释<!-- 注释 -->

CSS载入方式

内联式

嵌入式

外链式 <link rel="stylesheet" type="text/css" href="css/main.css">

css选择器

标签选择器

div{color: #1111;...
}

类选择器

.box{color: bule;.....
}

层级选择器,类和标签可以嵌套选择

css布局样式

  • border 设置元素四周的边框,如:border:1px solid black;设置元素四周边框是1像素宽的黑色实线

以上也可以拆分成四个边的写法,分别设置四个边的:

border-top,

border-left,

border-right,

border-bottom

  • padding 设置元素包含的内容和元素边框的距离,也叫内边距,如padding:20px;

    padding是同时设置4个边的,也可以像border一样拆分成分别设置四个边:

    padding-top、padding-left、padding-right、padding-bottom。

  • margin 设置元素和外界的距离,也叫外边距,如margin:20px;

    margin是同时设置4个边的,也可以像border一样拆分成分别设置四个边:

    margin-top、margin-left、margin-right、margin-bottom。

  • float 设置元素浮动,浮动可以让元素排列在一起,

    浮动分为左浮动:float:left;(常用)

    右浮动:float:right;

文本居中(重点)

  • 上下居中

line-height设置文字的行高,设置行高等于外框高度时文字自动上下居中

  • 水平居中

text-align 设置文字水平对齐方式,如text-align:center设置文字水平居中

css属性

布局常用样式属性:

  • width 设置元素(标签)的宽度,如:width:100px;
  • height 设置元素(标签)的高度,如:height:200px;
  • background 设置元素背景色或者背景图片,如:background:gold; 设置元素背景色为金色
  • border 设置元素四周的边框,如:border:1px solid black;设置元素四周边框是1像素宽的黑色实线

以上也可以拆分成四个边的写法,分别设置四个边的:

 border-top 设置顶边边框,如:border-top:10px solid red;border-left 设置左边边框,如:border-left:10px solid blue;
border-right 设置右边边框,如:border-right:10px solid green;
border-bottom 设置底边边框,如:border-bottom:10px solid pink;
  • padding 也可以像border一样拆分成分别设置四个边:padding-top、padding-left、padding-right、padding-bottom。
  • margin 也可以像border一样拆分成分别设置四个边:margin-top、margin-left、margin-right、margin-bottom。

文本常用样式属性一:

  • color 设置文字的颜色,如: color:red;
  • font-size 设置文字的大小,如:font-size:12px;
  • font-family 设置文字的字体,如:font-family:‘微软雅黑’;为了避免中文字不兼容,一般写成:font-family:‘Microsoft Yahei’;
  • font-weight 设置文字是否加粗,如:font-weight:bold; 设置加粗 font-weight:normal 设置不加粗
  • line-height 设置文字的行高,如:line-height:24px; 表示文字高度加上文字上下的间距是24px,也就是每一行占有的高度是24px
  • text-decoration 设置文字的下划线,如:text-decoration:none; 将文字下划线去掉
  • text-align 设置文字水平对齐方式,如text-align:center 设置文字水平居中
  • text-indent 设置文字首行缩进,如:text-indent:24px; 设置文字首行缩进24px

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/9918.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息