【问题标题】:Css overriding nodejs express bootstrapCss覆盖nodejs express bootstrap
【发布时间】:2014-03-30 17:20:59
【问题描述】:

我已经使用 Java+Spring 开发了一个用于移动设备的 Web 应用程序,由于响应缓慢,我现在正尝试在 node.js 上实现相同的东西,表达。

我将 bootstrap.css 和 styles.css 用于我的站点特定样式和一些 bootstrap 覆盖。在我的旧实现中,一切都正常工作,但现在在 nodejs 上,引导程序中的所有样式都被正确应用到我的标记中,而来自 styles.css 的所有覆盖都被 chrome 忽略。知道我错过了什么。

这是我的问题的示例演示

来自 html 的一些标记

<div class="row">
        <ul id="tabs-menu" class="nav nav-tabs">
          <li class="active"><a href="#bollywood" rel="1">Bollywood</a></li>
          <li><a href="#western" rel="3">Western</a></li>
          <li><a href="#pakistani" rel="2">Pakistani</a></li>
          <li><a href="#islamic" rel="4">Islamic</a></li>
        </ul>
</div>

由 chrome 检查的 css 属性

    //from bootstrap
    .nav-tabs > li > a:hover {
        border-color: #eeeeee #eeeeee #dddddd;
    }

    //from bootstrap
    .nav > li > a:hover, .nav > li > a:focus {
        text-decoration: none;
        background-color: #eeeeee;
    }

    //from bootstrap
    .nav-tabs > li > a {
        margin-right: 2px;
        line-height: 1.428571429;
        border: 1px solid transparent;
        border-radius: 4px 4px 0 0;
    }

    //from bootstrap
    .nav > li > a {
        position: relative;
        display: block;
        padding: 10px 15px;
    }

    //from style.css
    .nav>li>a {
        color: #000;
        background: #ddd;
    }
    //from style.css
    .nav>li>a {
        padding: 3px 1px 3px 1px; //ignored
        margin-bottom: 1px;
        margin-right: 1px; //ignored
        border-radius: 0px; //ignored
        font-size: 13px;
    }

问题是 style.css 中最后带有 //ignored 注释的样式被 chrom 忽略,而在我之前的实现中,完全相同的代码可以完美运行。

这是我的 style.css

body {
    min-height: 500px;
    padding-top: 70px;
    padding-bottom: 70px;
    font-family: 'juice_light';
}

a
{
    color:#CA4242;
}

a:hover
{
    color:#B71B1B;
}

.navbar-default {
    background-color: #fff;
    border-color: #e7e7e7;
}

.navbar-header {
    width:100%;
}

.navbar
{
    min-height:65px;
}

#MyPlayQueue
{
    float: right;
    padding: 15px;
    font-size: 14px;
    line-height: 40px;
    height: 20px;
    color: #000;
    font-weight: bold;
}

#MyPlayQueue
{
    float: right;
    padding: 20px 5px 0px 0px;
    font-size: 14px;
    line-height: 30px;
    height: 20px;
    color: #000;
    font-weight: bold;
}

#MyPlayQueue:hover
{
    color:#CA4242;
}


.row
{
    padding-left: 4px;
    padding-right: 4px;
    padding-bottom:10px;
}

.nav>li>a {
    padding:3px 1px 3px 1px;
    margin-bottom: 1px;
    margin-right: 1px;
    border-radius: 0px;
    font-size: 13px;
}

.tab-content>.active {
    padding: 10px 0px;
}

.nav>li>a {
    color: #000;
    background:#ddd;
}

.nav-tabs {
    border-bottom: 5px solid #D71921;
}

.nav-tabs>li.active>a
{
    color: #fff;
    background:#d71921;
    cursor:pointer;
}
.nav-tabs>li.active>a:hover
{
    color: #fff;
    background:#D52737;
}

#sub-categories, #sub-menu
{
    clear:both;
    text-align: center;
    padding: 10px 0px 0px;
}

p {
    margin: 0 0 5px;
}

@font-face {
    font-family: 'juice_light';
    src: url('/fonts/juice_light-webfont.eot');
    src: url('/fonts/juice_light-webfont.eot?#iefix') format('embedded-opentype'),
        url('/fonts/juice_light-webfont.woff') format('woff'),
        url('/fonts/juice_light-webfont.ttf') format('truetype'),
        url('/fonts/juice_light-webfont.svg#juice_lightregular') format('svg');
    font-weight: normal;
    font-style: normal;

}

@font-face {
    font-family: 'juice_regular';
    src: url('/fonts/juice_regular-webfont.eot');
    src: url('/fonts/juice_regular-webfont.eot?#iefix') format('embedded-opentype'),
        url('/fonts/juice_regular-webfont.woff') format('woff'),
        url('/fonts/juice_regular-webfont.ttf') format('truetype'),
        url('/fonts/juice_regular-webfont.svg#juice_regularregular') format('svg');
    font-weight: normal;
    font-style: normal;

}

#content
{
    padding:0px 0px 70px;
}

#content .stub_holder
{
    display: block;
    width: 120px;
    height: 120px;
    background: -15px -10px url("../images/stub_image.png");
}

#content #albumStage
{
    vertical-align:bottom;
    display:block;
}

#content #albumStage .albumCover img
{
    border:5px solid #eee;
    width:100px;
}

#content #albumStage .info .albumCover
{
    float:left;
}

#content #albumStage .info .albumInfo
{
    padding-left:115px;
}

#content #albumStage .info .albumInfo .albumTitle
{
    font-size:20px;
}

#content #albumStage .info .albumInfo .albumCategory
{
    font-size:20px;
}
#content #albumStage .info .albumInfo .albumTracks
{
    font-size:14px;
}

#content #albumStage #albumControls
{
    clear:both;
    display:block;
    padding:10px 0px 10px 0px;
}

#content #albumStage #albumControls .albumControls
{
    background:#D71921;
    padding:5px;
    border:3px solid #ccc;
    color:#fff;
    margin:3px 6px 3px 0px;
    cursor:pointer;
}

#content ul#albums, #content ul#songs
{
    list-style-type:none;
    padding: 0px;
}

#content ul#songs
{
    padding-left:0px;
    width:100%;
}

#content ul#songs li.song, #content ul#songs li.song_end
{
    padding:20px 5px 40px 5px;
    border-top:1px solid #aaa;
    display:block;
    clear:both;
}

#content ul#songs li.song_end
{
    text-align: center;
}

#content ul#songs li.song.alternate
{
    background:#f2f2f2;
}

#content ul#songs li.song .streamControls img
{
    padding-right: 3px;
    width:25px;
}

#content ul#songs li.song .streamControls, #content ul#songs li.song .songDetail
{
    float:left;
    padding-right:5px;
}

#content ul#songs li.song .songDetail
{
    max-width: 210px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#content ul#songs li.song .queueControls
{
    padding-right: 5px;
    float: right;
}


#content ul#albums li.album
{
    float:left;
    padding:3px;
    height: 170px;
}

#content ul#albums li.album img
{
    border : 5px solid #ddd;
    width: 120px;
}

#content ul#albums li.album .albumTitle
{
    display:block;
    font-weight:bold;
    padding-top:2px;
    text-align:center;
    width:120px;
}

#content ul#albums li.album a
{
    color:#000;
}

#aEnd
{
    clear: both;
    text-align: center;
    border: 1px solid #ddd;
    padding: 10px;
}

.loader
{
    display:inline-block;
}

.load-progress {
    width: 150px;
    background-color: #aaa;
    height: 5px;
}

.play-progress {
    width: 0px;
    background-color: #333;
    height: 5px;
}

.row.footer
{
    opacity:0.9;
    position: fixed;
    bottom: 0px;
    padding:0px;
    padding-top:5px;
    margin:0px 0px 0px -15px;
    height:70px;
    width:100%;
    background:#000;
}

#playListSeekBar, #playListControls
{
    text-align:center;
}

#playListSeekBar, #playListControls img
{
    padding-left:10px;
    padding-right:10px;
}

#playListSeekBar, #playListControls img.control
{
    cursor:pointer;
}

#playListSeekBar .timers
{
    color:#aaa;
}

#playListSeekBar .timers#timeLeft
{

}

#playListSeekBar #controls_playList
{
    padding-bottom: 3px;
}

另外还有 layout.jade,如果它有助于理解我的问题

doctype html
html
  head
    title= title
    meta(http-equiv='X-UA-Compatible', content='IE=edge')
    meta(name='viewport', content='width=device-width', initial-scale='1.0')
    meta(name='author', content='Khushal Khan')
    meta(name='description', content='Mobilink Streaming Web App')
    link(rel='stylesheet', href='/stylesheets/style.css')
    link(rel='stylesheet', href='/stylesheets/bootstrap.css')
    link(rel='shortcut icon', href="/images/favicon.ico")

    //
      script(src='/javascripts/less-1.3.3.min.js')

    //if lt IE 9
      script(src='/javascripts/html5shiv.js')

    script(type='text/javascript', src='/javascripts/jquery.min.js')
    script(type='text/javascript', src='/javascripts/bootstrap.min.js')
    script(type='text/javascript', src='/javascripts/scripts.js')
  body
    block content

【问题讨论】:

  • 能否请您发布或链接您的 style.css?除此之外,您是否有其他浏览器或只有 chrome 的问题?
  • 所有浏览器,样式表都很长 bootstrap.css 可以从 bootstrap 站点在线获得。让我发布我的 style.css
  • 检查已编辑的问题

标签: node.js twitter-bootstrap express pug


【解决方案1】:

好的,我认出了几件事:

  • 首先:您给出的第一个示例不起作用可能是因为您的// comments。 CSS 中的// 不是标准的,所以一些浏览器会误解。
  • 第二:对我来说,除了这些// 问题之外,您的示例代码运行良好。
  • 第三:我相信你的问题来自于首先调用你个人的 style.css 并且被给定的 bootstrap.css 部分覆盖。

请尝试下面的代码,我在其中更改了链接的 css 文件的位置:

doctype html
html
  head
    title= title
    meta(http-equiv='X-UA-Compatible', content='IE=edge')
    meta(name='viewport', content='width=device-width', initial-scale='1.0')
    meta(name='author', content='Khushal Khan')
    meta(name='description', content='Mobilink Streaming Web App')
    link(rel='stylesheet', href='/stylesheets/bootstrap.css')
    link(rel='stylesheet', href='/stylesheets/style.css')
    link(rel='shortcut icon', href="/images/favicon.ico")

    //
      script(src='/javascripts/less-1.3.3.min.js')

    //if lt IE 9
      script(src='/javascripts/html5shiv.js')

    script(type='text/javascript', src='/javascripts/jquery.min.js')
    script(type='text/javascript', src='/javascripts/bootstrap.min.js')
    script(type='text/javascript', src='/javascripts/scripts.js')
  body
    block content

【讨论】:

  • 只需先调用链接 bootstrap.css 和 style.css 即可完美运行
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-08
  • 2016-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-09
相关资源
最近更新 更多