gpt4 book ai didi

ruby-on-rails - CSS 背景图片未显示在 Rails 站点上

转载 作者:行者123 更新时间:2023-11-28 08:59:54 25 4
gpt4 key购买 nike

我正在尝试将 background-image css 属性用于我使用 Ruby on Rails 构建的网站。

我已经尝试了几种不同的背景图像变体:url、背景:url、带引号和不带引号,以及几种图像路径。该图像当前位于 app/assets/images/upload.png。

background: url(upload.png);

自定义.css.scss

/* UNIVERSAL */

body {
background-color: black;
padding-top: 8px;
width: 800px;
margin-left: auto;
margin-right: auto;
font-family: arial, sans-serif;
font-size: 16px;
}

.content {
background-color: white;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-khtml-border-radius: 10px;
border-radius: 10px;
padding: 1px 15px;
}

h2 {
font-size: 18px;
}

p {
font-size: 16px;
}

ol {
font-size: 16px;
}


/* NAVIGATION */

ul {
padding: 0px;
}

#navtop {
float: right;
display: inline-block;
position: relative;
bottom: 47px;
right:4px;
letter-spacing:1px;
}

#topnavcontainer {
margin-bottom: -40px;

}

#navtop li, #navbottom li, #navbuttons li {
display: inline;
margin: 0px;
padding: 0px;
}

#navbuttons {
word-spacing: 25px;
position: relative;
left: 400px;
bottom: 60px;
display: inline-block;
}

#navbottom {
text-align: center;
word-spacing:90px;
letter-spacing:1px;
margin-top:25px;
}

#navtop a:link, #navbottom a:link, #navtop a:visited, #navbottom a:visited {
text-decoration: none;
font-size: 12px;
color: #999999;
}

#navtop a:hover, #navbottom a:hover {
color: white;
}

#uploadbutton a:link, #uploadbutton a:visited, #viewbutton a:link, #viewbutton a:visited {
text-decoration: none;
border-style:solid;
border-width:3px;
border-color:#666666;
padding: 5px;
color: white;
font-size: 14px;
font-weight: bold;
letter-spacing:2px;
}

#uploadbutton a:hover {
color: #FF0000;
}

#viewbutton a:hover {
color: #0066FF;
}

/*style the main menu*/
.myMenu {
margin:0;
padding:0;
text-align: left;
}

.myMenu li {
list-style:none;
float:left;


}

.myMenu li a:link, .myMenu li a:visited {
display:block;
text-decoration:none;

padding: 0.5em 1em;
margin:0;


}

.myMenu li a:hover {
background-color:black;
}

/*style the sub menu*/
.myMenu li ul {
position:absolute;
visibility:hidden;
margin:0;
padding:0;
}

.myMenu li ul li {
display:inline;
float:none;
}

.myMenu li ul li a:link, .myMenu li ul li a:visited {
background-color:black;
width:55px;
}

.myMenu li ul li a:hover {
background-color:#999999;
}

/* HOME PAGE */

#homepage {
text-align: center;
}

#homeheadline {
color: white;
background-color: #333333;
font-weight:normal;
border-style:solid;
border-width:6px;
border-color:#333333;
letter-spacing:1px;
margin-bottom: 45px;
}

a#clickhere , a#clickhere:visited {
text-decoration: none;
color: #0066FF;
}

#videotitle {
color: #FF0000;
position: absolute;;
bottom: 70px;
display: inline;
font-size: 19px;
left: 60px;
}

#videolist {
position: absolute;
left: 40px;
display: inline-block;
}

#audiencetitle {
color: #0066FF;
position: absolute;
bottom: 70px;
left: 340px;
display: inline;
font-size: 19px;
}

#audiencelist {
position: absolute;
display: inline-block;
left: 320px;
}

a.greenbutton, a.greenbutton:visited, {
font-size: 14px;
color: white;
font-weight: bold;
text-decoration: none;
background-color: #009900;
border-style:solid;
border-width:7px;
border-color:#009900;
letter-spacing:1px;
}

#homead {
margin-bottom: 25px;
margin-top: 45px;
display: block;
}

#lists {
width: 538px;
height: 100px;
position: relative;
margin-bottom: 35px;
margin-left: auto;
margin-right: auto;
text-align: left;
}

/* FORMS */

.greenbutton {
font-family: arial, sans-serif;
font-size: 14px;
color: white;
font-weight: bold;
text-decoration: none;
background-color: #009900;
border-style:solid;
border-width:3px;
border-color:#009900;
letter-spacing:1px;
margin-bottom: 40px;
}

.textinput {
border: 1px solid #bbb;
height: 18px;
width: 300px;
margin-bottom:30px;
}

.signform {
text-align: center;
width:300px;
margin-left: auto;
margin-right: auto;

}

.signformfields {
text-align: left;
}

#error_explanation {
color:#f00;
font-size: 16px;
ul { list-style: none;
margin: 0 0 18px 0;
}
}

.field_with_errors {
@extend .control-group;
@extend .error;
}

/* Upload Menu */

#uploadpage {
height: 580px;

}
.uploadnav ul {
list-style-type: none;
}

.uploadnav {
width: 200px;
text-align: center;
float:left;


}

.uploadbox {
background-color: black;
background-image: url( image_path ("upload.png"));
border-style:solid;
border-width:25px;
border-color: black;
margin-top: 20px;

}

.uploadgreybox {
background-color: #CCCCCC;
border-style:solid;
border-width:25px;
border-color: #CCCCCC;
margin-top: 20px;
}

.uploadtext {
color: white;
background-color: black;
padding: 5px;
}

.uploadgreytext {
color: #666666;
background-color: #CCCCCC;
padding: 5px;
}



.uploadpagecontent {

float:right;
}

最佳答案

最正确的做法:

background-image: url(<%= asset_path 'upload.png' %>)

有关详细信息,请参阅指南:http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets (第 2.2.1 节 CSS 和 ERB)

注意:如果您在 application.css 中执行此操作,则向其添加 .erb 扩展名以成为 application.css.erb

关于ruby-on-rails - CSS 背景图片未显示在 Rails 站点上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10539784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com