我有这个:
_layout:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - LolaBikeMen</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
@*<span class="icon-bar"></span>
<span class="icon-bar"></span>*@
<span class="icon-bar"></span>
</button>
@Html.ActionLink("LolaBikeMen", "Index", "Home", null, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<br />
<ul class="nav navbar-nav">
@*<li>@Html.ActionLink("Home", "Index", "Home")</li>*@
<li class="nav ">@Html.ActionLink("WHO", "About", "Home")</li>
<li class="nav ">@Html.ActionLink("WHAT", "Index", "Student")</li>
<li class="nav ">@Html.ActionLink("AGENDA", "Index", "Course")</li>
<li class="nav">@Html.ActionLink("PHILOSPY", "Index", "Instructor")</li>
<li class="nav">@Html.ActionLink("BUCKET-LIST", "Index", "Department")</li>
<li class="nav">@Html.ActionLink("LolaRiders", "Index", "LolaBiker")</li>
<li class="nav">@Html.ActionLink("bycicle", "Index", "Bycicle")</li>
@*<li class="nav"> @Html.Partial("_LoginPartial")</li>*@
</ul>
</div>
</div>
</div>
@*<li class="nav"><img src="~/Images/LolabikesCoffeeLogo3.jpg"> </li>*@
<div class="container">
@RenderBody()
@*<footer>
<p>© @DateTime.Now.Year - LolaBikeMen</p>
</footer>*@
</div>
@*<div class="fill">
</div>*@
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/Cyborg-bootstrap.min")
@RenderSection("scripts", required: false)
</body>
</html>
CSS:
/* Move down content because we have a fixed navbar that is 50px tall */
.container{
/*background-color:MenuText;*/
}
.container2{
width:100%;
height:100%;
}
body {
padding-top: 90px;
padding-bottom: 20px;
}
html {
background: url(~/Images/Large.JPG) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.wrapper {
background-image: url(../Images/Large.JPG);
background-repeat: no-repeat;
background-size: 100% 100%;
width: 100%;
height: 100%;
}
.wide {
width:100%;
height:1000px;
background-image:url('../Images/Large.JPG');
background-size:cover;
}
.wide img {
width:100%;
}
navbar{
color:white;
}
.table-striped>tr>td:nth-child(odd)>td,
.table-striped>tr>td:nth-child(odd)>td {
background-color:white;
}
.table.table-condensed tr th {
border-top: 1px solid white;
}
.table.table-condensed tr th {
border-bottom: 1px solid white;
}
.a:hover, a:focus {
color:floralwhite;
text-decoration: underline;
}
a {
color:floralwhite;
text-decoration: none;
}
.table.table-condensed tr td {
border-bottom: 1px solid white; /* Change the color you want to set */
}
.wrapper {
width: 100%;
background-color: lightcyan;
}
img {
background-image: url('../Images/Large.JPG');
background-repeat: no-repeat;
background-position:top;
background-size:cover;
width: 100%;
height: 100%;
}
/**/
#map {
height: 100%;
width: 100%;
}
#map img {
max-width: 100%;
}
html, body {
height: 100%;
width: 100%;
}
.fullscreen,
.content-a {
width:100%;
min-height:100%;
}
.background {
background-repeat:no-repeat;
/* custom background-position */
background-position:50% 50%;
/* ie8- graceful degradation */
background-position:50% 50%\9 !important;
}
.fill {
top: -30px;
left: 0;
right: 0;
bottom: 0;
position:relative;
/*overflow-x;*/
width:100%;
height:100%;
}
html,body{height:100%;}
.carousel,.item,.active{height:100%;}
.carousel-inner{height:100%;}
.fill{width:100%;height:100%;background-position:center;background-size:cover;}
.navbar {
margin-bottom: 0;
}
/* Demo */
#map { background:black; }
/**/
/* Wrapping element
/* Set some basic padding to keep content from hitting the edges */
.body-content {
padding-left: 15px;
padding-right: 15px;
}
/* Override the default bootstrap behavior where horizontal description lists
will truncate terms that are too long to fit in the left column
*/
.dl-horizontal dt {
white-space: normal;
}
/* Set widths on the form inputs since otherwise they're 100% wide */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="select"] {
max-width: 280px;
}
/* Responsive: Portrait tablets and up */
@media screen and (min-width: 768px) {
.jumbotron {
margin-top: 20px;
}
.body-content {
padding: 0;
}
}
和INdex.cshtml(主页):
@{
ViewBag.Title = "Home Page";
}
<div class="container2 fill">
<div id="map">
<img src="~/Images/VeryLarge.JPG" class="img-responsive" alt="Responsive image">
</div>
</div>
<!--1st Large Banner Image -->
@*<div class="wrapper">
<img src="~/Images/Large.JPG" class="img-responsive" alt="Responsive image">
<div class="col-sm-6">
@*<h1 id="text">Hello World!</h1>*@
@*<div class="jumbotron hidden-sm" >
<img src="~/Images/IMG_4954 - Copy.JPG">
</div>*@
<script type="text/javascript">
$('.carousel').carousel();
</script>
所以在主页上我有一个大图像。但它并没有填满孔宽。并且高度不会填满整个屏幕。我希望如果你让屏幕变小,那么图像就会被裁剪 - 这取决于屏幕的尺寸。在其他页面中,我不想使用整个宽度。所以我不能把它留在_Layout.cshtml上:
<div class="container">
@RenderBody()
@*<footer>
<p>© @DateTime.Now.Year - LolaBikeMen</p>
</footer>*@
</div>
谢谢
oke,我把它添加到了:site.css:
.background {
background: url(../Images/Large.JPG) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
但是Index.cshtml页面将如何显示呢?
像这样:<div class="background">
</div>
如果我将鼠标悬停在此行上:
-webkit-background-size: cover;
我收到此消息:
警告87验证(WE):&#34; -webkit-background-size&#34;不是有效的特定于供应商的属性,或者它可能已被弃用。 G:\ Mijn Documents \ My Web Sites \ Lolabikes \ C#\ ContosoUniversity \ Content \ full-width-pics.css 14 5 Lolabike
哦,我现在就这样:的site.css:
body {
background-image: url('../Images/Large.JPG');
background-repeat: no-repeat;
background-attachment: fixed;background-size: 100%;
/*padding-top: 90px;
padding-bottom: 20px;*/
}
和index.cshtml:
<div class="container fill">
<div id="map">
</div>
</div>
oke,但现在正在处理所有页面:(
不仅仅在主页上。大图片只能在主页上看到,而不能在其他页面上看到。
谢谢
如果我这样做:
/* Move down content because we have a fixed navbar that is 50px tall */
.container{
/*background-color:MenuText;*/
}
.container2{
width:100%;
height:100%;
}
body {
/*padding-top: 90px;
padding-bottom: 20px;*/
}
/*html {
background: url(~/Images/Large.JPG) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}*/
.wrapper {
background-image: url(../Images/Large.JPG);
background-repeat: no-repeat;
background-size: 100% 100%;
width: 100%;
height: 100%;
}
.wide {
width:100%;
height:1000px;
background-image:url('../Images/Large.JPG');
background-size:cover;
}
.wide img {
width:100%;
}
navbar{
color:white;
}
.table-striped>tr>td:nth-child(odd)>td,
.table-striped>tr>td:nth-child(odd)>td {
background-color:white;
}
.table.table-condensed tr th {
border-top: 1px solid white;
}
.table.table-condensed tr th {
border-bottom: 1px solid white;
}
.a:hover, a:focus {
color:floralwhite;
text-decoration: underline;
}
a {
color:floralwhite;
text-decoration: none;
}
.table.table-condensed tr td {
border-bottom: 1px solid white; /* Change the color you want to set */
}
.wrapper {
width: 100%;
background-color: lightcyan;
}
img {
background-image: url('../Images/Large.JPG');
background-repeat: no-repeat;
background-position:top;
background-size:cover;
width: 100%;
height: 100%;
}
/**/
#map {
height: 100%;
width: 100%;
}
#map img {
max-width: 100%;
}
html, body {
height: 100%;
width: 100%;
}
.fullscreen,
.content-a {
width:100%;
min-height:100%;
}
.background {
background-image: url('../Images/Large.JPG');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100%;
}
.fill {
top: -30px;
left: 0;
right: 0;
bottom: 0;
position:relative;
/*overflow-x;*/
width:100%;
height:100%;
}
html,body{height:100%;}
.carousel,.item,.active{height:100%;}
.carousel-inner{height:100%;}
.fill{width:100%;height:100%;background-position:center;background-size:cover;}
.navbar {
margin-bottom: 0;
}
/* Demo */
#map { background:black; }
/**/
/* Wrapping element
/* Set some basic padding to keep content from hitting the edges */
.body-content {
padding-left: 15px;
padding-right: 15px;
}
/* Override the default bootstrap behavior where horizontal description lists
will truncate terms that are too long to fit in the left column
*/
.dl-horizontal dt {
white-space: normal;
}
/* Set widths on the form inputs since otherwise they're 100% wide */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="select"] {
max-width: 280px;
}
/* Responsive: Portrait tablets and up */
@media screen and (min-width: 768px) {
.jumbotron {
margin-top: 20px;
}
.body-content {
padding: 0;
}
}
并在index.cshtml中:
<div class="background"></div>
我看着chrome(F12):
Remote Address:::1:41787
Request URL:http://localhost:41787/Images/Large.JPG
Request Method:GET
Status Code:200 OK (from cache)
但图像根本没有显示。
答案 0 :(得分:0)
使用此 -
background: url(../Images/Large.JPG) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
修改
这是另一种选择 -
body {
background-image: url(../Images/Large.JPG);
background-repeat: no-repeat;
background-attachment: fixed;background-size: 100%;
}