在HTML使用css做一个好看的边框
时间: 2023-11-25 10:26:12 浏览: 36
可以使用CSS中的border属性来为HTML元素添加边框。下面是一个简单的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<style>
.box {
border: 2px solid blue; /* 设置边框样式 */
padding: 20px; /* 设置内边距 */
margin: 20px; /* 设置外边距 */
}
</style>
</head>
<body>
<div class="box">
<p>这是一个带边框的盒子。</p>
</div>
</body>
</html>
```
在上面的代码中,我们创建了一个类名为"box"的div元素,并在CSS中为其设置了边框、内边距和外边距。你可以根据自己的需求调整这些属性的值,以实现更好看的边框效果。
相关问题
css html 在一个div外加一个边框
你可以使用CSS的border属性来给一个div加上边框,例如:
```html
<div class="container">
<!-- 内容 -->
</div>
```
```css
.container {
border: 1px solid black;
}
```
这样就会在包含内容的div外加上一个1像素宽的黑色边框。你可以根据需要调整边框的宽度、颜色和样式。
在HTML用css 做一个登录的页面
下面是一个简单的使用CSS样式美化的登录页面示例:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Page</title>
<style>
body {
background-color: #f5f5f5;
font-family: Arial, sans-serif;
font-size: 14px;
text-align: center;
}
form {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 5px #ccc;
display: inline-block;
margin-top: 50px;
padding: 20px;
text-align: left;
}
h1 {
font-size: 24px;
margin-bottom: 20px;
text-align: center;
}
input[type="text"], input[type="password"] {
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
display: block;
margin-bottom: 20px;
padding: 10px;
width: 100%;
}
input[type="submit"] {
background-color: #007bff;
border: none;
border-radius: 3px;
color: #fff;
cursor: pointer;
display: block;
font-size: 16px;
margin-top: 20px;
padding: 10px;
width: 100%;
}
input[type="submit"]:hover {
background-color: #0069d9;
}
</style>
</head>
<body>
<form action="" method="post">
<h1>Login Form</h1>
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password" required>
<input type="submit" value="Login">
</form>
</body>
</html>
```
在上面的代码中,我们使用了CSS样式美化了一个简单的登录页面。其中,我们设置了背景颜色、字体、边框、圆角、阴影、内外边距等样式属性,以及输入框和提交按钮的样式。你可以根据自己的需求对样式进行调整,以实现更好的美化效果。