search
HomeWeb Front-endCSS TutorialHow to set border style with css? Introduction to different styles of borders (code examples)

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>

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>

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>

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;

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>

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>

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
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
All About mailto: LinksAll About mailto: LinksApr 22, 2025 am 11:04 AM

You can make a garden variety anchor link () open up a new email. Let's take a little journey into this feature. It's pretty easy to use, but as with anything

It's pretty cool how Netlify CMS works with any flat file site generatorIt's pretty cool how Netlify CMS works with any flat file site generatorApr 22, 2025 am 11:03 AM

Little confession here: when I first saw Netlify CMS at a glance, I thought: cool, maybe I'll try that someday when I'm exploring CMSs for a new project. Then

Testing for Visual Regressions with PercyTesting for Visual Regressions with PercyApr 22, 2025 am 11:02 AM

It’s a Herculean task to test

Edge Goes Chromium: What Does it Mean for Front-End Developers?Edge Goes Chromium: What Does it Mean for Front-End Developers?Apr 22, 2025 am 10:58 AM

In December 2018, Microsoft announced that Edge would adopt Chromium, the open source project that powers Google Chrome. Many within the industry reacted with

A Gutenburg-Powered NewsletterA Gutenburg-Powered NewsletterApr 22, 2025 am 10:57 AM

I like Gutenberg, the new WordPress editor. I'm not oblivious to all the conversation around accessibility, UX, and readiness, but I know how hard it is to

Using  for Menus and Dialogs is an Interesting IdeaUsing for Menus and Dialogs is an Interesting IdeaApr 22, 2025 am 10:56 AM

Using for a menu may be an interesting idea, but perhaps not something to actually ship in production. See "More Details on "

Automated Visual Regression Testing With PlaywrightAutomated Visual Regression Testing With PlaywrightApr 22, 2025 am 10:54 AM

With visual regression testing, we can update a page, take screenshots before and after the fact, and compare the results for unintended changes. In this article, learn how to set up visual regression testing using Playwright.

CSS Houdini Could Change the Way We Write and Manage CSSCSS Houdini Could Change the Way We Write and Manage CSSApr 22, 2025 am 10:45 AM

CSS Houdini may be the most exciting development in CSS. Houdini is comprised of a number of separate APIs, each shipping to browsers separately, and some

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment