Master precise counter placement with custom positioning, width controls, z-index layering, padding, margins, and responsive transforms
🎯 Overview: Layout & Positioning with Custom CSS
Counter placement is critical for visibility without obstruction. While the Styling tab offers dropdown controls for position type (Absolute/Relative/Fixed), top/left/right/bottom coordinates, width, and z-index, Custom CSS unlocks unlimited positioning freedom:
- 📍 Precise coordinate control – Set exact pixel or percentage positions beyond dropdown increments
- 📏 Advanced width and height – Control container dimensions independently for desktop and mobile
- 🔢 Custom z-index values – Layer counters above or below any element with negative or large values
- 📦 Padding and margin control – Fine-tune spacing inside and outside the counter
- 🔄 Transform-based positioning – Use
translate,scale,rotatefor advanced placement - 📱 Mobile position overrides – Different positioning for mobile devices with media queries
- 🎯 Per-product positioning – Different positions for different products or categories
- 🌀 Dynamic positioning – Animate counter movement with keyframes
This article covers every aspect of layout and positioning with Custom CSS, from basic coordinate overrides to complex responsive positioning strategies. We’ll explore the .product-views-counter container selector and how to control every positioning property.
💡 Prerequisites: Read “Custom CSS – Getting Started” First
This article assumes you understand CSS selectors, the !important flag, per-product targeting with .postid-X, and how to access the Custom CSS box. If you’re new to Custom CSS, start with Custom CSS – Getting Started.
🧩 The Positioning Selector
All positioning CSS targets the outermost container with the class .product-views-counter:
HTML Structure
<div class="product-views-counter"> <!-- ⬅️ Target this for positioning -->
<div class="view-counter-wrapper">
<div class="view-counter-icon-wrapper">...</div>
<span class="view-counter-text">42 views in 48 hours</span>
</div>
</div>Key selector: .product-views-counter controls position, top, left, right, bottom, width, z-index, padding, margin, and transform.
📍 Position Type: Absolute, Relative, Fixed
The position property determines how the counter is positioned on the page:
| Value | Behavior | Use Case |
|---|---|---|
| Absolute | Positioned relative to nearest positioned ancestor (usually the product image container) | Default. Overlay counter on product image (top-left, bottom-right, etc.) |
| Relative | Positioned relative to its natural document flow position | Counter appears after the product image in document flow (below image) |
| Fixed | Positioned relative to viewport (stays in place when scrolling) | Sticky counter that follows user as they scroll (rare, use sparingly) |
Changing Position Type
/* Change to relative (counter appears below image) */
.product-views-counter {
position: relative !important;
}
/* Change to fixed (counter stays in viewport) */
.product-views-counter {
position: fixed !important;
top: 20px !important;
right: 20px !important;
}Important: When position: relative, the top/left/right/bottom properties are ignored by the plugin (set to 0 or auto). Use margin to adjust positioning instead.
🗺️ Coordinate Control: Top, Left, Right, Bottom
For position: absolute or position: fixed, use coordinate properties to place the counter:
Basic Coordinate Override
/* Top-left corner (10px from top, 10px from left) */
.product-views-counter {
position: absolute !important;
top: 10px !important;
left: 10px !important;
bottom: auto !important;
right: auto !important;
}
/* Bottom-right corner (10px from bottom, 10px from right) */
.product-views-counter {
position: absolute !important;
top: auto !important;
left: auto !important;
bottom: 10px !important;
right: 10px !important;
}Key rule: Set opposing coordinates to auto. If you set both top and bottom, the counter might stretch vertically (usually unintended). Use top or bottom, not both. Same for left/right.
Percentage-Based Positioning
Use % values for responsive positioning that scales with container size:
/* Center horizontally (50% from left) */
.product-views-counter {
position: absolute !important;
left: 50% !important;
transform: translateX(-50%) !important; /* Offset by half counter width */
}
/* Center vertically and horizontally */
.product-views-counter {
position: absolute !important;
top: 50% !important;
left: 50% !important;
transform: translate(-50%, -50%) !important;
}Why transform? When using left: 50%, the counter’s left edge is at 50%, not its center. transform: translateX(-50%) shifts it back by half its own width, achieving true centering.
Negative Coordinates (Off-Screen)
/* Partially off-screen (left edge hidden) */
.product-views-counter {
position: absolute !important;
top: 10px !important;
left: -20px !important; /* 20px off the left edge */
}
/* Completely off-screen (hidden until animation) */
.product-views-counter {
position: absolute !important;
top: 0 !important;
left: -200px !important; /* Fully off-screen */
animation: slide-in 1s ease forwards !important;
}
@keyframes slide-in {
to {
left: 10px; /* Slide into view */
}
}📏 Width and Height Control
Width (Container Size)
The plugin uses width (in %) for desktop and Width (Small Screens, %) for mobile. Override with Custom CSS:
/* Fixed pixel width (not percentage) */
.product-views-counter {
width: 250px !important;
}
/* Full width (100% of container) */
.product-views-counter {
width: 100% !important;
}
/* Auto width (shrink to content) */
.product-views-counter {
width: auto !important;
}Max-Width and Min-Width
/* Flexible width with limits */
.product-views-counter {
width: 100% !important;
max-width: 300px !important; /* Never wider than 300px */
min-width: 150px !important; /* Never narrower than 150px */
}Height (Usually Auto)
Height is typically auto (determined by content). You can override it for custom designs:
/* Fixed height (for square counters) */
.product-views-counter {
width: 100px !important;
height: 100px !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
}🔢 Z-Index: Layering and Stacking
Z-index controls which elements appear “on top” of others. Higher values = closer to user.
Basic Z-Index Override
/* High z-index (above most elements) */
.product-views-counter {
z-index: 9999 !important;
}
/* Low z-index (below most elements) */
.product-views-counter {
z-index: 1 !important;
}
/* Negative z-index (behind everything, even image) */
.product-views-counter {
z-index: -1 !important;
}Use cases:
- High z-index (9999) – Counter must appear above sticky headers, modals, or overlays
- Medium z-index (100-500) – Normal layering, above image but below headers
- Low z-index (1-10) – Counter should appear below certain elements
- Negative z-index (-1) – Counter appears behind the product image (watermark effect)
Per-Product Z-Index
/* High z-index for premium products (always on top) */
.postid-456 .product-views-counter {
z-index: 10000 !important;
}
/* Low z-index for sale items (subtle) */
.product_cat-sale .product-views-counter {
z-index: 10 !important;
}⚠️ Z-Index Only Works with Positioned Elements
Z-index only applies to elements with position: relative, absolute, or fixed. If position: static (default), z-index is ignored. Always ensure your counter has a position value other than static.
📦 Padding: Internal Spacing
Padding adds space inside the counter container, between the edge and the content:
Uniform Padding
/* 10px padding on all sides */
.product-views-counter {
padding: 10px !important;
}
/* No padding (tight fit) */
.product-views-counter {
padding: 0 !important;
}Directional Padding
/* Different padding per side (top right bottom left) */
.product-views-counter {
padding: 5px 15px 5px 15px !important; /* Vertical: 5px, Horizontal: 15px */
}
/* Individual sides */
.product-views-counter {
padding-top: 8px !important;
padding-right: 20px !important;
padding-bottom: 8px !important;
padding-left: 20px !important;
}Tip: Padding is applied to .product-views-counter. If you want padding around the wrapper (background/border box), target .view-counter-wrapper instead:
/* Padding inside the wrapper (with background) */
.view-counter-wrapper {
padding: 12px 24px !important;
}📐 Margin: External Spacing
Margin adds space outside the counter container, pushing it away from adjacent elements:
Basic Margin
/* 20px margin on all sides */
.product-views-counter {
margin: 20px !important;
}
/* Directional margin (top right bottom left) */
.product-views-counter {
margin: 10px 0 10px 0 !important; /* Vertical: 10px, Horizontal: 0 */
}Using Margin for Relative Positioning
When position: relative, use margin to adjust placement:
/* Relative position with margin offset */
.product-views-counter {
position: relative !important;
margin-top: -50px !important; /* Move counter up 50px */
margin-left: 20px !important; /* Move counter right 20px */
}Auto Margin for Centering
/* Center horizontally (for relative positioning) */
.product-views-counter {
position: relative !important;
margin-left: auto !important;
margin-right: auto !important;
}🔄 Transform: Advanced Positioning
The transform property allows positioning without affecting document flow:
Translate (Move)
/* Move right 20px, down 10px */
.product-views-counter {
transform: translate(20px, 10px) !important;
}
/* Move left 30px (negative X) */
.product-views-counter {
transform: translateX(-30px) !important;
}
/* Center with percentage */
.product-views-counter {
position: absolute !important;
left: 50% !important;
transform: translateX(-50%) !important;
}Scale (Resize)
/* Shrink to 80% of original size */
.product-views-counter {
transform: scale(0.8) !important;
}
/* Enlarge to 120% */
.product-views-counter {
transform: scale(1.2) !important;
}Rotate
/* Rotate 45 degrees */
.product-views-counter {
transform: rotate(45deg) !important;
}
/* Rotate -15 degrees (counterclockwise) */
.product-views-counter {
transform: rotate(-15deg) !important;
}Combining Transforms
/* Move, scale, and rotate (space-separated) */
.product-views-counter {
transform: translate(20px, 10px) scale(1.1) rotate(5deg) !important;
}📱 Mobile Position Overrides
Use media queries to apply different positioning on mobile devices:
Basic Mobile Override
/* Desktop: top-left, Mobile: bottom-right */
.product-views-counter {
position: absolute !important;
top: 10px !important;
left: 10px !important;
bottom: auto !important;
right: auto !important;
}
@media (max-width: 768px) {
.product-views-counter {
top: auto !important;
left: auto !important;
bottom: 10px !important;
right: 10px !important;
}
}Mobile: Full Width
/* Desktop: 50% width, Mobile: 100% width */
.product-views-counter {
width: 50% !important;
}
@media (max-width: 768px) {
.product-views-counter {
width: 100% !important;
left: 0 !important;
right: 0 !important;
}
}Mobile: Fixed Positioning (Sticky Counter)
/* Desktop: absolute, Mobile: fixed (sticky at top) */
.product-views-counter {
position: absolute !important;
top: 10px !important;
left: 10px !important;
}
@media (max-width: 768px) {
.product-views-counter {
position: fixed !important;
top: 0 !important;
left: 0 !important;
width: 100% !important;
z-index: 9999 !important;
}
}🎨 Real-World Positioning Examples
Example 1: Centered Counter Below Image
/* Counter appears below image, centered */
.product-views-counter {
position: relative !important;
margin-top: 15px !important;
margin-left: auto !important;
margin-right: auto !important;
width: auto !important;
}Example 2: Corner Badge (Top-Right)
/* Circular badge in top-right corner */
.product-views-counter {
position: absolute !important;
top: -10px !important;
right: -10px !important;
width: 60px !important;
height: 60px !important;
border-radius: 50% !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
z-index: 100 !important;
}
.view-counter-wrapper {
flex-direction: column !important;
gap: 2px !important;
}Example 3: Watermark Behind Image
/* Counter appears behind image (watermark effect) */
.product-views-counter {
position: absolute !important;
bottom: 20px !important;
right: 20px !important;
z-index: -1 !important; /* Behind image */
opacity: 0.3 !important;
font-size: 24px !important;
transform: rotate(-15deg) !important;
}Example 4: Sticky Counter on Mobile
/* Normal positioning on desktop, sticky on mobile */
@media (max-width: 768px) {
.product-views-counter {
position: fixed !important;
bottom: 0 !important;
left: 0 !important;
width: 100% !important;
z-index: 9999 !important;
background: rgba(0, 0, 0, 0.9) !important;
padding: 15px !important;
color: #ffffff !important;
}
}Example 5: Per-Product Positioning
/* Premium products: Top-right badge */
.postid-456 .product-views-counter {
top: 10px !important;
right: 10px !important;
bottom: auto !important;
left: auto !important;
}
/* Sale items: Bottom-left banner */
.product_cat-sale .product-views-counter {
top: auto !important;
right: auto !important;
bottom: 0 !important;
left: 0 !important;
width: 100% !important;
}🔍 Troubleshooting Positioning Issues
Issue 1: Counter Not Moving
Cause: Missing !important, or position: relative with top/left (use margin instead).
Solution:
/* ✅ CORRECT: Absolute with coordinates */
.product-views-counter {
position: absolute !important;
top: 20px !important;
left: 20px !important;
}
/* ✅ CORRECT: Relative with margin */
.product-views-counter {
position: relative !important;
margin-top: 20px !important;
}Issue 2: Z-Index Not Working
Cause: Element has position: static (default), which ignores z-index.
Solution:
/* ✅ CORRECT: Position + z-index */
.product-views-counter {
position: absolute !important; /* Required for z-index */
z-index: 9999 !important;
}Issue 3: Counter Not Centered with left: 50%
Cause: Missing transform: translateX(-50%).
Solution:
/* ✅ CORRECT: With transform offset */
.product-views-counter {
position: absolute !important;
left: 50% !important;
transform: translateX(-50%) !important;
}Issue 4: Mobile Position Not Applying
Cause: Media query breakpoint doesn’t match actual device width, or missing !important.
Solution:
/* ✅ CORRECT: With !important in media query */
@media (max-width: 768px) {
.product-views-counter {
bottom: 10px !important;
left: 10px !important;
}
}✅ Quick Reference: Positioning Essentials
| Property | Example |
|---|---|
| Position Type | position: absolute !important; |
| Coordinates | top: 20px !important; left: 20px !important; |
| Width | width: 250px !important; or width: 50% !important; |
| Z-Index | z-index: 9999 !important; |
| Padding | padding: 10px 20px !important; |
| Margin | margin: 15px !important; |
| Transform (Move) | transform: translate(20px, 10px) !important; |
| Transform (Center) | left: 50% !important; transform: translateX(-50%) !important; |
| Transform (Scale) | transform: scale(1.2) !important; |
| Transform (Rotate) | transform: rotate(15deg) !important; |