CSS样式写在JSP代码中的几种方法
1、行内样式。
可以直接把css代码写在现有的HTML标签元素的开始标签里面,并且css样式代码要写在style=" "双引号中才可以,
如:
这里文字是红色。
2、内部样式。
如果想让HTML标签和css样式区分开来,可以采取将css样式代码写在标签之间。
这里的可以写在
标签之间或者标签之间。body {background-color: red}
p {margin-left: 20px}
3、外部样式
将css单独放置于一个文件中,在jsp中通过link引入。
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
alert("<%=request.getAttribute("message")%>");
<% } %>
Login
style.css
html{
width: 100%;
height: 100%;
overflow: hidden;
}
body{
width: 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;
width: 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{
width: 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{
width: 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文件位置一样即可
idea新建css文件方法:https://jingyan.baidu.com/article/636f38bb4ad6fed6b9461061.html