gpt4 book ai didi

CSS margin 不响应 margin-top 但适用于其他 margin 属性

转载 作者:太空宇宙 更新时间:2023-11-04 03:24:28 28 4
gpt4 key购买 nike

CSS

.title{
margin-top: 200px; // does not work!
margin-left: 20px;
font-weight: bold;
color: $green;
font-size: 2.5em;
}

.title:hover{
background-color: transparent;
}

.title:visited{
color: $green;
}

rails/html.erb

<body>
.....

<%if current_page?(login_path) or request.path == "/signup"%>
<%= link_to "TITLE", "#", class: "title"%>
<%= yield %>
<% else %>
.....
</body>

我的标题 CSS 曾经可以工作,但现在不行了。无论如何,我的标题总是贴在屏幕的顶部。我已经尝试过 ma​​rgin-toppadding-top, 但它拒绝向下移动。但是,ma​​rgin-left 确实有效,所以我不太确定为什么边距的一个方面有效而另一个方面无效。

我在这里做错了什么?如果您认为问题没有列在上面的代码中,而是在我的 CSS 的其他地方,请告诉我,这样我就可以查看我的 css 的其他部分可能存在问题的地方!

以防万一下面是定义基本布局的部分

/* BASIC CONFIGURATION */
body {
color: #797979;
background: $background;
font-family: 'Lato', sans-serif;
padding: 0px !important;
margin: 0px !important;
font-size:13px;
}

table{
border-collapse: separate;
border-spacing: 10px 5px;
}

td{
margin-right: 10px;
}

#main-content{
font-family: 'Lato', sans-serif;
}

ul li {
list-style: none;
}

a, a:hover, a:focus {
text-decoration: none;
outline: none;
}

a:hover{
background-color: inherit;
}
::selection {

background: #68dff0;
color: #fff;
}
::-moz-selection {
background: #68dff0;
color: #fff;
}

#container {
width: 100%;
height: 100%;
}

最佳答案

你的问题就在这里:

body {
color: #797979;
background: $background;
font-family: 'Lato', sans-serif;
padding: 0px !important;
margin: 0px !important;
font-size:13px;
}

您已标记您希望所有边距和填充为 0 并使它们成为 !important。如果你想覆盖它,你必须让你的 .title 元素对边距很重要。

我建议尽可能避免使用 !important。通常您不需要它,除非您要覆盖提供的 CSS,该 CSS 用 !important 定义了一些字段。

关于CSS margin 不响应 margin-top 但适用于其他 margin 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27319341/

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