如何更改Bootstrap容器的背景?

huangapple go评论66阅读模式
英文:

How do I change the background on a bootstrap container

问题

以下是代码部分的翻译:

[theme="bloodRed"] {
    background-color: #ff2424;
    color: #e571e1;
    accent-color: #00ff00;
}
<!DOCTYPE html>
<html lang="en" theme="bloodRed">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Sign up</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        <link href="/css/style.css" rel="stylesheet">
        <link rel="icon" href="https://getbootstrap.com/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png">
    </head>
    <body>
        <div class="container">
            <div class="login-box">
                <div class="row">
                    <div class="col-md-6">
                        <h2>Sign up</h2>
                        <form action="register" method="post">
                            <div class="form-group">
                                <label>First and Last name</label>
                                <input type="text" name="name" class="form-control" required>
                            </div>
                            <div class="form-group">
                                <label>Email</label>
                                <input type="email" name="email" class="form-control" required>
                            </div>
                            <div class="form-group">
                                <label>Password</label>
                                <input type="password" name="password" class="form-control" required>
                            </div>
                            <button type="submit" class="btn btn-outline-info" style="margin-top: 10px;"> Sign up </button>
                        </form>
                        <p style="margin-top: 15px;">Already have an account? &#160;&#160;<a class="btn btn-outline-success" href="login">Login here!</a></p>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
const express = require("express");
const app = express();
app.use(express.static("public"));
app.set("view engine", "ejs");

请注意,这只是对代码部分的翻译,没有包括问题的回答。

英文:

So I'm making a ejs login project, style.css:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

[theme=&quot;bloodRed&quot;] {
background-color: #ff2424;
color: #e571e1;
accent-color: #00ff00;
}

<!-- end snippet -->

register.ejs:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot; theme=&quot;bloodRed&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
&lt;title&gt;Sign up&lt;/title&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD&quot; crossorigin=&quot;anonymous&quot;&gt;
&lt;link href=&quot;/css/style.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;link rel=&quot;icon&quot; href=&quot;https://getbootstrap.com/docs/5.3/assets/img/favicons/favicon-32x32.png&quot; sizes=&quot;32x32&quot; type=&quot;image/png&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;login-box&quot;&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-md-6&quot;&gt;
&lt;h2&gt;Sign up&lt;/h2&gt;
&lt;form action=&quot;register&quot; method=&quot;post&quot;&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label&gt;First and Last name&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;form-control&quot; required&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label&gt;Email&lt;/label&gt;
&lt;input type=&quot;email&quot; name=&quot;email&quot; class=&quot;form-control&quot; required&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label&gt;Password&lt;/label&gt;
&lt;input type=&quot;password&quot; name=&quot;password&quot; class=&quot;form-control&quot; required&gt;
&lt;/div&gt;
&lt;button type=&quot;submit&quot; class=&quot;btn btn-outline-info&quot; style=&quot;margin-top: 10px;&quot;&gt; Sign up &lt;/button&gt;
&lt;/form&gt;
&lt;p style=&quot;margin-top: 15px;&quot;&gt;Already have an account? &#160;&#160;&lt;a class=&quot;btn btn-outline-success&quot; href=&quot;login&quot;&gt;Login here!&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

and then this js code connects them:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const express = require(&quot;express&quot;);
const app = express();
app.use(express.static(&quot;public&quot;));
app.set(&quot;view engine&quot;, &quot;ejs&quot;);

<!-- end snippet -->

but in register.ejs, the text doesnt change, neither does the background, if you go outside the div its red, help?

答案1

得分: 0

CSS遵循特异性和级联规则。您将theme属性添加到html元素中,但Bootstrap CSS(在重置中)会覆盖它,因为它在body上应用了白色的背景颜色和文本颜色#212529;

将您的theme属性添加到body标签会有所帮助,但还有许多其他地方会应用文本或背景颜色。最好使用Bootstrap SASS模块和/或自定义属性(CSS变量)。关于自定义的文档部分详细介绍了如何操作。

英文:

CSS follows rules of specificity and cascade. You're adding your theme property to the html element, but the Bootstrap CSS (in the reboot) is overriding it because it's applying a background-color of white on the body and a text color of #212529;.

Adding your theme property to the body tag, will help, but there are lots of other places that will apply text or background colors. It's better to use the Bootstrap SASS modules and/or custom properties (CSS variables). The documentation section on Customization details how.

huangapple
  • 本文由 发表于 2023年6月2日 06:25:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76386088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定