CSS/SCSS更改未在浏览器中生效

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

CSS/SCSS changes to code not applying in browser

问题

我正在尝试通过修改 scss/css 来隐藏一个数字。它是图片中的标签:poll-row__number。

奇怪的是,它在 scss 文件中并没有显示出来,但检查器显示另一个文件。

我正在在虚拟环境中运行 Adhocracy 安装(Nginx 在 Ubuntu Linux 上)。我已经将 css/scss 文件中的所有 poll-row__number 引用更改为 display:none / visibility:hidden。重启了服务器并清除了浏览器缓存,尝试了 Chrome、FireFox 和 Safari。但数字仍然可见。当我在检查器中更改它时,它消失了。

这是我的 css 目录和文件 CSS/SCSS更改未在浏览器中生效。poll-row__number 在 _poll.scss 中,就像这样 CSS/SCSS更改未在浏览器中生效。正如您所看到的,display:none/visibility:hidden 的值已经添加了进去。

当使用 grep 命令搜索 div 时,系统中没有找到任何内容。当使用 grep 命令搜索 pol-row__number 时,找到了它,但它找到的所有内容都已更改为 display:none/visibility:hidden。

我做错了什么,还需要什么信息来帮助我解决这个奇怪的问题。我已经尽我所能尝试了一切。

英文:

I am trying to hide a number by modifying the scss/css. It is the tag in the picture: poll-row__number.

CSS/SCSS更改未在浏览器中生效
Strange thing is also it is not in the scss file the inspector is showing but another.

I am running an Adhocracy installation (Nginx on Ubuntu Linux) in a virtual environment. I changed all the poll-row__number references in css/ scss files to display:none / visibility:hidden. Rebooted the server and deleted my cache from my browser, tried Chrome, FireFox and Safari. But the number stays visible. When I change it in the inspector, it dissapears.

This is my css directory with files CSS/SCSS更改未在浏览器中生效
The poll-row__number is in _poll.scss like here CSS/SCSS更改未在浏览器中生效
As you can see the value display:none/ visibility:hidden is added.

When grepping the div it finds nothing systemwide. When grepping the pol-row__number it finds it, but everything it finds is changed to display:none/ visibility:hidden.

What am I doing wrong and what else do you want for information to help me fix this strange ptoblem.

I tried all I can think of.

答案1

得分: 1

这里是翻译好的部分:

  • 尝试在控制台(Web浏览器)中添加 display: none;

  • 首先确保将 SCSS 转化为 CSS 文件:

sass --watch src/scss/_project_header.scss:src/css/_project_header.css

  • 其次,请验证 .poll-row__number 是否未在与你的 HTML 文件链接的另一个 CSS 文件中使用,因为我们可以看到当前的 displayinline-block

  • 然后,请检查是否多次使用了 .poll-row__number,因为基本的 CSS 规则是,最后声明的属性会覆盖其他属性,例如:

CSS

.poll-row__number {
  display: none;
}

.poll-row__number {
  display: inline-block;
}

在这里,.poll-row__number 将变为 inline-block。我刚刚注意到你的代码中存在这个问题(或者这是有意为之):

第1行:.poll-row__number(没有显示属性)
第2行:.poll-row__number, .poll-row__label(显示属性为 inline-block)

(这是我的意见,但使用“__”来命名ID或类可能看起来不太美观且容易混淆,请停止使用它:要么使用“CamelCase”,要么只使用一个下划线“_”)。

英文:

There's not much of code you're showing us. So it'll be hard to find the error.

  • Try to add display: none; in the console (web browser)

  • First make sure the scss is translated to the css file :

sass --watch src/scss/_project_header.scss:src/css/_project_header.css

  • Second, verify that the .poll-row__number is not used in another css file linked to you html file because as we can see the current display is inline-block.

  • Then, check if you don't use twice .poll-row__number because the basic css rule is the following, the last property stated is the one that overlaps the others, example :

CSS

.poll-row__number{
display :none;
}

.poll-row__number{
display :inline-block;
}

There, .poll-row__number will get inline-block. And I just saw that you have this issue in your code (or was it on purpose) :

Line 1 : .poll-row__number (has no display property)
Line 2 : .poll-row__number, .poll-row__label (has display inline-block)

(It is my opinion but using "__" for ids or class is ugly and confusing. Please stop it: either use "CamelCase" or just use one "_")

答案2

得分: 1

感谢所有的帮助。我找到了解决办法。对于许多开发者来说可能很明显,但对我来说并不是专业领域。

我的操作步骤:

  1. 我修改了我想要更改的CSS/SCSS文件。

  2. 然后我进入我的虚拟环境,执行了以下命令:

    npm install npm run build:prod
    pip install --upgrade -r requirements.txt
    export DJANGO_SETTINGS_MODULE=adhocracy-plus.config.settings.build
    python manage.py compilemessages
    python manage.py collectstatic
    

    我不确定是否所有这些步骤都是必需的,但我想也许CSS/SCSS被构建并存储在某个地方,然后被调用以覆盖项目文件夹中的CSS文件。之后,我重新启动了我的进程:

    sudo systemctl restart Adhocracy-plus
    sudo systemctl restart Adhocracy-plus.service
    sudo systemctl restart Adhocracy-plus-background-task
    sudo systemctl restart nginx
    

然后就可以正常工作了。

总结:

CSS/SCSS已经被编译。所以更改CSS/SCSS,重新编译/构建项目,然后重新启动服务。

英文:

Thanks for all the help. I found the solution. Maybe obvious for a lot of developers, but I am not a pro in this sence.

What I did:

I changed the css/scss files that I wanted to change.
Then I went to my virtual environment and did:

npm install npm run build:prod
pip install --upgrade -r requirements.txt
export DJANGO_SETTINGS_MODULE=adhocracy-plus.config.settings.build
python manage.py compilemessages
python manage.py collectstatic

I do not know if they all are needed, but I figured, maybe the css/scss is build and stored somewhere and then called so it overrides the css file in the projectfolder.
After this I restarted my processes:

sudo systemctl

restart Adhocracy-plus

sudo systemctl restart Adhocracy-plus.service

sudo systemctl restart Adhocracy-plus-background-task

sudo systemctl restart nginx

Then it worked.

In conclusion:

CSS/SCSS is compiled. So changed the CSS/SCSS, recompiled/ build the project ,restarted the services.

huangapple
  • 本文由 发表于 2023年2月16日 08:41:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466782.html
匿名

发表评论

匿名网友

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

确定