【问题标题】:Full width bootstrap carousel全宽引导轮播
【发布时间】:2016-03-03 07:37:52
【问题描述】:

我知道在这个网站上有很多关于 full width bootstrap carousel 的问题,但我很困惑怎么做?! ,我花了一整天的时间来做这件事,但我做不到...... 我给所有标签 marginpadding 0px 和 width 100% 但它不起作用:/

Site.css

body {
padding-top: 0px;
padding-bottom: 0px;
}

.body-content {
padding-left: 0px;
padding-right: 0px;
}
input,
select,
textarea {
max-width: 280px;
}

.field-validation-error {
color: #b94a48;
}

.field-validation-valid {
display: none;
}

input.input-validation-error {
border: 1px solid #b94a48;
}

input[type="checkbox"].input-validation-error {
border: 0 none;
}

.validation-summary-errors {
color: #b94a48;
}

.validation-summary-valid {
display: none;
}

Index.cshtml

@model NP1.ViewModels.HomeVM
@{
ViewBag.Title = "Home Page";
}
@section scripts{

}
@section styles{

}
<!-- start carousel -->

<div class="carousel slide" data-ride="carousel" data-interval="3000">
<div  class="carousel-inner">
    @foreach (var item in Model.Carousels)
    {

        if (item == Model.Carousels.FirstOrDefault())
        {
            <div  class="item active ">
                <img style="height:450px; width:100%;" class="img-responsive" src="@Url.Content(item.CarouselImage.ToString())">
                <div class="carousel-caption">
                    <h3>@item.CarouselSubject</h3>
                    <h4>@item.CarouselInfo</h4>
                </div>
            </div>
        }
        else
        {
            <div  class="item">
                <img style="height: 450px; width: 100%;" class="img-responsive" src="@Url.Content(item.CarouselImage.ToString())" />
                <div class="carousel-caption">
                    <h3>@item.CarouselSubject</h3>
                    <h4>@item.CarouselInfo</h4>
                </div>
            </div>
        }
    }
</div>

Layout.cshtml:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@RenderSection("styles", false)
</head>
<body class="container-fluid" style="width:100% !important;padding:0px;">
@*overflow-x:hidden;*@

<div class="container body-content">
@RenderBody()
<footer></footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", false)
</body>
</html>

【问题讨论】:

  • 要么只放置呈现的 HTML 和 CSS,要么使用 Razor / ASP.NET 对其进行标记。
  • 尝试将“container-fluid”类添加到您的 div 而不是正文中。默认情况下,body 始终是全宽的。
  • 我做了你的解决方案,但它还没有工作@Franco
  • 对不起,我不明白你的解决方案:/ @PraveenKumar
  • @shimaamini 矿山不是解决方案。

标签: html css twitter-bootstrap


【解决方案1】:

试试这个

<div id="theCarousel" class="carousel slide" data-ride="carousel">
                    <ol class="carousel-indicators">
                        <li data-target="#theCarousel" data-slide-to="0" class="active"></li>
                        <li data-target="#theCarousel" data-slide-to="1"></li>
                        <li data-target="#theCarousel" data-slide-to="2"></li>
                    </ol>

                    <div class="carousel-inner">
                        <div class="item active">
                        <div class="slide1"></div>
                            <div class="carousel-caption">
                                <h1>Amazing Background</h1>
                            </div>
                        </div>
                        <div class="item">
                        <div class="slide2"></div>
                            <div class="carousel-caption">

                            </div>
                        </div>
                        <div class="item">
                        <div class="slide3"></div>
                            <div class="carousel-caption">

                            </div>
                        </div>
                    </div>
                </div>    

【讨论】:

  • 谢谢,你所有的代码都可以正常工作,但是当我将它添加到我的项目中时,一切都是顺从的,它不起作用
  • 你会做jsfiddle吗?
  • 是的,但是,我不知道如何将 bootstrap.css 文件添加到 jsfiddle,因为我使用 bootstrap
  • 我不知道我是否正确,但我将我的代码复制到 jsfiddle 并添加 Bootstrap.css,我的代码工作正常! jsfiddle.net/21fd2hg4我不知道为什么在我的本地项目中它不起作用:(@RAP
【解决方案2】:

而不是给你的身体 container-fluid 的类,然后将你的旋转木马包装在一个容器中。你应该把它放在你的html中:

<html>
 <body>
  <div class="container-fluid" style="padding: 0;">
   <!-- put your carousel in here -->
  </div>
 </body>
</html>

从这个小提琴复制 html: http://jsfiddle.net/florianperrenet/shkt5wyh/

【讨论】:

  • 谢谢,当我做你的例子时它工作正常,但我不知道,为什么当我将它附加到我的项目中时它不起作用:(
  • 我已经编辑了我的答案,您可以在 Html 中尝试一些更改。告诉我!
【解决方案3】:

您还必须更改您的 css:

body {
padding-top: 0px;
padding-bottom: 0px;
width:100%;
height:100%
}

这段代码''必须在“容器”内的任何原因。

试试这个:

<div class="body-content">
   <div class="container-fluid">
      <!-- your carousel here-->
   </div>
</div>

【讨论】:

  • 谢谢,是的,我使用了 Bootstrap.css,我附加了这些代码,但它还不起作用:(
  • 感谢您的宝贵时间,但我的问题还没有解决
【解决方案4】:

我意识到这是几年后的事了,但供将来参考:在您的“_Layout.cshtml”视图中,您将看到:

<div class="container body-content">
     @RenderBody()
     <hr />
     <footer>
         <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
     </footer>
</div>

删除“容器”。那应该可以解决它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-12
    • 2013-10-29
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 2017-01-17
    相关资源
    最近更新 更多