Spring Boot 轮播全屏 html,css,bootstrap

Posted

技术标签:

【中文标题】Spring Boot 轮播全屏 html,css,bootstrap【英文标题】:Spring boot carousel fullscreen html,css,bootstrap 【发布时间】:2018-10-27 01:23:38 【问题描述】:

我在使用 html 和 css 制作全屏轮播时遇到问题。当我启动我的 web 应用程序时,它只在浏览器中向我显示任何内容,例如它的空白 html 文件,只有顶部有 glyphicon。当我在浏览器中打开它而不启动 spring 时它工作正常。我猜我在应用程序属性或映射中遗漏了一些东西。

body 
    font-family: 'Roboto', sans-serif;



.carousel-fade .carousel-inner .item 
    -webkit-transition-property: opacity;
    transition-property: opacity;

.carousel-fade .carousel-inner .item,
.carousel-fade .carousel-inner .active.left,
.carousel-fade .carousel-inner .active.right 
    opacity: 0;

.carousel-fade .carousel-inner .active,
.carousel-fade .carousel-inner .next.left,
.carousel-fade .carousel-inner .prev.right 
    opacity: 1;

.carousel-fade .carousel-inner .next,
.carousel-fade .carousel-inner .prev,
.carousel-fade .carousel-inner .active.left,
.carousel-fade .carousel-inner .active.right 
    left: 0;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);

.carousel-fade .carousel-control 
    z-index: 2;



/* carousel fullscreen */

.carousel-fullscreen .carousel-inner .item 
    height: 100vh;
    min-height: 600px;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;



/* carousel fullscreen - vertically centered caption*/

.carousel-fullscreen .carousel-caption 
    top: 50%;
    bottom: auto;
    -webkit-transform: translate(0, -50%);
    -ms-transform: translate(0, -50%);
    transform: translate(0, -50%);


/* overlay for better readibility of the caption  */

.overlay 
    position: absolute;
    width: 100%;
    height: 100%;
    background: #000;
    opacity: 0.3;
    transition: all 0.2s ease-out;



/* typography */

h1,h2,h3,h4 
    font-weight: 700;


.super-heading 
    font-size: 70px;



.super-paragraph 
    font-size: 30px; font-weight: 300;


.carousel-caption .super-paragraph a,
.carousel-caption .super-paragraph a:hover

    color: #fff;


#carousel-example-generic 
    margin: 40px 0;


.demo-content padding-top: 50px; padding-bottom: 50px; 

html

<html>
<head>
    <title>Test</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,700' rel='stylesheet' type='text/css'>
    <link th:href="@/css/custom.css" rel='stylesheet' type='text/css'>
</head>
<body>

<!-- fullscreen -->

<div id="carousel-example-generic2" class="carousel slide carousel-fullscreen carousel-fade" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
        <li data-target="#carousel-example-generic2" data-slide-to="0" class="active"></li>
        <li data-target="#carousel-example-generic2" data-slide-to="1"></li>
        <li data-target="#carousel-example-generic2" data-slide-to="2"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
        <div class="item active" style="background-image: url('static/1.jpg');">
            <div class="overlay"></div>
            <div class="carousel-caption">
                <h1 class="super-heading"></h1>
                <p class="super-paragraph"></p>
            </div>
        </div>
        <div class="item" style="background-image: url('static/2.jpg');">
            <div class="overlay"></div>
            <div class="carousel-caption">
                <h1 class="super-heading"></h1>
                <p class="super-paragraph"></p>
            </div>
        </div>
        <div class="item" style="background-image: url('static/3.jpg');">
            <div class="overlay"></div>
            <div class="carousel-caption">
                <h1 class="super-heading"></h1>
                <p></p>
            </div>
        </div>
    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic2" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#carousel-example-generic2" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

控制器

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@org.springframework.stereotype.Controller
public class Controller 

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView index() 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("index");
        return modelAndView;
    

pom.xml

 <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.demo</groupId>
        <artifactId>ritagal</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>

        <name>Test</name>
        <description>Demo project for Spring Boot</description>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.0.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.21</version><!--$NO-MVN-MAN-VER$-->
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
</dependencies>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>


    </project>

【问题讨论】:

这个白屏是什么?没有css的html?什么是prj结构?这两个文件是否位于同一个文件夹中? (静态) 我在一个模板文件夹中有css和html,在静态文件夹中有图片。我尝试将图像放入模板文件夹,结果仍然保持不变 【参考方案1】:

通过以下文件结构设法完成这项工作

resources
│       ├── application.properties
│       ├── static
│       │   ├── css
│       │   │   └── custom.css
│       │   └── images
│       │       ├── 1.jpg
│       │       ├── 2.jpg
│       │       └── 3.jpg
│       └── templates
│           └── index.html 

将html中的引用改为

<link href='/css/custom.css' rel='stylesheet' type='text/css'>

<div class="item active" style="background-image: url('/images/1.jpg');">
...

application.properties 在我的情况下是空的

【讨论】:

还是同样的问题 @MaxShepard 请在您的帖子中提供与此路径相关的配置、控制器文件 完成了,我没有这个项目的配置类,只有控制器【参考方案2】:

我能够取得进展,根据 thymeleaf 样式 th:href="@/css/custom.css" 和 th:style="'background-image:url(' + @ /images/1.jpg + ');'"> 现在一切正常。谢谢大家帮助我!

【讨论】:

以上是关于Spring Boot 轮播全屏 html,css,bootstrap的主要内容,如果未能解决你的问题,请参考以下文章

Vue与swiper想结合封装全屏轮播插件

Swiper实现全屏视觉差轮播

div+css如何实现全屏放大键效果加自动播放语音效果?

实现全屏轮播,并且轮播div中的文字盒子一直自动垂直居中

jquery-自适应全屏背景轮播动画

css 如何让图片全屏的问题