html - CSS 在我的 RoR 应用程序中无法正常工作

标签 html css ruby-on-rails ruby svg

我正在按照 12 RoR 教程中的 Mackenzie Child 12 创建博客。

我完全按照教程学习,并严格按照他的代码进行操作。

我的问题是 css 样式表没有按预期工作。我的博客元素的问题是,无论我做什么,我都无法使用 CSS 代码调整 .svg Logo 的大小。我什至将他的代码完全复制并粘贴到我的同名文件中。

原始 Logo 大小约为 400x600 像素,我希望将其调整为 40x60 以适应侧边栏。

这是我正在使用的 CSS:

@import 'normalize';

html, body {
    font-family: 'Raleway', sans-serif;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 500;
}

a {
    text-decoration: none;
    color: inherit;
}

#sidebar {
    width: 250px;
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    background: #f5f7f9;
    padding: 7em 0 0 0;
    border-right: 1px solid #d6dce0;

    #logo {

        width: 50px;
        position: absolute;
        right: 3em;
        top: 3em;
    }
    ul {
        list-style: none;
        text-align: right;
        padding-right: 3em;
        .category {
            font-weight: 700;
            font-size: 0.7em;
            text-transform: uppercase;
            color: #33acb7;
        }
        li {
            padding: .5em 0;
            a {
                color: #9eafba;
                text-decoration: none;
                transition: all .4s ease;
                &:hover {
                    color: #33acb7;
                }
            }
        }
        .active {
            a {
                color: #33acb7;
            }
        }
    }
    .sign_in {
        position: absolute;
        right: 3em;
        top: 80%;
        font-size: .8em;
        color: #9eafba;
    }
}

这是我正在修改的 html.erb 代码:

<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
</head>
<body>
    <div id="sidebar">
        <div id="logo">
            <%= link_to root_path do %>
                <%= image_tag "logo.svg" %>
            <% end %>
        </div>

        <ul>
            <li class="category">Website</li>
            <li>Blog</li>
            <li>About</li>
        </ul>
    </div>

<%= yield %>

</body>
</html>

我这辈子都弄不明白。我正在使用 normalize 将浏览器预设归零。

我在使用 css 和 rails 时遇到的其他问题与 css 没有按应有的方式添加表格样式有关。我应用的一半样式根本不做任何事情,与填充、文本格式、颜色等有关。其他人是否遇到过 CSS 无法正常工作的问题?

好像我的 CSS 编译器在我的两台 mac 上都坏了。

我在 OS X 优胜美地终端的 rails 服务器上运行 ruby​​...如果它有所作为的话。

提前致谢。

知识库

最佳答案

尝试更改 #logo 选择器以包含 #logo img 并查看输出是否正确:

#logo img {
    width: 50px;
    position: absolute;
    right: 3em;
    top: 3em;
}

关于html - CSS 在我的 RoR 应用程序中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31444804/

相关文章:

php - 如何自动将一个div分成两部分

html - 单击时显示输入标题工具提示(不是悬停)

javascript - HTML Doctype 导致视频自动播放而不滚动到

html - 汉堡包切换不适用于移动设备

html - 如何将文本宽度与动态大小的图像/标题的宽度相匹配?

javascript - jQuery - animationComplete 持续时间

html - 当图像 float 到它们的左侧时,p 标签不会中断

ruby-on-rails - Rails STI Controller

ruby-on-rails - ruby mechanize 网站抓取总是只返回 javascript 数据

ruby-on-rails - 我应该如何以 DRY 和数据库有效的方式存储本地化值 - Ruby on Rails/i18n