【问题标题】:Why isn't my padding working? (HTML & CSS) [closed]为什么我的填充不起作用? (HTML和CSS)[关闭]
【发布时间】:2016-02-08 11:29:46
【问题描述】:

在我的网站上,我创建了一个侧边栏。但是,我希望边栏中的内容和边栏的边框之间有 40px 的填充。我已经尝试过了,但由于某种原因,它没有用。怎么回事?

我的代码:

.sidebar {
  padding: "40px 40px 40px 40px";
}
<div id="sidebar">
    <form id="signUp" name="signUp">
        <p>
            <b>Hey!</b> Want to post comments and receive cool information about me? If You Do, Sign Up Now! :D<br>
            <br>
            Nickname: <input id="nickname" placeholder="Nickname" required="" type="text"><br>
            Email Address: <input id="email" maxlength="254" placeholder="Email Address" required="" type="text"><br>
            Password: <input id="password" placeholder="Password" required="" type="password"><br>
            <input onclick="confirmAccount" type="button" value="Submit">
        </p>
    </form>
</div>

【问题讨论】:

  • 使用#sidebar作为id
  • 仍然无法正常工作...感谢您的建议:D
  • #sidebar { padding: 40px 40px 40px 40px; },应该可以解决它

标签: html css cell padding cellpadding


【解决方案1】:

使用正确的选择器(# 而不是.)并删除引号,然后这应该可以工作。

#sidebar {
  padding: 40px 40px 40px 40px;
}
<div id="sidebar">
    <form id="signUp" name="signUp">
        <p>
            <b>Hey!</b> Want to post comments and receive cool information about me? If You Do, Sign Up Now! :D<br>
            <br>
            Nickname: <input id="nickname" placeholder="Nickname" required="" type="text"><br>
            Email Address: <input id="email" maxlength="254" placeholder="Email Address" required="" type="text"><br>
            Password: <input id="password" placeholder="Password" required="" type="password"><br>
            <input onclick="confirmAccount" type="button" value="Submit">
        </p>
    </form>
</div>

【讨论】:

    【解决方案2】:

    您已将 .sidebar 放入您的 css 样式中,这是与类 (.) 关联的标签。

    对于 ID(例如侧边栏),始终使用井号 (#) 在 CSS 中标识它们。在这种情况下,您需要在代码中放置 #sidebar 而不是 .sidebar。

    【讨论】:

      【解决方案3】:

      首先,您的 div 有一个 id,因此请使用 # 而不是 .。其次从填充值中删除引号 - 因为它们都是相同的,您可以只使用一个 40px 值。以下应该工作:

      #sidebar {
        padding: 40px;
      }
      

      【讨论】:

      • 还是不行...谢谢你的建议!
      【解决方案4】:

      删除你的`"...

      改用#sidebar { padding: 40px 40px 40px 40px; }

      或者您可以只使用#sidebar { padding: 40px; },因为您需要所有边距为 40px...

      【讨论】:

      • 对不起兄弟...仍然无法正常工作。感谢您的建议!
      猜你喜欢
      • 1970-01-01
      • 2012-08-30
      • 2021-12-20
      • 2013-06-11
      • 2015-12-16
      • 2013-09-07
      • 2021-12-01
      • 2016-08-09
      • 1970-01-01
      相关资源
      最近更新 更多