Background border shadow css

CSS backgrounds and borders

The CSS backgrounds and borders module provides properties for adding borders, rounded corners, and box shadows to elements.

You can add different types of border styles, including borders made of images of any image type, from raster images to CSS gradients. Borders can be square or rounded, and a different radius can be set for each corner. Elements can be rounded whether or not they have a visible border.

Box shadows include inset and outset shadow, single or multiple shadows, and solid or allowed to fade to transparent. An outer box-shadow casts a shadow as if the border-box of the element were opaque. An inner box-shadow casts a shadow as if everything outside the padding edge were opaque. The shadow can be solid or include a spread distance with the shadow color transitioning to transparent.

The properties in this module also let you define whether cells inside a should have shared or separate borders.

Backgrounds, borders, and box shadows in action

This sample of borders, backgrounds, and box shadows consists of centered background images made of linear and radial gradients. A series of box shadows make the border appear to «pop». The element on the left has a border image set. The element on the right has a rounded dotted border.

Читайте также:  Как решать задачи javascript

The background images are defined with background-image . The images are centered with background-position . Different values of the background-clip property for the multiple background images are used to make the background images stay within the content box. The background color gets clipped to the padding box preventing the background from appearing through the transparent sections for the border-image and the dotted border . The rounded corners in the element on the right are created using the border-radius property. A single box-shadow declaration is used to set all the shadows, both inset and outset.

To see the code for this sample, view the source on GitHub.

Reference

Properties

  • background-attachment
  • background-clip
  • background-color
  • background-image
  • background-origin
  • background-position
  • background-repeat
  • background-size
  • background shorthand
  • background-position-x Experimental
  • background-position-y Experimental
  • background-position-inline Experimental
  • background-position-block Experimental
  • border-bottom-color
  • border-bottom-style
  • border-bottom-width
  • border-bottom shorthand
  • border-left-color
  • border-left-style
  • border-left-width
  • border-left shorthand
  • border-right-color
  • border-right-style
  • border-right-width
  • border-right shorthand
  • border-top-color
  • border-top-style
  • border-top-width
  • border-top shorthand
  • border-color shorthand
  • border-style shorthand
  • border-width shorthand
  • border shorthand
  • border-collapse
  • border-bottom-left-radius
  • border-bottom-right-radius
  • border-top-left-radius
  • border-top-right-radius
  • border-radius shorthand
  • border-image-outset
  • border-image-repeat
  • border-image-slice
  • border-image-source
  • border-image-width
  • border-image shorthand
  • box-shadow

Data types

Guides

Explains how to implement decorative images using CSS background images.

Explains how to set one or more backgrounds on an element.

Describes how to change the size and repeating behavior of background images.

Explains how borders, along with other box model properties, impact the CSS box model.

Explains how to create CSS gradient background images.

  • border-block-end-color property
  • border-block-start-color property
  • border-inline-end-color property
  • border-inline-start-color property
  • border-block-end-style property
  • border-block-start-style property
  • border-inline-end-style property
  • border-inline-start-style property
  • border-block-end-width property
  • border-block-start-width property
  • border-inline-end-width property
  • border-inline-start-width property
  • border-start-start-radius property
  • border-start-end-radius property
  • border-end-start-radius property
  • border-end-end-radius property
  • box-sizing property
  • box-decoration-break property
  • text-shadow property
  • url() CSS function
  • data type
  • data type
  • data type
  • currentcolor keyword

Specifications

See also

  • Interactive tools that let you visually create borders images, rounded corners, and box shadows:
    • Border-image generator
    • Border-radius generator
    • Box-shadow generator

    Found a content problem with this page?

    This page was last modified on Jul 17, 2023 by MDN contributors.

    Your blueprint for a better internet.

    Источник

    CSS box-shadow генератор

    box-shadow — это CSS3 свойство, которое позволяет создавать эффект тени для, практически, любого элемента веб страницы. Оно похоже на эффект Drop Shadows в Photoshop, с помощью этого свойства создается иллюзия глубины на 2-мерных страницах.

    Синтаксис

    Свойство принимает составное значение из пяти разных частей: горизонтальное смещение, вертикальное смещение, размытие, растяжение, цвет тени. К тому же можно указать будет ли тень внешней или внутренней.

     CSS div { box-shadow: offset-x offset-y blur spread color position; } 

    В отличие от других свойств, каких как border, которые разбиты на подсвойства (border-width, border-style и тд), box shadow CSS стоит особняком. Соответственно, важен порядок, в котором вы записываете значения свойства.

    Горизонтальное смещение (по оси X)

    Первое значение offset-x — смещение тени по оси X. Положительное значение сместит тень вправо, а отрицательное — влево.

     CSS .box-1 { box-shadow: -15px 0 10px 0 rgba(0,0,0,0.2); } .box-2 { box-shadow: 15px 0 10px 0 rgba(0,0,0,0.2); } 

    Вертикальное смещение (по оси Y)

    Второе значение offset-y — смещение тени по оси Y. Положительное значение сместит тень вниз, а отрицательное — наверх.

     CSS .box-1 { box-shadow: 0 15px 10px 0 rgba(0,0,0,0.2); } .box-2 { box-shadow: 0 -15px 10px 0 rgba(0,0,0,0.2); } 

    Размытие

    Третье значение (blur) представляет собой радиус размытия тени, посмотрите как он работает на box shadow генераторе выше. Значение 0 означает, что тень будет совсем не размыта, края и стороны будут абсолютно четкие. Чем выше значение, тем более мутную и размытую тень вы получите. Отрицательные значения не допускаются.

     CSS .box-1 { box-shadow: 0 5px 0 0 rgba(0,0,0,0.2); } .box-2 { box-shadow: 0 5px 15px 0 rgba(0,0,0,0.2); } .box-3 { box-shadow: 0 5px 30px 0 rgba(0,0,0,0.2); } 

    Растяжение

    Четвертое значение (spread) представляет собой размер тени или дистанции от тени до элемента. При положительном значении тень увеличится, выйдет за пределы элемента. Отрицательное значение уменьшит и сожмет тень.

     CSS .box-1 { box-shadow: 0 0 5px 0 rgba(0,0,0,0.2); } .box-2 { box-shadow: 0 0 5px 5px rgba(0,0,0,0.2); } .box-3 { box-shadow: 0 0 5px -15px rgba(0,0,0,0.2); } 

    Цвет

    Цвет тени может быть абсолютно любым и записан в разных форматах, доступных в CSS (HEX, RGB, RGBA и пр), попробуйте разные оттенки в css box shadow generator.

     CSS .box-1 { box-shadow: 0 10px 5px -5px #e6ecc1; } .box-2 { box-shadow: 0 10px 5px -5px rgba(30, 129, 204, 0.2); } 

    Внешняя/внутренняя

    Значение inset определяет положение тени. По умолчанию оно не указано, это означает, что тень будет снаружи элемента. Для того, чтобы тень была внутри элемента, необходимо в конце добавить ключевое слово inset.

     CSS .box-1 { box-shadow: 10px 10px 10px 2px rgba(34, 60, 80, 0.2) inset; } .box-2 { box-shadow: 10px 10px 10px 2px rgba(34, 60, 80, 0.2); } 

    Несколько теней

    В CSS тень блока может быть не одна. Чтобы добавить несколько теней, достаточно написать их в одном свойстве через запятую.

     CSS .box-1 { box-shadow: 10px 10px 10px 2px rgba(34, 60, 80, 0.2) inset, 10px 10px 10px 2px rgba(34, 60, 80, 0.2); } 

    Круглая тень

    Тень может быть круглой, для этого достаточно добавить свойство border-radius

     CSS .box-1 { box-shadow: 10px 10px 10px 0px rgba(34, 60, 80, 0.2); border-radius: 50%; } 

    Эффект увеличения с тенью

    Используя свойства box-shadow и transform, можно создать иллюзию приближения и отдаления элемента от пользователя.

     CSS .box-1 { transform: scale(1); box-shadow: 0 0 5px 5px rgba(34, 60, 80, 0.2); transition: box-shadow 0.5s, transform 0.5s; } .box-1:hover { ransform: scale(1.2); box-shadow: 0 0 15px 7px rgba(34, 60, 80, 0.2); transition: box-shadow 0.5s, transform 0.5s; } 

    Эффект парения элемента с помощью box-shadow

    Мы можем добавить тень к псевдоэлементу :after и создать тень ниже элемента. Тем самым создавая иллюзию, что элемент был поднят вверх, а потом упал.

     CSS .box-1 { position: relative; transform: translateY(0); transition: transform 1s; } .box-1::after { content: ""; display: block; position: absolute; bottom: -30px; left: 50%; height: 8px; width: 100%; box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 0.4); border-radius: 50%; background-color: rgba(0, 0, 0, 0.2); transform: translate(-50%, 0); transition: transform 1s; } .box-1:hover { transform: translateY(-40px); transition: transform 1s; } .box-1:hover::after { transform: translate(-50%, 40px) scale(0.75); transition: transform 1s; } 

    Тень и свойство clip-path

    Тень возможно сделать не только на элементах в виде блока или круга, но и на более сложных формах с использованием свойства clip-path . Правда свойство box-shadow при этом не сработает и нам придется заменить его другим. Приступим, создадим элемент box-1.

     CSS .box-1 { clip-path: polygon(30px 0%, 100% 0%, 100% 100%, 30px 100%, 0 50%); } 

    В CSS существует фильтр, который тоже делает CSS тень блока — drop-shadow() . Но у вас не поучится использовать его непосредственно на элементе, так как clip-path просто отрежет эту тень. Поэтому создаем родительский блок и наложим тень на него.

     CSS .box-1__wrapper { filter: drop-shadow(-1px 6px 3px rgba(34, 60, 80, 0.2)); } .box-1 { clip-path: polygon(30px 0%, 100% 0%, 100% 100%, 30px 100%, 0 50%); } 
    • Студия Профессиональная разработка сайтов под заказ Подробнее
    • Иконки Прекрасный способ визуально выразить главную мысль Подробнее
    • Сервисы Полезные инструменты для веб разработчиков Подробнее
    • Блог Делимся в опытом и знанием в IT сфере Подробнее
    • Поделиться ВконтактеFacebook Контакты support@active-vision.ru

    © 2019 — 2023 Active-Vision. Политика конфиденциальности. Вся информация на сайте носит справочный характер и не является публичной офертой, определяемой статьей 437 ГК РФ

    Источник

    CSS box-shadow Property

    The box-shadow property attaches one or more shadows to an element.

    Default value: none
    Inherited: no
    Animatable: yes. Read about animatable Try it
    Version: CSS3
    JavaScript syntax: object.style.boxShadow=»10px 20px 30px blue» Try it

    Browser Support

    The numbers in the table specify the first browser version that fully supports the property.

    Numbers followed by -webkit- or -moz- specify the first version that worked with a prefix.

    CSS Syntax

    Note: To attach more than one shadow to an element, add a comma-separated list of shadows (see «Try it Yourself» example below).

    Property Values

    Value Description Demo
    none Default value. No shadow is displayed Demo ❯
    h-offset Required. The horizontal offset of the shadow. A positive value puts the shadow on the right side of the box, a negative value puts the shadow on the left side of the box Demo ❯
    v-offset Required. The vertical offset of the shadow. A positive value puts the shadow below the box, a negative value puts the shadow above the box Demo ❯
    blur Optional. The blur radius. The higher the number, the more blurred the shadow will be Demo ❯
    spread Optional. The spread radius. A positive value increases the size of the shadow, a negative value decreases the size of the shadow Demo ❯
    color Optional. The color of the shadow. The default value is the text color. Look at CSS Color Values for a complete list of possible color values.

    More Examples

    Example

    Add a blur effect to the shadow:

    Источник

Оцените статью