这篇文章主要介绍css中怎么使用border属性与display属性,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
css中如何使用border属性与display属性
border属性介绍
border属性设置元素边框。
边框3个要素如:粗细、线型、颜色。
边框线型属性值说明表如:
属性指 |
描述 |
---|
none |
定义无边框。 |
hidden |
与 "none" 相同。不过应用于表时除外,对于表,hidden 用于解决边框冲突。 |
dotted |
定义点状边框。在大多数浏览器中呈现为实线。 |
dashed |
定义虚线。在大多数浏览器中呈现为实线。 |
solid |
定义实线。 |
double |
定义双线。双线的宽度等于 border-width 的值。 |
groove |
定义 3D 凹槽边框。其效果取决于 border-color 的值。 |
ridge |
定义 3D 垄状边框。其效果取决于 border-color 的值。 |
inset |
定义 3D inset 边框。其效果取决于 border-color 的值。 |
outset |
定义 3D outset 边框。其效果取决于 border-color 的值。 |
inherit |
规定应该从父元素继承边框样式。 |
边框方向属性值说明表如:
属性 |
描述 |
---|
border-top |
设置元素上边框。 |
border-bottom |
设置元素下边框。 |
border-left |
设置元素左边框。 |
border-right |
设置元素右边框。 |
边框实践
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>边框</title>
<style>
.box{
width: 200px;
height: 100px;
border: 1px solid red;
}
</style>
</head>
<body>
<div class="box">
微笑是最初的信仰
</div>
</body>
</html>
注意:边框颜色可以省略不写,默认为黑色。如果其他2个属性不写就不会显示边框。
设置元素边框方向实践
代码块
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>边框</title>
<style>
.box{
width: 200px;
height: 100px;
border-top: 2px double red;
border-bottom: 2px ridge lawngreen;
border-left: 2px inset darkorange ;
border-right:2px groove darkblue;
}
</style>
</head>
<body>
<div class="box">
微笑是最初的信仰
</div>
</body>
</html>
display属性介绍
属性值 |
描述 |
---|
inline |
将块级元素转换为行内元素。 |
block |
作用:1、将行内元素转换为块级元素。2、将隐藏的元素设置为显示状态。 |
none |
将显示的元素设置为隐藏状态。 |
display属性实践
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>将span标签转换为块级元素</title>
<style>
.box{
width: 200px;
height: 100px;
display: block;
background-color: red;
}
</style>
</head>
<body>
<span class="box">微笑是最初的信仰</span>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>将h2标签转换为行内元素</title>
<style>
.box{
width: 200px;
height: 100px;
display: inline;
background-color: red;
}
</style>
</head>
<body>
<h2 class="box">微笑是最初的信仰</h2>
</body>
</html>
注意:如果块级元素使用了display: inline;,就拥有了行内元素特点。
以上是“css中怎么使用border属性与display属性”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注天达云行业资讯频道!