Skip to content

Commit 8795e2f

Browse files
authored
Update templates to use scoped CSS (#35658)
* Update templates to use scoped CSS * Move html and body styles to static CSS file
1 parent 9cf684d commit 8795e2f

File tree

8 files changed

+118
-99
lines changed

8 files changed

+118
-99
lines changed

src/ProjectTemplates/Shared/AspNetProcess.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ public async Task ContainsLinks(Page page)
139139
foreach (IHtmlLinkElement styleSheet in html.GetElementsByTagName("link"))
140140
{
141141
Assert.Equal("stylesheet", styleSheet.Relation);
142-
await AssertOk(styleSheet.Href.Replace("about://", string.Empty));
142+
// Workaround for https://github.com/dotnet/aspnetcore/issues/31030#issuecomment-811334450
143+
// Cleans up incorrectly generated filename for scoped CSS files
144+
var styleSheetHref = styleSheet.Href.Replace("_", string.Empty).Replace("about://", string.Empty);
145+
await AssertOk(styleSheetHref);
143146
}
144147
foreach (var script in html.Scripts)
145148
{

src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<title>@ViewData["Title"] - Company.WebApplication1</title>
77
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
88
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/Company.WebApplication1.styles.css" asp-append-version="true" />
910
</head>
1011
<body>
1112
<header>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
a {
11+
color: #0077cc;
12+
}
13+
14+
.btn-primary {
15+
color: #fff;
16+
background-color: #1b6ec2;
17+
border-color: #1861ac;
18+
}
19+
20+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21+
color: #fff;
22+
background-color: #1b6ec2;
23+
border-color: #1861ac;
24+
}
25+
26+
.border-top {
27+
border-top: 1px solid #e5e5e5;
28+
}
29+
.border-bottom {
30+
border-bottom: 1px solid #e5e5e5;
31+
}
32+
33+
.box-shadow {
34+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
35+
}
36+
37+
button.accept-policy {
38+
font-size: 1rem;
39+
line-height: inherit;
40+
}
41+
42+
.footer {
43+
position: absolute;
44+
bottom: 0;
45+
width: 100%;
46+
white-space: nowrap;
47+
line-height: 60px;
48+
}
Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,18 @@
1-
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2-
for details on configuring this project to bundle and minify static web assets. */
3-
4-
a.navbar-brand {
5-
white-space: normal;
6-
text-align: center;
7-
word-break: break-all;
8-
}
9-
10-
a {
11-
color: #0077cc;
12-
}
13-
14-
.btn-primary {
15-
color: #fff;
16-
background-color: #1b6ec2;
17-
border-color: #1861ac;
18-
}
19-
20-
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21-
color: #fff;
22-
background-color: #1b6ec2;
23-
border-color: #1861ac;
24-
}
25-
261
html {
272
font-size: 14px;
283
}
4+
295
@media (min-width: 768px) {
306
html {
317
font-size: 16px;
328
}
339
}
3410

35-
.border-top {
36-
border-top: 1px solid #e5e5e5;
37-
}
38-
.border-bottom {
39-
border-bottom: 1px solid #e5e5e5;
40-
}
41-
42-
.box-shadow {
43-
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
44-
}
45-
46-
button.accept-policy {
47-
font-size: 1rem;
48-
line-height: inherit;
49-
}
50-
5111
html {
5212
position: relative;
5313
min-height: 100%;
5414
}
5515

5616
body {
5717
margin-bottom: 60px;
58-
}
59-
.footer {
60-
position: absolute;
61-
bottom: 0;
62-
width: 100%;
63-
white-space: nowrap;
64-
line-height: 60px;
65-
}
18+
}

src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<title>@ViewData["Title"] - Company.WebApplication1</title>
77
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
88
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/Company.WebApplication1.styles.css" asp-append-version="true" />
910
</head>
1011
<body>
1112
<header>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
a {
11+
color: #0077cc;
12+
}
13+
14+
.btn-primary {
15+
color: #fff;
16+
background-color: #1b6ec2;
17+
border-color: #1861ac;
18+
}
19+
20+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21+
color: #fff;
22+
background-color: #1b6ec2;
23+
border-color: #1861ac;
24+
}
25+
26+
.border-top {
27+
border-top: 1px solid #e5e5e5;
28+
}
29+
.border-bottom {
30+
border-bottom: 1px solid #e5e5e5;
31+
}
32+
33+
.box-shadow {
34+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
35+
}
36+
37+
button.accept-policy {
38+
font-size: 1rem;
39+
line-height: inherit;
40+
}
41+
42+
.footer {
43+
position: absolute;
44+
bottom: 0;
45+
width: 100%;
46+
white-space: nowrap;
47+
line-height: 60px;
48+
}
Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,18 @@
1-
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2-
for details on configuring this project to bundle and minify static web assets. */
3-
4-
a.navbar-brand {
5-
white-space: normal;
6-
text-align: center;
7-
word-break: break-all;
8-
}
9-
10-
a {
11-
color: #0077cc;
12-
}
13-
14-
.btn-primary {
15-
color: #fff;
16-
background-color: #1b6ec2;
17-
border-color: #1861ac;
18-
}
19-
20-
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21-
color: #fff;
22-
background-color: #1b6ec2;
23-
border-color: #1861ac;
24-
}
25-
261
html {
272
font-size: 14px;
283
}
4+
295
@media (min-width: 768px) {
306
html {
317
font-size: 16px;
328
}
339
}
3410

35-
.border-top {
36-
border-top: 1px solid #e5e5e5;
37-
}
38-
.border-bottom {
39-
border-bottom: 1px solid #e5e5e5;
40-
}
41-
42-
.box-shadow {
43-
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
44-
}
45-
46-
button.accept-policy {
47-
font-size: 1rem;
48-
line-height: inherit;
49-
}
50-
5111
html {
5212
position: relative;
5313
min-height: 100%;
5414
}
5515

5616
body {
5717
margin-bottom: 60px;
58-
}
59-
.footer {
60-
position: absolute;
61-
bottom: 0;
62-
width: 100%;
63-
white-space: nowrap;
64-
line-height: 60px;
65-
}
18+
}

src/ProjectTemplates/test/template-baselines.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"Pages/_ViewImports.cshtml",
2323
"Pages/_ViewStart.cshtml",
2424
"Pages/Shared/_Layout.cshtml",
25+
"Pages/Shared/_Layout.cshtml.css",
2526
"Pages/Shared/_LoginPartial.cshtml",
2627
"Pages/Shared/_ValidationScriptsPartial.cshtml",
2728
"Properties/launchSettings.json",
@@ -104,6 +105,7 @@
104105
"Pages/_ViewImports.cshtml",
105106
"Pages/_ViewStart.cshtml",
106107
"Pages/Shared/_Layout.cshtml",
108+
"Pages/Shared/_Layout.cshtml.css",
107109
"Pages/Shared/_ValidationScriptsPartial.cshtml",
108110
"Properties/launchSettings.json",
109111
"wwwroot/favicon.ico",
@@ -185,6 +187,7 @@
185187
"Pages/_ViewImports.cshtml",
186188
"Pages/_ViewStart.cshtml",
187189
"Pages/Shared/_Layout.cshtml",
190+
"Pages/Shared/_Layout.cshtml.css",
188191
"Pages/Shared/_LoginPartial.cshtml",
189192
"Pages/Shared/_ValidationScriptsPartial.cshtml",
190193
"Properties/launchSettings.json",
@@ -267,6 +270,7 @@
267270
"Pages/_ViewImports.cshtml",
268271
"Pages/_ViewStart.cshtml",
269272
"Pages/Shared/_Layout.cshtml",
273+
"Pages/Shared/_Layout.cshtml.css",
270274
"Pages/Shared/_LoginPartial.cshtml",
271275
"Pages/Shared/_ValidationScriptsPartial.cshtml",
272276
"Properties/launchSettings.json",
@@ -349,6 +353,7 @@
349353
"Pages/_ViewImports.cshtml",
350354
"Pages/_ViewStart.cshtml",
351355
"Pages/Shared/_Layout.cshtml",
356+
"Pages/Shared/_Layout.cshtml.css",
352357
"Pages/Shared/_ValidationScriptsPartial.cshtml",
353358
"Properties/launchSettings.json",
354359
"wwwroot/favicon.ico",
@@ -430,6 +435,7 @@
430435
"Pages/_ViewImports.cshtml",
431436
"Pages/_ViewStart.cshtml",
432437
"Pages/Shared/_Layout.cshtml",
438+
"Pages/Shared/_Layout.cshtml.css",
433439
"Pages/Shared/_LoginPartial.cshtml",
434440
"Pages/Shared/_ValidationScriptsPartial.cshtml",
435441
"Properties/launchSettings.json",
@@ -611,6 +617,7 @@
611617
"Views/Home/Privacy.cshtml",
612618
"Views/Shared/Error.cshtml",
613619
"Views/Shared/_Layout.cshtml",
620+
"Views/Shared/_Layout.cshtml.css",
614621
"Views/Shared/_LoginPartial.cshtml",
615622
"Views/Shared/_ValidationScriptsPartial.cshtml",
616623
"wwwroot/favicon.ico",
@@ -692,6 +699,7 @@
692699
"Views/Home/Privacy.cshtml",
693700
"Views/Shared/Error.cshtml",
694701
"Views/Shared/_Layout.cshtml",
702+
"Views/Shared/_Layout.cshtml.css",
695703
"Views/Shared/_ValidationScriptsPartial.cshtml",
696704
"wwwroot/favicon.ico",
697705
"wwwroot/css/site.css",
@@ -772,6 +780,7 @@
772780
"Views/Home/Privacy.cshtml",
773781
"Views/Shared/Error.cshtml",
774782
"Views/Shared/_Layout.cshtml",
783+
"Views/Shared/_Layout.cshtml.css",
775784
"Views/Shared/_LoginPartial.cshtml",
776785
"Views/Shared/_ValidationScriptsPartial.cshtml",
777786
"wwwroot/favicon.ico",
@@ -853,6 +862,7 @@
853862
"Views/Home/Privacy.cshtml",
854863
"Views/Shared/Error.cshtml",
855864
"Views/Shared/_Layout.cshtml",
865+
"Views/Shared/_Layout.cshtml.css",
856866
"Views/Shared/_LoginPartial.cshtml",
857867
"Views/Shared/_ValidationScriptsPartial.cshtml",
858868
"wwwroot/favicon.ico",
@@ -934,6 +944,7 @@
934944
"Views/Home/Privacy.cshtml",
935945
"Views/Shared/Error.cshtml",
936946
"Views/Shared/_Layout.cshtml",
947+
"Views/Shared/_Layout.cshtml.css",
937948
"Views/Shared/_ValidationScriptsPartial.cshtml",
938949
"wwwroot/favicon.ico",
939950
"wwwroot/css/site.css",
@@ -1014,6 +1025,7 @@
10141025
"Views/Home/Privacy.cshtml",
10151026
"Views/Shared/Error.cshtml",
10161027
"Views/Shared/_Layout.cshtml",
1028+
"Views/Shared/_Layout.cshtml.css",
10171029
"Views/Shared/_LoginPartial.cshtml",
10181030
"Views/Shared/_ValidationScriptsPartial.cshtml",
10191031
"wwwroot/favicon.ico",

0 commit comments

Comments
 (0)