ASP.NET中我新增加样式文件为什么不起作用呀

ba_wang_mao 2020-05-11 09:00:12

ASP.NET小白一个,我想增加一个样式文件,让网页上的标签对齐,但是增加了样式文件后,发现不起作用,不知道错在哪里?



1、添加样式前网页运行效果图如下:


2、添加样式之前的Default.aspx 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PartyInvites.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>

</head>
<body>
<form id="form1" runat="server">
<div>
<h1>New Year's Eve at Jacqui's!</h1>
<p>We're going to have an exciting party. And you're invited!</p>
</div>
<div><label>Your name:</label><input type="text" id="name" /></div>
<div><label>Your email:</label><input type="text" id="email"/></div>
<div><label>Your phone:</label><input type="text" id="phone" /></div>
<div>
<label>Will you attend?</label>
<select id="Willattend">
<option value="">Choose an Option</option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</div>
<div>
<button type="submit">Submit RSVP</button>
</div>
</body>
</form>
</html>





3、添加如下样式文件 PartyStyles.css

body {

#form1 label{width:120px;display:inline-block;}
#form1 input{margin:2px;margin-left:4px;width:150px;}
#form1 select{margin:2px;width:154px;}
button[type=submit] {margin-top:5px;}
}



4、添加如下样式文件 PartyStyles.css后Default.aspx 代码修正如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PartyInvites.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link rel="stylesheet" type="text/css" href="PartyStyles.css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>New Year's Eve at Jacqui's!</h1>
<p>We're going to have an exciting party. And you're invited!</p>
</div>
<div><label>Your name:</label><input type="text" id="name" /></div>
<div><label>Your email:</label><input type="text" id="email"/></div>
<div><label>Your phone:</label><input type="text" id="phone" /></div>
<div>
<label>Will you attend?</label>
<select id="Willattend">
<option value="">Choose an Option</option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</div>
<div>
<button type="submit">Submit RSVP</button>
</div>
</body>
</form>
</html>



5、添加样式后网页运行效果图如下:

...全文
262 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
EdsionWang 2020-05-15
  • 打赏
  • 举报
回复
项目下的.css文件拖拽到.aspx的<head></head>标签内就引用成功了。
正怒月神 版主 2020-05-12
  • 打赏
  • 举报
回复
引用样式放在head里,标签是script。 标签选用样式是 class不是href。 自己定义的样式是 标签的style。 你好好看看样式的属性是什么。
  • 打赏
  • 举报
回复
啥拉出来,你自己没引用这样式,自然出不来,除非直接内嵌样式
泉低调前行 2020-05-12
  • 打赏
  • 举报
回复
原来自己解决了!vs里面有CSS要自己拉出来
ba_wang_mao 2020-05-11
  • 打赏
  • 举报
回复
4、添加如下样式文件 PartyStyles.css后Default.aspx 代码修正如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PartyInvites.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link rel="stylesheet" type="text/css" href="PartyStyles.css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>New Year's Eve at Jacqui's!</h1>
<p>We're going to have an exciting party. And you're invited!</p>
</div>
<div><label>Your name:</label><input type="text" id="name" /></div>
<div><label>Your email:</label><input type="text" id="email"/></div>
<div><label>Your phone:</label><input type="text" id="phone" /></div>
<div>
<label>Will you attend?</label>
<select id="Willattend">
<option value="">Choose an Option</option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</div>
<div>
<button type="submit">Submit RSVP</button>
</div>
</body>
</form>
</html>

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧