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)

Sep 10, 2018 pm 02:22 PM
border property css

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

See all articles