Home > Web Front-end > CSS Tutorial > How to set border style with css? Introduction to different styles of borders (code examples)

How to set border style with css? Introduction to different styles of borders (code examples)

青灯夜游
Release: 2018-09-10 14:22:29
Original
8924 people have browsed it

This chapter will show you how to set the border style in CSS? The introduction of different styles of borders (code examples) has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1: Basic style of border border line

The border style attribute specifies what kind of border to display

1. border-style property

none: Default no border
dotted: Define a dotted border
dashed: Define a dashed border
solid: Define solid border
Double: Define two borders. The width of the two borders is the same as the value of border-width
groove: Define the 3D groove border. The effect depends on the color value of the border
ridge: Define the 3D ridge border. The effect depends on the color value of the border
inset: Define a 3D inset border. The effect depends on the color value of the border
Outset: Define a 3D outset border. The effect depends on the color value of the border

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>border-style属性</title> 
<style>
	.demo{width: 500px;height: 500px;margin:50px auto;}
	p.none {border-style:none;}
	p.dotted {border-style:dotted;}
	p.dashed {border-style:dashed;}
	p.solid {border-style:solid;}
	p.double {border-style:double;}
	p.groove {border-style:groove;}
	p.ridge {border-style:ridge;}
	p.inset {border-style:inset;}
	p.outset {border-style:outset;}
	p.hidden {border-style:hidden;}
</style>
</head>

<body>
	<div class="demo">
		<p class="none">无边框。</p>
		<p class="dotted">虚线边框。</p>
		<p class="dashed">虚线边框。</p>
		<p class="solid">实线边框。</p>
		<p class="double">双边框。</p>
		<p class="groove"> 凹槽边框。</p>
		<p class="ridge">垄状边框。</p>
		<p class="inset">嵌入边框。</p>
		<p class="outset">外凸边框。</p>
		<p class="hidden">隐藏边框。</p>
	</div>
</body>
Copy after login

Effect picture:

How to set border style with css? Introduction to different styles of borders (code examples)

The above example is to set the upper, lower, left and right borders at the same time , you can also set the border on one side separately: border-top-style (top border), border-bottom-style (bottom border), border-left-style (left border), border-right-style (right border).

2.border-width attribute

Set the border width. There are two ways to specify the width of the border: you can specify the length value, such as 2px or 0.1em (units are px, pt, cm, em etc.), or use one of the 3 keywords: thick, medium (default), and thin.

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>border-width 属性</title>
		<style>
			.demo {
				width: 500px;
				height: 500px;
				margin: 50px auto;
			}
			
			.one {
				border-style: solid;
				border-width: 5px;
			}
			
			.two {
				border-style: solid;
				border-width: medium;
			}
			
			.three {
				border-style: solid;
				border-width: 1px;
			}
		</style>
	</head>

	<body>
		<div class="demo">
			<p class="one">一些文本。</p>
			<p class="two">一些文本。</p>
			<p class="three">一些文本。</p>
		</div>
	</body>
Copy after login

Rendering:

How to set border style with css? Introduction to different styles of borders (code examples)

Note: The "border-width" attribute has no effect if used alone. You must first set the border using the "border-style" attribute.

3.border-color property

Set the color of the border. Colors that can be set:
name - the name of the specified color, such as "red"
RGB - Specify RGB value, such as "rgb(255,0,0)"
Hex - Specify a hexadecimal value, such as "#ff0000"

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>border-color 属性</title>
		<style>
			.demo {
				width: 500px;
				height: 500px;
				margin: 50px auto;
			}
			
			.one {
				border-style:solid;
	            border-color:red;
			}
			
			.two {
				border-style: solid;
				border-color:rgb(80,189,114);
			}
			
			.three {
				border-style: solid;
				border-color: #0188FB;
			}
		</style>
	</head>

	<body>
		<div class="demo">
			<p class="one">颜色1</p>
			<p class="two">颜色2</p>
			<p class="three">颜色3</p>
		</div>
	</body>
Copy after login

Rendering:

How to set border style with css? Introduction to different styles of borders (code examples)

Note: If the "border-color" attribute is used alone Doesn't work. You need to set the border first using the "border-style" property.

4. Border - abbreviation attribute

The above are to set different attributes of the border separately, or you can set different attributes of the border at the same time, for example:

border:5px solid red;
Copy after login

2: Border rounded corners

border-radius: Set rounded corners on all four sides of the border at the same time
Border-top-left-radius: Set the upper left corner of the border to be rounded
Border-top-right-radius: Set the upper right corner of the border to be rounded
border-bottom-left-radlius: Set the lower left corner of the border to be rounded
border-bottom-right-radius: Set the rounded corner of the lower right corner of the border

As the name suggests, you can add a rounded corner effect to the border after setting the basic properties of the border

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>边框圆角 </title>
		<style>
			.demo {
				width: 800px;
				height: 500px;
				margin: 50px auto;
			}
			.demo *{
				width: 100px;
				height: 100px;
				margin: 20px 10px;
				border: 3px solid #21B4BB;
				float: left;
			}
			.demo1 {
	            border-radius:10px;
			}
			
			.demo2 {
				border-top-left-radius:10px;
			}
			
			.demo3 {
				border-top-right-radius:10px;
			}
			.demo4 {
				border-bottom-left-radius :10px;
			}
			.demo5 {
				border-bottom-right-radius:10px;
			}
		</style>
	</head>

	<body>
		<div class="demo">
			<div class="demo1">四边同时设置圆角</div>
			<div class="demo2">左上角设置圆角</div>
			<div class="demo3">右上角设置圆角</div>
			<div class="demo4">左下角设置圆角</div>
			<div class="demo5">右下角时设置圆角</div>
		</div>
	</body>
Copy after login

Rendering:

How to set border style with css? Introduction to different styles of borders (code examples)

3: Box-shadow

h-shadow: Horizontal Shadow distance
v-shadow: vertical shadow distance
blur: optional, blur distance
spread: optional, shadow size
color: optional, color
inset: optional value , change the current shadow to inner shadow

Grammar specification: box-shadow:h-shadow v-shadow blur spread color inset;
can also be abbreviated as: box-shadow:h-shadow v-shadow blur color;

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>边框阴影</title>
		<style>
			.demo {
				width: 200px;
				height: 200px;
				margin: 50px auto;
				border: 1px solid #2DC4CB;
				box-shadow:5px 5px #ccc;
			}
			
		</style>
	</head>

	<body>
		<div class="demo">
			hello
		</div>
	</body>
Copy after login

Rendering:

How to set border style with css? Introduction to different styles of borders (code examples)

Setting the border shadow effect can make the box (container) more three-dimensional and bring more Good visual effects.




The above is the detailed content of How to set border style with css? Introduction to different styles of borders (code examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template