移动广告容器溢出到自家广告中 - RTL/LTR 布局不匹配
您好
我正在使用 Horizon 主题和官方的 House Ads 插件,并且我创建了一个自定义组件来使用与 Discourse 设计系统兼容的 CSS 变量和布局规则来设置广告样式。
问题:广告容器在移动设备上溢出视口(LTR 和 RTL 均如此)
- 主题: Horizon(在默认主题或其他主题如 Material 等中不可重现)
- 插件: House Ads + 自定义组件
- 设备: 移动设备
- 行为:
- 当 网站语言 = 英语 (LTR) 时 →
.ad-container的左边缘被裁剪(向左溢出)。 - 当 网站语言 = 波斯语/阿拉伯语 (RTL) 时 → 右边缘被裁剪(向右溢出)。
- 当 网站语言 = 英语 (LTR) 时 →
- 预期: 广告卡应完全包含在视口内,居中或与帖子内容宽度对齐。
我的 CSS 代码:
摘要
:root {
/* 核心颜色 */
--ad-bg: var(--secondary);
--ad-border: var(--highlight);
--ad-text: var(--primary);
/* 标签 */
--ad-label-bg: var(--highlight);
--ad-label-text: var(--danger);
}
.house-creative {
margin-left: 0 !important;
}
.house-creative a.between-posts-ad {
display: block;
text-decoration: none;
color: inherit;
background-color: transparent;
font-family: inherit;
}
/* ===============================
卡片容器
=============================== */
.house-creative .ad-container {
direction: rtl !important;
text-align: center !important;
margin-bottom: 20px;
padding: 10px 5px;
max-width: calc(#{$topic-avatar-width} + #{$topic-body-width} + (#{$topic-body-width-padding} * 2)); background-color: var(--ad-bg);
border: 2px solid var(--ad-border);
border-radius: 10px;
box-sizing: border-box;
line-height: 1.7;
color: var(--ad-text);
transition:
background-color 0.3s ease,
border-color 0.3s ease,
box-shadow 0.3s ease,
transform 0.2s ease;
}
.house-creative a.between-posts-ad:hover .ad-container {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.house-creative .ad-label {
display: inline-block;
text-align: center;
margin-bottom: 6px;
padding: 4px 12px;
font-size: 0.85em;
font-weight: 700;
text-transform: uppercase;
background-color: var(--ad-label-bg);
color: var(--ad-label-text);
border-radius: 999px;
}
.house-creative .ad-container .ad-text {
margin: 0;
font-size: 1rem;
line-height: 1.9;
color: var(--ad-text);
direction: rtl ;
text-align: center !important ;
unicode-bidi: isolate;
}
@media (max-width: 480px) {
.house-creative .ad-container {
direction: rtl !important;
text-align: center !important;
padding: 16px 12px;
width: 100%;
max-width: 100%;
}
}
