需要隐藏一个小部件的H2。

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

I need to hide a H2 of a widget

问题

我有一个博客,在博客中我使用了GetYourGuide的联盟链接。
特别是,我在这个页面上使用它:
https://www.visitare.net/best-tours-in-bologna/

我通过Elementor的HTML小部件插入了联盟小部件,但它带有一个非常恼人的H2标题:
需要隐藏一个小部件的H2。

我尝试用CSS删除它:

.title-banner {display:none;} 
.title-banner[data-v-48b40ecd] {display:none;} 

我还使用了!important,但没有起作用。

每次我使用这个联盟链接时,这个问题都会重复出现,我不明白为什么GetYourGuide要插入一个应该是根据博客个性化的标题。

英文:

I have a blog where I use the affiliate links of GetYourGuide.
In particular, I use it in this page:
https://www.visitare.net/best-tours-in-bologna/

I insert the affiliate widget through the HTML widget of Elementor, and it comes with a very annoying H2 header:
需要隐藏一个小部件的H2。

I tried to delete it with CSS:

.title-banner {display:none;} 
.title-banner[data-v-48b40ecd] {display:none;} 

and I also used !important, but nothing worked

This problem also repeats each time I use this affiliate links, I don't understand why GetYourGuide has to insert a headline that should be personal based on the blog.

答案1

得分: 1

以下是您要翻译的内容:

在您开始阅读之前,请阅读我的评论,位于原帖问题下。

经过一番思考并作为最后的手段,可以通过某种变通方法来实现。这只是一个想法,也许在特别是移动视图方面已经不再有意义了。您只需在那里进行一些实验。

那么这是关于什么的?这个想法是将<iframe>放在一个容器中,将<iframe>设置为position: absolute;并使用负值margin-top将其拉上一点。最后,我们还需要使用clip-path属性来进行遮罩。**注意:**这是您需要为每个<iframe>做的事情,例如博洛尼亚的热门景点最佳美食之旅等等。

为了更好地理解,这里有一个非常简要的示例。灰色区域实际上是容器。当然,它的height可以与<iframe>相同,仅用于演示目的更大。另一方面,红色区域代表<iframe>。最后,Lorem Ipsum占位文本只是代表任意的内容。在您的情况下,当然,这将是图片。

我认为将<iframe>放入一个容器,然后应用下面的CSS规则应该可以在Elementor中实现

<!-- 开始片段: js 隐藏: false 控制台: true Babel: false -->

<!-- 语言: lang-css -->

.iframe-container {
    width: 480px;
    height: 300px;
    background: #ccc;
}

.iframe-dummy {
    padding: 10px;
    width: 460px;
    background: red;
}

.iframe-dummy h2 {
    margin: 0;
    text-align: center;
    color: white;
}

.iframe-dummy p {
    text-align: justify;
    color: white;
}

/* 变通类(见HTML中的示例之后) */

.workaround {
    position: absolute;
    margin-top: -45px;
    clip-path: margin-box;
}

<!-- 语言: lang-html -->

<h2>之前:</h2>
<div class="iframe-container">
    <div class="iframe-dummy">
        <h2>恼人的标题</h2>
        <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
    </div>
</div>
<h2>之后:</h2>
<div class="iframe-container">
    <div class="iframe-dummy workaround">
        <h2>恼人的标题</h2>
        <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
    </div>
</div>

<!-- 结束片段 -->

编辑(参考原帖的评论):

你能直接为我的网站展示一个实际示例吗?

我再次查看了您的网站,发现已经存在一个合适的容器。除此之外,您也可以省略设置position: absolute;。我必须提到,由于没有自定义类名或ID,我不得不回到那里已有的东西。我稍后会回来。

/* 包含博洛尼亚热门景点等内容的列 */

body.page-id-7215 .elementor-element-a8f0323 .elementor-widget-container > div:first-child {
    margin-top: -60px;
    clip-path: margin-box;
}

/* 包含有用链接等内容的列 */

body.page-id-7215 .elementor-element-0ca608c .elementor-widget-container > div:first-child {
    margin-top: -115px;
    clip-path: margin-box;
}

目标解释:

  • body.page-id-7215 - 需要用于不影响其他子页面(唯一的页面ID)
  • .elementor-element-a8f0323 - 包含博洛尼亚热门景点等内容的左列的类名
  • .elementor-element-0ca608c - 包含有用链接等内容的右列的类名
  • .elementor-widget-container - 小部件容器
  • div:first-child - &lt;iframe&gt;的实际容器(我们需要的那个)

属性解释:

我已经在上面解释了这些属性(请参考上面)。

截图(通过DevTools应用的CSS):

https://i.imgur.com/tEusP11.jpg

结束语:

回到我已经提到的事情。使用.page-id-7215.elementor-element-a8f0323.elementor-element-0ca608c是不太理想的

英文:

Before you start reading here, please read my comments under the OP's question.

After some thought and as a last resort, it could be done with some sort of workaround. It's just an idea and maybe it will get to the point, especially when it comes to mobile views, where it doesn't make sense anymore. You'll just have to experiment around there.

So what's it all about? The idea is to put the &lt;iframe&gt; in a container, set <iframe> to position: absolute; and pull it up a bit with a negative value for margin-top. Finally, we also need the clip-path property to mask it. NOTE: This is what you need to do for each &lt;iframe&gt;, e.g. Top sights in Bologna, Best Food Tours, etc.

For a better understanding here is a very brief example. The gray area is virtually the container. Of course, it can have the same height as the &lt;iframe&gt; and is only larger for demonstration purposes. The red area, on the other hand, is supposed to represent the &lt;iframe&gt;. Finally, the Lorem Ipsum placeholder text simply represents any arbitrary content. In your case, of course, this would be the images.

I think putting the &lt;iframe&gt; into a container and then applying the CSS rules from below should be possible with Elementor.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.iframe-container {
    width: 480px;
    height: 300px;
    background: #ccc;
}

.iframe-dummy {
    padding: 10px;
    width: 460px;
    background: red;
}

.iframe-dummy h2 {
    margin: 0;
    text-align: center;
    color: white;
}

.iframe-dummy p {
    text-align: justify;
    color: white;
}

/* THE WORKAROUND CLASS (see AFTER example in HTML) */

.workaround {
    position: absolute;
    margin-top: -45px;
    clip-path: margin-box;
}

<!-- language: lang-html -->

&lt;h2&gt;Before:&lt;/h2&gt;
&lt;div class=&quot;iframe-container&quot;&gt;
    &lt;div class=&quot;iframe-dummy&quot;&gt;
        &lt;h2&gt;Annoying Title&lt;/h2&gt;
        &lt;p&gt;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;After:&lt;/h2&gt;
&lt;div class=&quot;iframe-container&quot;&gt;
    &lt;div class=&quot;iframe-dummy workaround&quot;&gt;
        &lt;h2&gt;Annoying Title&lt;/h2&gt;
        &lt;p&gt;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

EDIT (in reference to a comment by the OP):

> Can you show me a practical example directly for my website?

I took another look at your website and found that a suitable container already exists. Besides that, you can also omit setting position: absolute;. I have to mention that by not having custom class names or IDs, I had to fall back on what was there. I'll come back to that later.

First, here is the required CSS:

/* Column containing Top sights in Bologna, etc. */

body.page-id-7215 .elementor-element-a8f0323 .elementor-widget-container &gt; div:first-child {
	margin-top: -60px;
	clip-path: margin-box;
}

/* Column containing Useful Links, etc. */

body.page-id-7215 .elementor-element-0ca608c .elementor-widget-container &gt; div:first-child {
	margin-top: -115px;
	clip-path: margin-box;
}

Targeting explanation:

body.page-id-7215 - is needed to not take effect on other subpages as well (unique page id)

.elementor-element-a8f0323 - class name of left column containing Top sights in Bologna, etc.

.elementor-element-0ca608c - class name of right column containing Useful Links, etc.

.elementor-widget-container - the widget container

div:first-child - the actual container of the &lt;iframe&gt; (the one we need)

Properties explanation:
I have already explained the properties before (see above).

Screenshot (CSS applied via DevTools):
https://i.imgur.com/tEusP11.jpg

Closing words:
To come back to what I already mentioned. Using .page-id-7215, .elementor-element-a8f0323 and .elementor-element-0ca608c is suboptimal, since these names can change, e.g. with a new installation, etc.

答案2

得分: 0

当在浏览器中加载来自与网页不同域的iFrame时,会阻止JavaScript访问该iFrame,CSS也一样。您可能可以尝试调整您HTML中的内容安全策略(Content Security Policies) meta 标签,但我怀疑它会奏效。

然而,您可以使用类似Nodejs的服务器来实现。使用Node的 http 模块加载/获取所有这些小部件,然后使用 jsdom 获取您想要的部分,并将它们组装成最终的网页。

您可以定期或每小时运行该Node脚本,以将您定制的HTML(页面)保存在磁盘上并提供静态服务。

英文:

You can't do that in the browser. When an iFrame is loaded from a domain different that that of the webpage, JavaScript access to that iFrame is blocked. CSS too. You might be able to fiddle with the Content Security Policies meta tags on in your HTML but I doubt it.

You could however use a server like Nodejs and do it. Use Node's http module and load/fetch all these widgets then use jsdom to get the parts you want and assemble it all into your final webpage.

You could run that node script daily or hourly to save your customized HTML (page) on disk and serve it static.

huangapple
  • 本文由 发表于 2023年5月17日 17:37:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270646.html
匿名

发表评论

匿名网友

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

确定