我正在使用CMDER创建我的网页,我正在尝试让我的CSS正常运行我的网页,但CSS的某些部分还没有工作。例如,我的#mainPicture不显示,我的内容框以及背景颜色也不起作用。这是我的css文件。
body {
margin: 0;
padding: 0;
text-align: left;
font-family:"Adobe Garamond Pro Bold", Georgia, "Times New Roman", Times, serif;
font-size: 13px;
color: #061C37;
background: #014D5D url_for('static', filename='images/background.png');
background-repeat:repeat-x;
}
*
{
margin: 0 auto 0 auto;
text-align:left;}
#page
{
display: block;
height:auto;
position: relative;
overflow: hidden;
width: 800px;
}
.topNaviagationLink
{
text-align:center;
position:relative;
margin-top:30px;
font-size:16px;
margin-left:-10px;
width:121px;
height: 35px;
line-height: 35px;
float:left;
color:#CEEAEE;
font-family:"Adobe Garamond Pro Bold", Georgia, "Times New Roman", Times, serif;
}
.topNaviagationLink a
{
text-decoration:none;
color:#CDE2FC;
}
.topNaviagationLink a:hover
{
text-align:center;
border-bottom:none;
color:#0C61C9;
display: block;
width:121px;
height: 35px;
line-height: 35px;
background-image:url_for('static', filename='images/tab.png');
}
#mainPicture
{
width:670px;
height:345px;
background-color:#FFFFFF;
}
#mainPicture
{
width:670px;
height:345px;
background-color:#FFFFFF;
}
#mainPicture .picture
{
position:relative;
width:650px;
height:325px;
top:10px;
background-image:url_for('static', filename='images/hudson1.jpg');
background-repeat:no-repeat;
margin-left:10px;
}
#headerTitle
{
position:relative;
top:30px;
left:40px;
font-size:25px;
color:#061C37;
font-family:"Adobe Garamond Pro Bold", Georgia, "Times New Roman", Times, serif;
}
#headerSubtext
{
position:relative;
top:30px;
left:50px;
font-size:14px;
color:#008CBA;
font-family:"Adobe Garamond Pro Bold", Georgia, "Times New Roman", Times, serif;
}
.contentBox
{
width:670px;
height:auto;
background-color:#FFFFFF;
margin-top:10px;
}
.contentBox .innerBox
{
position:relative;
width:650px;
height:auto;
top:10px;
margin-left:10px;
background-image:url(content_back.png)url_for('static', filename='images/content_back.png');
background-repeat:repeat-x;
padding-bottom:35px;
}
.contentTitle
{
font-size:19px;
margin-bottom:0px;
padding-top:18px;
margin-left:15px;
margin-top:15px;
}
.contentText
{
font-size:13px;
line-height:24px;
margin-left:13px;
margin-right:13px;
}
html, body {
text-align: center;
}
p {text-align: left;}
input[type=submit] {
background-color: white;
color: black;
border: 2px solid #008CBA;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
font-family:"Adobe Garamond Pro Bold", Georgia, "Times New Roman", Times, serif;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #061C37;
color: white;
}
我的应用
webapp.py
静态文件夹 - cssfolder --imagesfolder
模板文件夹 - index.html - newyork.html
这是newyork.html:
<!doctype html>
<head>
<title>New York</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/theme.css') }}">
</head>
<div class="innerBox">
<h2>New York</h2>
<div class="contentText"><p>
New York is a state in the northeastern United States, and is the 27th-most extensive, fourth-most populous, and seventh-most densely populated U.S. state. New York is bordered by New Jersey and Pennsylvania to the south and Connecticut, Massachusetts, and Vermont to the east. The state has a maritime border in the Atlantic Ocean with Rhode Island, east of Long Island, as well as an international border with the Canadian provinces of Quebec to the north and Ontario to the west and north.
</p>
<img src="{{ url_for('static', filename='images/newyork1.jpg') }}" alt="New York" style="width:750px;height:350px;">
<p>
The state of New York, with an estimated 19.8 million residents in 2015, is often referred to as New York State to distinguish it from New York City, the state's most populous city and its economic hub. With an estimated population of 8.55 million in 2015, New York City is the most populous city in the United States and the premier gateway for legal immigration to the United States. The New York City Metropolitan Area is one of the most populous urban agglomerations in the world. New York City is a global city, exerting a significant impact upon commerce, finance, media, art, fashion, research, technology, education, and entertainment, its fast pace defining the term New York minute.
</p></div>
</div>
这是我的index.html:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#newyorkbutton").click(function(){
$.get("/newyork", function(data, status){
$("#city").html(data);
});
});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A Blog ABout My Travels</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static', filename='css/theme.css') }}">
</head>
<body>
<div id="mainPicture">
<div class="picture">
<div id="headerTitle">Places I've Been</div>
<div id="headerSubtext">A Blog About My Travels</div>
</div>
</div>
<div id="page">
<input type="submit" name="NewYork" id="newyorkbutton" value="New York">
</div>
<div id="city" class="contentBox">
<div class="innerBox">
<h2>Welcome to My Travels</h2>
<div class="contentText"><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p><br />
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p></div>
</div>
</div>
</body>
</html>
它带来了newyork模板很好,但它并没有出现在内容框中。这些按钮也完美地显示了我在问题顶部提到的问题。
任何帮助都会很棒。
答案 0 :(得分:0)
我有同样的问题。 HTML文件中的CSS URL不是服务器URL数据库上的文件。如果您正在使用flask,请将此代码添加到flask.py
文件中。
@app.route('/css/<file>') # the route name, <file> is like a request.args
def css():
return render_template(file) # the file variable is created
# when a the <file> is something.
然后将CSS文件放在模板文件夹中,并将文件名放在HTML中,如<link rel="stylesheet" href="/file.css">
您可以对任何其他文件类型执行相同操作。