モバイル広告コンテナがオーバーフローする問題(ハウス広告 – RTL/LTR レイアウトの不一致)
こんにちは
Horizon テーマと公式のハウス広告プラグインを使用しており、Discourse のデザインシステムと互換性のある CSS 変数とレイアウトルールを使用して広告をスタイリングするためのカスタムコンポーネントを作成しました。
問題: モバイルでビューポートからはみ出す広告コンテナ(LTR および RTL の両方)
- テーマ: Horizon(デフォルトや Material などの他のテーマでは再現されません)
- プラグイン: House Ads + カスタムコンポーネント
- デバイス: モバイル
- 動作:
- サイト言語 = 英語 (LTR) の場合 →
.ad-containerの左端が切り取られる(左にはみ出す)。 - サイト言語 = ペルシア語/アラビア語 (RTL) の場合 → 右端が切り取られる(右にはみ出す)。
- サイト言語 = 英語 (LTR) の場合 →
- 期待される動作: 広告カードはビューポート内に完全に収まり、投稿コンテンツの幅に対して中央揃えまたは揃えられていること。
私の CSS コード:
Summary
:root {
/* Core colors */
--ad-bg: var(--secondary);
--ad-border: var(--highlight);
--ad-text: var(--primary);
/* Label */
--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;
}
/* ===============================
Card Container
=============================== */
.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%;
}
}
