【问题标题】:How do I get the CSS file to apply correctly to my PHP/HTML code?如何让 CSS 文件正确应用于我的 PHP/HTML 代码?
【发布时间】:2018-11-29 01:36:18
【问题描述】:

看起来像这样:

但它应该看起来像video at 26:05

有几件事我想问:

  • 如果我想将代码链接到数据库,代码是否仍然有效?
  • 如果我要更改一些 CSS,它会起作用吗?
  • 错误是在 CSS 中还是在 HTML 文件中?

它应该在页面的右侧。

/* 
html5doctor.com Reset Stylesheet
v1.6.1
Last Updated: 2010-09-17
Author: Richard Clark - http://richclarkdesign.com 
Twitter: @rich_clark
*/

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
    margin:0;
    padding:0;
    border:0;
    outline:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}

body {
    line-height:1;
}

article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section { 
    display:block;
}

nav ul {
    list-style:none;
}

blockquote, q {
    quotes:none;
}

blockquote:before, blockquote:after,
q:before, q:after {
    content:'';
    content:none;
}

a {
    margin:0;
    padding:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}

/* change colours to suit your needs */
ins {
    background-color:#ff9;
    color:#000;
    text-decoration:none;
}

/* change colours to suit your needs */
mark {
    background-color:#ff9;
    color:#000; 
    font-style:italic;
    font-weight:bold;
}

del {
    text-decoration: line-through;
}

abbr[title], dfn[title] {
    border-bottom:1px dotted;
    cursor:help;
}

table {
    border-collapse:collapse;
    border-spacing:0;
}

/* change border colour to suit your needs */
hr {
    display:block;
    height:1px;
    border:0;   
    border-top:1px solid #cccccc;
    margin:1em 0;
    padding:0;
}

input, select {
    vertical-align:middle;
}

/*classes*/

.main-wrapper {
    margin: 0 auto;
    width: 1000px;
}

a {
    text-decoration: none;
}

body {
    background-color: #ccc;
}

header nav {
    width: 100%;
    height: 60px;
    background-color: #fff;
}

header nav ul {
    float: left;
}

header nav ul li {
    float: left;
    list-style: none;
}

header nav ul li a {
    font-family: arial;
    font-size: 16px;
    color: #111;
    line-height: 63px;
}

header .nav-login {
    float: right;
}

header .nav-login form {
    float: left;
    padding-top: 15px;
}

header .nav-login form input {
    float: left;
    width: 140px;
    height: 30px;
    padding: 0px 10px;
    margin-right: 10px;
    border: none;
    background-color: #ccc;
    font-family: arial;
    font-size: 14px;
    color: #111;
    line-height: 30px;
}

header .nav-login form input button {
    float: left;
    width: 60px;
    height: 30px;
    margin-right: 10px;
    border: none;
    background-color: #f3f3f3;
    font-family: arial;
    font-size: 14px;
    color: #111;
    cursor: pointer;
}

header .nav-login form input button {
    background-color: #ccc; 
}

header .nav-login a {
    display: block;
    width: 60px;
    height: 60px;
    border: none;
    float: left;
    background-color: #fff;
    font-family: arial;
    font-size: 16px;
    color: #111;
    line-height: 63px;
    cursor: pointer;
}

.main-container {
    padding-top: 40px;  
}

.main-container h2 {
    font-family: arial;
    font-size: 16px;
    color: #111;
    line-height: 50px;
    text-align: center;
}

/*signup.php*/

.signup-form {
    width: 400px;
    margin: 0 auto;
    padding-top: 30px;
}

.signup-form input {
    width: 90%;
    height: 40px;
    padding: 0px 5%;
    margin-bottom:4px;
    border: none;
    background-color: #fff;
    font-family: arial;
    font-size: 16px;
    color: #111;
    line-height: 40px;
}

.signup-form button {
    display: block;
    margin: 0 auto;
    width: 30%;
    height: 40px;
    border: none;
    background-color: #222;
    font-family: arial;
    font-size: 16px;
    color: #111;
    cursor: pointer;
}

.signup-form button:hover {
    background-color: #111;
}
<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="reset.css"></link>
        <link rel="stylesheet" type="text/css" href="style.css"></link>
    </head>
    <body>
        <header>
            <nav>
                <div class="main-wrapper">
                    <ul>
                        <li><a href="index.php">Home</a></li>
                    </ul>
                    <div clalss="nav-login">
                        <form>
                            <input type="text" name="uid" placeholder="Username/e-mail">
                            <input type="password" name="pwd" placeholder="password">
                            <button type="submit" name="submit">Login</button>
                        </form>
                        <a href="singup.php">Sign up</a>
                    </div>
                </div>
            </nav>
        </header>
</body>
</html>

【问题讨论】:

  • 显示你的文件夹结构
  • 使用指向外部网站(youtube 等)的链接意味着,随着时间的推移,即使这个问题得到了正确且对您有用的答案,随着时间的推移,它也会变得毫无用处,因为外部链接将变得无效。请尝试为您的问题制作一个完整的小例子。
  • 看起来像一个 CSS 问题,我建议通过示例视频来捕捉缺失的样式。
  • 是您对网站客户端(包括 CSS)进行故障排除时最好的朋友
  • 好的,明天我将发布我的作品的完整版本

标签: javascript php html css


【解决方案1】:

好的,这里有一些修复:

  • 您在 html 中拼错了“class”(并且您不需要 &lt;/link&gt; 关闭);
  • 有些类是在css上声明的,但是在html中没有使用(html:&lt;form class="signup-form"&gt;/css:.signup-form);
  • 您忘记添加视频告诉您的一些 CSS 属性(浮动:左);

我做了一些调整,但你应该尝试修复其余的:

/* 
html5doctor.com Reset Stylesheet
v1.6.1
Last Updated: 2010-09-17
Author: Richard Clark - http://richclarkdesign.com 
Twitter: @rich_clark
*/

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
    margin:0;
    padding:0;
    border:0;
    outline:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}

body {
    line-height:1;
}

article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section { 
    display:block;
}

nav ul {
    list-style:none;
}

blockquote, q {
    quotes:none;
}

blockquote:before, blockquote:after,
q:before, q:after {
    content:'';
    content:none;
}

a {
    margin:0;
    padding:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}

/* change colours to suit your needs */
ins {
    background-color:#ff9;
    color:#000;
    text-decoration:none;
}

/* change colours to suit your needs */
mark {
    background-color:#ff9;
    color:#000; 
    font-style:italic;
    font-weight:bold;
}

del {
    text-decoration: line-through;
}

abbr[title], dfn[title] {
    border-bottom:1px dotted;
    cursor:help;
}

table {
    border-collapse:collapse;
    border-spacing:0;
}

/* change border colour to suit your needs */
hr {
    display:block;
    height:1px;
    border:0;   
    border-top:1px solid #cccccc;
    margin:1em 0;
    padding:0;
}

input, select {
    vertical-align:middle;
}

/*classes*/

.main-wrapper {
    margin: 0 auto;
    width: 1000px;
}

a {
    text-decoration: none;
}

body {
    background-color: #ccc;
}

header nav {
    width: 100%;
    height: 60px;
    background-color: #fff;
}

header nav ul {
    float: left;
}

header nav ul li {
    float: left;
    list-style: none;
}

header nav ul li a {
    font-family: arial;
    font-size: 16px;
    color: #111;
    line-height: 63px;
}

header .nav-login {
    float: right;
}

header .nav-login form {
    float: left;
    padding-top: 15px;
}

header .nav-login form input {
    float: left;
    width: 140px;
    height: 30px;
    padding: 0px 10px;
    margin-right: 10px;
    border: none;
    background-color: #ccc;
    font-family: arial;
    font-size: 14px;
    color: #111;
    line-height: 30px;
}

header .nav-login form input button {
    float: left;
    width: 60px;
    height: 30px;
    margin-right: 10px;
    border: none;
    background-color: #f3f3f3;
    font-family: arial;
    font-size: 14px;
    color: #111;
    cursor: pointer;
}

header .nav-login form input button {
    background-color: #ccc; 
}

header .nav-login a {
    display: block;
    width: 60px;
    height: 60px;
    border: none;
    float: left;
    background-color: #fff;
    font-family: arial;
    font-size: 16px;
    color: #111;
    line-height: 63px;
    cursor: pointer;
}

.main-container {
    padding-top: 40px;  
}

.main-container h2 {
    font-family: arial;
    font-size: 16px;
    color: #111;
    line-height: 50px;
    text-align: center;
}

/*signup.php*/

.signup-form {
    width: 600px;
    margin: 0 auto;
    padding-top: 30px;
}

.signup-form input {
    float: left;
    width: 90%;
    height: 40px;
    padding: 0px 5%;
    margin-bottom:4px;
    border: none;
    background-color: #fff;
    font-family: arial;
    font-size: 16px;
    color: #111;
    line-height: 40px;
}

.signup-form button {
    float:left;
    display: block;
    margin: 0 auto;
    width: 30%;
    height: 40px;
    border: none;
    background-color: #eee;
    font-family: arial;
    font-size: 16px;
    color: #111;
    cursor: pointer;
}

.signup-form button:hover {
    background-color: #111;
}
<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="reset.css">
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
        <header>
            <nav>
                <div class="main-wrapper">
                    <ul>
                        <li><a href="index.php">Home</a></li>
                    </ul>
                    <div class="nav-login">
                        <form class="signup-form">
                            <input type="text" name="uid" placeholder="Username/e-mail">
                            <input type="password" name="pwd" placeholder="password">
                            <button type="submit" name="submit">Login</button>
                        </form>
                        <a href="singup.php">Sign up</a>
                    </div>
                </div>
            </nav>
        </header>
</body>
</html>

说实话,我并没有完全理解你的问题,但我还是会尽力回答:

  1. 我没有看到与数据库链接的问题,因为您的代码中没有任何与数据库相关的内容...
  2. CSS 主要是视觉效果,因此如果您更改它,它不会改变代码的功能。
  3. 在这种情况下,错误出现在 CSS 和 HTML 中。

不管怎样,希望对你有帮助。

【讨论】:

  • 非常感谢你花了好几个小时试图找出 css 出了什么问题,并且非常关注它,以至于我什至没有意识到 html 中可能存在错误,我一直在代码学院学习如何编写 css 并认为我会尝试一下,我也确实查看了 html,但错误是如此基本,我跳过它而没有注意到,因为谁拼错了类。
【解决方案2】:

在我说什么之前,它是&lt;link rel="stylesheet" href="style.css"&gt; 而不是&lt;link rel="stylesheet" type="text/css" href="style.css"&gt;&lt;/link&gt;。你已经关闭了标签。这可能就是它不起作用的原因。无论如何,这是另一个解决方案。

我发现 this answer on stackoverflow 可以解决您的问题:

你必须用标签包围 CSS:

<?php include 'header.php'; ?>
<style>
<?php include 'CSS/main.css'; ?>
</style>

...PHP 包含以 .css 结尾也可以正常工作。通过这种方式,您甚至可以在 CSS 文件中使用 PHP。这对组织例如非常有帮助。颜色作为变量。

【讨论】:

    猜你喜欢
    • 2012-09-22
    • 2021-04-23
    • 1970-01-01
    • 2017-01-31
    • 1970-01-01
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    • 2011-09-13
    相关资源
    最近更新 更多