导轨,如何将导航菜单中的“主页”链接更改为徽标图像?

问题描述

我就像在在线课程中一样,完成了模仿应用程序的创建。我认为,通过使我的应用程序看起来更好,我可以再走一步。 我正在尝试将“主页”链接文本更改为图像。 当然,我之前是在HTML中完成的,而在Rails中则没有。由于“ link_to”方法,我有点困惑。如何进行操作,并给出当前的设置?

application.html.erb

<header>
      <div class="header-logo">
        <%= link_to("Home","/") %>
      </div>
           ...

routes.rb在哪里

get "/" => "home#top"

home.scss


* {
  box-sizing: border-box;
}

html {
  font: 100%/1.5 'Avenir Next','Hiragino Sans',sans-serif;
  line-height: 1.7;
  letter-spacing: 1px;
}

ul,li {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

a {
  text-decoration: none;
  color: #2d3133;
  font-size: 14px;
}

h1,h2,h3,h4,h5,h6,p {
  margin: 0;
}

input {
  background-color: transparent;
  outline-width: 0;
}

form input[type="submit"] {
  border: none;
  cursor: pointer;
}

/* Common Layout ================================ */
body {
  color: #2d3133;
  background-color: white;
  margin: 0;
  min-height: 1vh;
  background-image: url("/top.jpg");
}

.main {
  position: absolute;
  top: 64px;
  width: 100%;
  height: auto;
  min-height: 100%;
  background-color: #f5f8fa;
}

.container {
  max-width: 600px;
  margin: 60px auto;
  padding-left: 15px;
  padding-right: 15px;
  clear: both;
}

/* Header ================================ */
header {
  height: 64px;
  position: absolute;
  z-index: 1;
  width: 100%;
}

.header-logo {
  float: left;
  padding-left: 20px;
  color: black;
  font-size: 22px;
  line-height: 64px;
}

.header-logo a{
  color: black;
  font-size: 22px;
}

.header-menus {
  float: right;
  padding-right: 20px;
}

.header-menus li {
  float: left;
  line-height: 64px;
  font-size: 13px;
  color: black;
  padding-left: 15px;
}

.header-menus a {
  float: left;
  font-size: 13px;
  color: black;
  padding-right: 15px;
}

.header-menus .fa {
  padding-right: 5px;
}

.header-menus input[type="submit"] {
  padding: 0 20px;
  float: left;
  line-height: 64px;
  color: black;
  margin: 0;
  font-size: 13px;
}

/* Top ================================ */
.top-main {
  padding: 200px 0 100px;
  text-align: center;
  position: absolute;
  top: 0;
  width: 100%;
  height: auto;
  min-height: 100%;
  color: black;
  background-color: white;
  background-repeat: no-repeat;
  background-position: center 50%;
  background-size: cover;
  background-image: url("/top.jpg");
}

.top-message {
  position: relative;
}

.top-main h2 {
  font-size: 70px;
  font-weight: 500;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  margin-bottom: 20px;
}

.top-main p {
  font-size: 24px;
}

/* About ================================ */
.about-main {
  padding: 180px 8% 0;
  color: black;
}

.about-main h2 {
  font-size: 64px;
  font-weight: 500;
  line-height: 1.4;
}

.about-main p {
  font-weight: 200;
  font-size: 20px;
}

.about-img {
  width: 25%;
}

/* Form ================================ */
.form {
  max-width: 600px;
  margin: 0 auto;
  background-color: black;
  box-shadow: 0 2px 6px #c1ced7;
}

.form-heading {
  font-weight: 300;
  margin: 60px 0 20px;
  font-size: 48px;
  color: #bcc8d4;
}

.form-body {
  padding: 30px;
}

.form-error {
  color: #ff4d75;
}

.form input {
  width: 100%;
  border: 1px solid #ffffff;
  padding: 10px;
  color: #57575f;
  font-size: 16px;
  letter-spacing: 2px;
  border-radius: 2px;
}

.form textarea {
  width: 100%;
  min-height: 110px;
  font-size: 16px;
  letter-spacing: 2px;
}

.form input[type="submit"] {
  background-color: #ffffff;
  color: black;
  cursor: pointer;
  font-weight: 300;
  width: 120px;
  border-radius: 2px;
  margin-top: 8px;
  margin-bottom: 0;
  float: right;
}

.form-body:after {
  content: '';
  display: table;
  clear: both;
}

/* Flash ================================ */
.flash {
  padding: 10px 0;
  color: black;
  background: rgb(251,170,88);
  text-align: center;
  position: absolute;
  top: 64px;
  z-index: 10;
  width: 100%;
  border-radius: 0 0 2px 2px;
  font-size: 14px;
}

谢谢您的时间:)

解决方法

我想这就是你想要的

<%= link_to "#{image_tag("name-of-img-here.png")}".html_safe,root_path %>

请确保您的图片位于app/assets/images/文件夹中,以便正确链接。

您可能还需要添加一个类,然后为其设置样式,以使其看起来不错。

,

您可以尝试<%= link_to image_tag('image_here'),'/' %>

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...