valsha
(KingPin)
4 Septiembre, 2021 15:30
1
De acuerdo con este post How to add customer HTML after "post_1"
y este ejemplo:
<script type="text/discourse-plugin" version="0.8">
api.decorateWidget("post:after", helper => {
const firstPost = helper.attrs.firstPost;
const h = helper.h;
if (firstPost) {
return h("div#custom-ad", [
h(
"a.custom-ad-link",
{ href: "example.com" },
h("img", { src: "https://picsum.photos/id/74/750/90" })
)
]);
}
});
</script>
Podemos establecer la imagen que necesitemos, pero ¿cómo centrar correctamente esta imagen y hacer que se escale para el diseño móvil?
porque ahora se muestra así
1 me gusta
Don
5 Septiembre, 2021 11:25
2
Hola,
Para hacer esto, debes usar algo de CSS.
En la vista Móvil y Escritorio (CSS) común, añade un ancho del 100% a la imagen.
#custom-ad {
.custom-ad-link {
img {
width: 100%;
}
}
}
En la vista Escritorio (CSS), añade un ancho máximo al ID #custom-ad para que el ancho del banner sea igual al del avatar del tema más el cuerpo del tema. Esto equivaldrá al ancho del 100% de la imagen que acabamos de añadir en la configuración común.
#custom-ad {
max-width: calc(45px + 690px + (11px * 2));
}
45px = Ancho del avatar del tema
690px + (11px * 2) = Ancho del cuerpo del tema más el relleno de 11px a la izquierda y 11px a la derecha utilizado en la clase .cooked.
Se verá así
Vista de escritorio (completa)
Vista de escritorio (responsiva)
Vista móvil
2 Me gusta
valsha
(KingPin)
5 Septiembre, 2021 17:20
3
¿Todo junto será algo así?
<script type="text/discourse-plugin" version="0.8">
api.decorateWidget("post:after", helper => {
const firstPost = helper.attrs.firstPost;
const h = helper.h;
if (firstPost) {
return h("div#custom-ad", [
h(
"a.custom-ad-link",
{ href: "example.com" },
h("img", { src: "https://picsum.photos/id/74/750/90" })
)
]);
}
});
</script>
#custom-ad {
.custom-ad-link {
img {
width: 100%;
}
}
}
#custom-ad {
max-width: calc(45px + 690px + (11px * 2));
}
Don
5 Septiembre, 2021 17:35
4
No, debes agregar esto a las secciones de CSS.
Así que todo quedará junto.
Común / Encabezado
<script type="text/discourse-plugin" version="0.8">
api.decorateWidget("post:after", helper => {
const firstPost = helper.attrs.firstPost;
const h = helper.h;
if (firstPost) {
return h("div#custom-ad", [
h(
"a.custom-ad-link",
{ href: "example.com" },
h("img", { src: "https://picsum.photos/id/74/750/90" })
)
]);
}
});
</script>
Común / CSS
#custom-ad {
.custom-ad-link {
img {
width: 100%;
}
}
}
Escritorio / CSS
#custom-ad {
max-width: calc(45px + 690px + (11px * 2));
}
2 Me gusta
system
(system)
Cerrado
5 Octubre, 2021 20:37
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.