You are here

background_image.css.twig in Background Image 2.x

/* Background Image Styles (https://www.drupal.org/project/background_image). */

{# Wrapper #}
.{{ base_class }}-wrapper {
  position: relative;
}

.{{ base_class }}-full-viewport .{{ base_class }}-wrapper::after {
  content: '';
  display: block;
  position: relative;
  height: 100vh;
  width: 100vw;
  z-index: -1;
}

{# Image #}
.{{ base_class }}-inner {
  bottom: 0;
  left: 0;
  overflow: hidden;
  position: fixed;
  right: 0;
  top: 0;
  transform: translate3d(0, 0, 0);
  z-index: -1;
}

.{{ base_class }},
.{{ base_class }}::before,
.{{ base_class }}::after {
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  bottom: -40px;
  display: block;
  left: -40px;
  position: absolute;
  right: -40px;
  top: -40px;
  transform: translate3d(0,0,0) translateZ(0);
}

{# Scroll Full Viewport Blur #}
{% if settings.blur.type == 2 %}
body:not(.{{ base_class }}-full-viewport) .{{ base_class }} {
  filter: blur({{ settings.blur.radius }}px);
}
{% endif %}

{# Persistent Blur #}
{% if settings.blur.type == 3 %}
.{{ base_class }} {
  filter: blur({{ settings.blur.radius }}px);
}
{% endif %}

.{{ base_class }}::before,
.{{ base_class }}::after {
  content: '';
}

.{{ base_class }}-overlay {
  bottom: 0;
  height: 100vh;
  left: 0;
  position: absolute;
  right: 0;
  transform: translate3d(0,0,0) translateZ(0);
}

body:not(.{{ base_class }}-full-viewport) .{{ base_class }}-overlay {
  display: none;
}

{# Text #}
.{{ base_class }}-full-viewport .{{ base_class }}-text {
  bottom: 0;
  left: 0;
  position: absolute;
  right: 0;
}

.{{ base_class }}-text {
  width: 100%;
}

{# Preload Image #}
.{{ background_image_class }}::before {
  background-color: {{ settings.preload.background_color|default('transparent') }};
  background-image: url("{{ preload_url }}");
  {# Blur the preload image so it doesn't appear pixelated. Don't use
     settings.blur.radius though as it might not be set. -#}
  -webkit-filter: blur(40px);
  filter: blur(40px);
}

{# Fallback Image #}
.{{ background_image_class }}::after {
  background-image: url("{{ fallback_url }}");
}

{# Media Queries #}
{% for media in media_queries %}
@media {{ media.query }} {
  .{{ background_image_class }}::after {
    background-image: url("{{ media.url }}");
  }
}
{% endfor %}

File

templates/background_image.css.twig
View source
  1. /* Background Image Styles (https://www.drupal.org/project/background_image). */
  2. {# Wrapper #}
  3. .{{ base_class }}-wrapper {
  4. position: relative;
  5. }
  6. .{{ base_class }}-full-viewport .{{ base_class }}-wrapper::after {
  7. content: '';
  8. display: block;
  9. position: relative;
  10. height: 100vh;
  11. width: 100vw;
  12. z-index: -1;
  13. }
  14. {# Image #}
  15. .{{ base_class }}-inner {
  16. bottom: 0;
  17. left: 0;
  18. overflow: hidden;
  19. position: fixed;
  20. right: 0;
  21. top: 0;
  22. transform: translate3d(0, 0, 0);
  23. z-index: -1;
  24. }
  25. .{{ base_class }},
  26. .{{ base_class }}::before,
  27. .{{ base_class }}::after {
  28. background-repeat: no-repeat;
  29. background-position: center center;
  30. background-size: cover;
  31. bottom: -40px;
  32. display: block;
  33. left: -40px;
  34. position: absolute;
  35. right: -40px;
  36. top: -40px;
  37. transform: translate3d(0,0,0) translateZ(0);
  38. }
  39. {# Scroll Full Viewport Blur #}
  40. {% if settings.blur.type == 2 %}
  41. body:not(.{{ base_class }}-full-viewport) .{{ base_class }} {
  42. filter: blur({{ settings.blur.radius }}px);
  43. }
  44. {% endif %}
  45. {# Persistent Blur #}
  46. {% if settings.blur.type == 3 %}
  47. .{{ base_class }} {
  48. filter: blur({{ settings.blur.radius }}px);
  49. }
  50. {% endif %}
  51. .{{ base_class }}::before,
  52. .{{ base_class }}::after {
  53. content: '';
  54. }
  55. .{{ base_class }}-overlay {
  56. bottom: 0;
  57. height: 100vh;
  58. left: 0;
  59. position: absolute;
  60. right: 0;
  61. transform: translate3d(0,0,0) translateZ(0);
  62. }
  63. body:not(.{{ base_class }}-full-viewport) .{{ base_class }}-overlay {
  64. display: none;
  65. }
  66. {# Text #}
  67. .{{ base_class }}-full-viewport .{{ base_class }}-text {
  68. bottom: 0;
  69. left: 0;
  70. position: absolute;
  71. right: 0;
  72. }
  73. .{{ base_class }}-text {
  74. width: 100%;
  75. }
  76. {# Preload Image #}
  77. .{{ background_image_class }}::before {
  78. background-color: {{ settings.preload.background_color|default('transparent') }};
  79. background-image: url("{{ preload_url }}");
  80. {# Blur the preload image so it doesn't appear pixelated. Don't use
  81. settings.blur.radius though as it might not be set. -#}
  82. -webkit-filter: blur(40px);
  83. filter: blur(40px);
  84. }
  85. {# Fallback Image #}
  86. .{{ background_image_class }}::after {
  87. background-image: url("{{ fallback_url }}");
  88. }
  89. {# Media Queries #}
  90. {% for media in media_queries %}
  91. @media {{ media.query }} {
  92. .{{ background_image_class }}::after {
  93. background-image: url("{{ media.url }}");
  94. }
  95. }
  96. {% endfor %}