AMP & CSS
-
Hi,
I am using the original AMP (classic mode) plugin. But I don’t understand exactly how to do the CSS settings. Can you give me a sample code?
Thank you
Viewing 2 replies - 1 through 2 (of 2 total)
-
HI @2ladd,
in the classic mode you need to utilize the amp_post_template_css action of the AMP plugin. You can read more about this here: https://amp-wp.org/documentation/how-the-plugin-works/classic-templates/. You should put the code in your child theme’s functions.php. The sample code is below:
add_action( 'amp_post_template_css', 'xyz_amp_my_additional_css_styles' ); function xyz_amp_my_additional_css_styles( $amp_template ) { // only CSS here please... ?> /* Results widget stars */ .rmp-amp-star::before { content: "★"; font-size: 26px; color: #ccc; margin: -2px; } .rmp-amp-star-highlighted::before { color: #FF912C; } .rmp-amp-stars, .rmp-amp-average, .rmp-amp-votes { display: inline-block; } /* Text-align center in rating widget */ .rmp-amp-rating-widget { text-align: center; } /* Bottom margin on title */ #rmp-amp-rating-widget-title { margin-bottom: 10px; } /* These two inputs should not be displayed */ #rmp-amp-action, #rmp-amp-post-id { display: none; } /* Center the stars */ .rmp-amp-centered-fieldset { margin-left: auto; margin-right: auto; max-width: 200px; } .rmp-amp-rating { --star-size: 3; /* use CSS variables to calculate dependent dimensions later */ padding: 0; /* to prevent flicker when mousing over padding */ border: none; /* to prevent flicker when mousing over border */ unicode-bidi: bidi-override; direction: rtl; /* for CSS-only style change on hover */ text-align: left; /* revert the RTL direction */ user-select: none; /* disable mouse/touch selection */ font-size: 3em; /* fallback - IE doesn't support CSS variables */ font-size: calc(var(--star-size) * 1em); /* because <code>var(--star-size)em</code> would be too good to be true */ cursor: pointer; /* disable touch feedback on cursor: pointer - http://stackoverflow.com/q/25704650/1269037 */ -webkit-tap-highlight-color: rgba(0,0,0,0); -webkit-tap-highlight-color: transparent; margin-bottom: 16px; } /* the stars */ .rmp-amp-rating > label { display: inline-block; position: relative; width: 1.1em; /* magic number to overlap the radio buttons on top of the stars */ width: calc(var(--star-size) / 3 * 1.1em); } .rmp-amp-rating > *:hover, .rmp-amp-rating > *:hover ~ label, .rmp-amp-rating:not(:hover) > input:checked ~ label { color: transparent; /* reveal the contour/white star from the HTML markup */ cursor: inherit; /* avoid a cursor transition from arrow/pointer to text selection */ } .rmp-amp-rating > *:hover:before, .rmp-amp-rating > *:hover ~ label:before, .rmp-amp-rating:not(:hover) > input:checked ~ label:before { content: "★"; position: absolute; left: 0; color: gold; } .rmp-amp-rating > input { position: relative; transform: scale(3); /* make the radio buttons big; they don't inherit font-size */ transform: scale(var(--star-size)); /* the magic numbers below correlate with the font-size */ top: -0.5em; /* margin-top doesn't work */ top: calc(var(--star-size) / 6 * -1em); margin-left: -2.5em; /* overlap the radio buttons exactly under the stars */ margin-left: calc(var(--star-size) / 6 * -5em); z-index: 2; /* bring the button above the stars so it captures touches/clicks */ opacity: 0; /* comment to see where the radio buttons are */ font-size: initial; /* reset to default */ } form.amp-form-submit-error [submit-error] { color: red; } <?php }You might have to adjust the css to fit your website.
Blaz
Thank you.
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘AMP & CSS’ is closed to new replies.