You are here

background_image.css.twig in Background Image 2.0.x

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

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

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