Giter VIP home page Giter VIP logo

unocss-preset-safe-area's Introduction

unocss-preset-safe-area

Use safe area with UnoCSS.

Usage

Setup

To ensure the correct functioning of env styles, make sure to include the viewport-fit=cover in viewport meta tag:

<meta
    name="viewport"
-   content="width=device-width, initial-scale=1.0"
+   content="width=device-width, initial-scale=1.0, viewport-fit=cover"
/>

Installation

npm install unocss @yeungkc/unocss-preset-safe-area
yarn add unocss @yeungkc/unocss-preset-safe-area
pnpm add unocss @yeungkc/unocss-preset-safe-area

Import

import presetSafeArea from '@yeungkc/unocss-preset-safe-area'

export default defineConfig({
    ...
    presets: [...presetSafeArea()...]
    ...
})

Rule

This preset supports safe-area-inset-*, titlebar-area-* and keyboard-inset-*.

Basic usage:

  • pt-safe-1 : padding-top:env(safe-area-inset-top, 0.25rem);
  • for addition, use +, example: pt+safe-1 : padding-top:calc(env(safe-area-inset-top) + 0.25rem);.
  • To specify env properties, like titlebar-x, keyboard-t, use w-titlebar-x-1:width:env(titlebar-area-x, 0.25rem);.

Currently supports p, m, w, h, max-w, min-w, max-h, min-h, left, top, right, bottom, where:

  • safe represents safe-area-inset-
  • titlebar represents titlebar-area-
  • keyboard represents keyboard-inset-

For all usage examples, it's all Autocomplete:

(top|left|right|bottom)(+|-)(safe|keyboard)-<num>
(top|left|right|bottom)(+|-)safe-(r|l|t|b)-<num>
(top|left|right|bottom)(+|-)titlebar-(x|y|w|h)-<num>
(top|left|right|bottom)(+|-)keyboard-(r|l|t|b|w|h)-<num>
(w|h)(+|-)safe-(r|l|t|b)-<num>
(min|max)-(w|h)(+|-)safe-(r|l|t|b)-<num>
(w|h)(+|-)(titlebar|keyboard)-<num>
(w|h)(+|-)titlebar-(x|y|w|h)-<num>
(min|max)-(w|h)(+|-)(titlebar|keyboard)-<num>
(min|max)-(w|h)(+|-)titlebar-(x|y|w|h)-<num>
(w|h)(+|-)keyboard-(r|l|t|b|w|h)-<num>
(min|max)-(w|h)(+|-)keyboard-(r|l|t|b|w|h)-<num>
(m|p)(r|l|t|b)(+|-)(safe|keyboard)-<num>
(m|p)(r|l|t|b)(+|-)safe-(r|l|t|b)-<num>
(m|p)(r|l|t|b)(+|-)titlebar-(x|y|w|h)-<num>
(m|p)(r|l|t|b)(+|-)keyboard-(r|l|t|b|w|h)-<num>

If you need more clarification, you can refer to this CSS example.

License

MIT License © 2024-PRESENT YeungKC

unocss-preset-safe-area's People

Contributors

yeungkc avatar

Stargazers

lly avatar Hooray Hu avatar Johnkat Mj avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.