html - 如何将 html 和 css 定位到特定页面?

标签 html css web containers squarespace

我正在使用 Squarespace 作为我的网站构建器。我在我的博客提要上方添加了一个搜索图标 https://www.livingwithphotography.co.uk/learn/但是出于某种原因,搜索框也会出现在每篇博文中。这是我不想要的,相反我只是希望它显示在此页面上 https://www.livingwithphotography.co.uk/learn/ .

为了编码搜索图标,我在站点标题中添加了这段代码

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>

然后我添加了这个CSS代码

.myTitle {
width: 100px;
padding: 10px;
border: 1px solid grey;
margin: 40px; 
font-size: 22px;
text-align: center;
margin-left: auto;
margin-right: auto;
}

最后我将这段代码添加到 PAGE HEADER CODE INJECTION

<div class="myTitle"><a href="/search?q=&f_collectionId=5568d109e4b0cb923356090b"><img src="https://livingwithphotography.squarespace.com/s/Screen-Shot-2015-06-01-at-120646.png" alt="search icon" style="width:20px">  <a href="/search?q=&f_collectionId=5568d109e4b0cb923356090b">Search</a></div>
<script>
  $(document).ready(function() {
  $(".myTitle").prependTo("#content");
});
</script>

我希望有办法,谢谢你的帮助:)

最佳答案

这有点 hacky,但应该可以。将代码包装在您在此 if 中添加 div 的位置。

$(document).ready(function() {
    if(window.location.pathname == "/learn") {
        $(".myTitle").prependTo("#content");
    }
});

关于html - 如何将 html 和 css 定位到特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30579542/

相关文章:

javascript - onFocus 不适用于 javascript 函数

javascript - Canvas 平移所有元素,包括小 map

html - 为什么向一行中的按钮添加 float-left 会导致它们之间的间距发生变化?

网页:系统会记录用户显示每个页面的时长

php - 无法选中 <div> 内的复选框,但在外部运行良好

html - 如何为内容设置仅可滚动的 div?

css - Box-shadow CSS 样式在 IE9 中不起作用?

css - 将 bootstrap 3 col 转换为 bootstrap 2

java - 我无法使用 spring 框架将 Hibernate Validator 集成到 javaweb 项目中

python - 使用flask根据python传递的数据更改html图像