12.16 CSS学习

12.16

CSS

1、行内样式。

可以直接把css代码写在现有的HTML标签元素的开始标签里面,并且css样式代码要写在style=" "双引号中才可以,

如:

<p style="color:red">这里文字是红色。</p>

2、内部样式。

如果想让HTML标签和css样式区分开来,可以采取将css样式代码写在<style type="text/css"> </style>标签之间。

这里的<style></style>可以写在<head></head>标签之间或者<body></body>标签之间。

<head>
<style type="text/css">  
    body {background-color: red}  
    p {margin-left: 20px}
</style>  
</head>

3、外部样式

将css单独放置于一个文件中,在jsp中通过link引入。

index.jsp

复制代码
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
  <link rel="stylesheet" type="text/css" href="style.css"/>   <!--引入css样式-->
</head>
<body>

<%
  Object message = request.getAttribute("message");
  if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
  alert("<%=request.getAttribute("message")%>");
</script>
<%  }  %>

<div id="login">
  <h1>Login</h1>
  <form action="Servlet?method=login" method="post" onsubmit="return check()">
    <input type="text" required="required"  placeholder="请输入账号" name="id"></input>
    <input type="password" required="required"  placeholder="请输入密码" name="password"></input>
    <button class="but" type="submit">登录</button>
  </form>
</div>
</body>
</html>
复制代码

style.css

复制代码
html{
     100%;
    height: 100%;
    overflow: hidden;
}
body{
     100%;
    height: 100%;
    font-family: 'Open Sans',sans-serif;
    margin: 0;
    background-color: #4A374A;
}
#login{
    position: absolute;
    top: 50%;
    left:50%;
    margin: -150px 0 0 -150px;
     300px;
    height: 300px;
}
#login h1{
    color: #fff;
    text-shadow:0 0 10px;
    letter-spacing: 1px;
    text-align: center;
}
h1{
    font-size: 2em;
    margin: 0.67em 0;
}
input{
     278px;
    height: 18px;
    margin-bottom: 10px;
    outline: none;
    padding: 10px;
    font-size: 13px;
    color: #fff;
    text-shadow:1px 1px 1px;
    border-top: 1px solid #312E3D;
    border-left: 1px solid #312E3D;
    border-right: 1px solid #312E3D;
    border-bottom: 1px solid #56536A;
    border-radius: 4px;
    background-color: #2D2D3F;
}
.but{
     300px;
    min-height: 20px;
    display: block;
    background-color: #4a77d4;
    border: 1px solid #3762bc;
    color: #fff;
    padding: 9px 14px;
    font-size: 15px;
    line-height: normal;
    border-radius: 5px;
    margin: 0;
}
复制代码

css文件位置与对应jsp文件位置一样即可

原文地址:https://www.cnblogs.com/wangdayang/p/13855191.html