- Magento 2.2.3
- Ubuntu 16.04 Server VM using VirtualBox with icewm window manager
- Apache 2.4
- MySQL 14.14
- PHP 7.0
- Custom theme which inherits from
Magento/blank
I have a custom .phtml
file:
Vendor/theme/Magento_Theme/templates/html/new_products.phtml
<div class="new-products-banner-container">
<div class="new-products-banner">
<h1 class="new-products-banner-title">NEW RELEASES</h1>
</div>
</div>
<?php echo $this->getLayout()
->createBlock("Magento\Catalog\Block\Product\Widget\NewWidget")
->setProductsCount("10")
->setTemplate("product/widget/new/content/new_grid.phtml")
->toHtml();
?>
The block inherits styles perfectly well when written outside of any media query, however I can use neither the .media-width
mixin, nor a CSS @media
query to separate mobile/desktop styles.
When placing these styles within media queries, the default styles are applied. I have tried various configurations within the .less file and its current state is as follows:
Vendor/theme/Magento_Theme/web/css/new_products.less
//
// Common
// _____________________________________________
& when (@media-common = true) {
.new-products-banner-container {
width: 100%;
height: 53px;
z-index: 1;
}
.new-products-banner {
width: 100%;
max-width: 1280px;
height: 100%;
margin: 0 auto;
}
.new-products-banner-title {
margin-bottom: 0;
}
.block-title {
display: none;
}
.block-new-products {
margin-top: 10px;
}
}
//
// Mobile
// _____________________________________________
.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {
.new-products-banner-container {
width: 100%;
height: 53px;
z-index: 1;
}
.new-products-banner {
width: 100%;
max-width: 1280px;
height: 100%;
margin: 0 auto;
}
.new-products-banner-title {
margin-bottom: 0;
line-height: 2;
}
.block-title {
display: none;
}
.block-new-products {
margin-top: 10px;
}
}
//
// Desktop
// _____________________________________________
.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
.new-products-banner-container {
width: 100%;
height: 53px;
z-index: 1;
}
.new-products-banner {
width: 100%;
max-width: 1280px;
height: 100%;
margin: 0 auto;
}
.new-products-banner-title {
margin-bottom: 0;
line-height: 1.25;
}
.block-title {
display: none;
}
.block-new-products {
margin-top: 10px;
}
}
Note:
I am aware that styles needn't be repeated for mobile/desktop views when they are included in the common view, however even these measures do not ensure that the CSS is rendered.