将logo在CSS中调整大小以适应菜单,使用Thymeleaf。

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

Resize logo to menu in CSS with Thymeleaf

问题

我有这个CSS:

/* 全局CSS样式 */
body {
    background-color: #364f6b;
    margin: 0;
    padding: 0;
}

/* 样式化标志 */
.logo {
    width: 1px;
    height: auto;
}

index.html:

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
  
  
    <!-- 菜单 -->
    <link id="themeLink" th:href="@{/css/mystic-planets.css}" rel="stylesheet" />
    <meta name="format-detection" content="telephone=no">

</head>
<body>
<header>
    <img th:src="@{/images/137364472_padded_logo.png}" alt="mystic-planets" />
</header>
</body>
</html>

但是标志没有重新调整大小。

英文:

I have this css:

/* Global CSS styles */
body {
    background-color: #364f6b;
    margin: 0;
    padding: 0;
}

/* Styling the logo */
.logo {
    width: 1px;
    height: auto;
}

index.html:

&lt;!DOCTYPE HTML&gt;
&lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
  
  
    &lt;!-- Menu --&gt;
    &lt;link id=&quot;themeLink&quot; th:href=&quot;@{/css/mystic-planets.css}&quot;  rel=&quot;stylesheet&quot; /&gt;
    &lt;meta name=&quot;format-detection&quot; content=&quot;telephone=no&quot;&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;header&gt;
    &lt;img th:src=&quot;@{/images/137364472_padded_logo.png}&quot;  alt=&quot;mystic-planets&quot; /&gt;
&lt;/header&gt;
&lt;/body&gt;
&lt;/html&gt;

but the logo does not resize

答案1

得分: 2

你当前的CSS规则只针对具有logo类的元素,但是在你的HTML中,img标签没有这个类。

如果你想将CSS规则应用于你的标志,你应该像这样将logo类添加到img标签中:

<img class="logo" th:src="@{/images/137364472_padded_logo.png}"  alt="mystic-planets" />

然后,你的CSS规则应该起作用。然而,使用width: 1px;,你的标志可能会显得非常小,所以你可能需要调整width属性到你想要的大小。

.logo {
    width: 100px;  /* 根据你的喜好调整 */
    height: auto;
}
英文:

Your current CSS rule for the .logo class only targets elements that have the logo class, but in your HTML, the img tag does not have that class.

If you want to apply the CSS rule to your logo, you should add the logo class to the img tag like this:

&lt;img class=&quot;logo&quot; th:src=&quot;@{/images/137364472_padded_logo.png}&quot;  alt=&quot;mystic-planets&quot; /&gt;

Then, your CSS rule should work. However, with width: 1px;, your logo might appear extremely small, so you might want to adjust the width property to your desired size.

.logo {
    width: 100px;  /* Adjust to your preferred size */
    height: auto;
}

huangapple
  • 本文由 发表于 2023年7月24日 18:56:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753787.html
匿名

发表评论

匿名网友

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

确定