CSS

Last Edited Time
Feb 9, 2022 06:16 AM
date
Jan 3, 2018
slug
css
status
Published
tags
CSS
Notebook
summary
早期的 CSS 记录
type
Post

body size

html,
body {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

remove select default style

-webkit-appearance: none;

add placeholder for input[date]

input[type='month']::before {
  color: #999999;
  content: attr(placeholder);
}

input[type='month'] {
  color: #ffffff;
}

input[type='month']:focus,
input[type='date']:valid {
  color: #666666;
}

input[type='month']:focus::before,
input[type='date']:valid::before {
  content: '' !important;
}

/* onblur="(this.type='."'text'".')" onfocus="(this.type='."'time'".')" oninput="(this.type='."'text'".')" onchange="(this.type='."'text'".')" */

disable text selection

* {
  -webkit-user-select: none;
  -moz-user-select: none;
}

input {
  -webkit-user-select: text;
  -moz-user-select: text;
}

iPhone tap highlight color

* {
  -webkit-tap-highlight-color: transparent;
}

smooth scroll

.affix {
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
}

not show scrollbar

#element::-webkit-scrollbar {
  display: none;
}

disable 300ms delay

button {
  -ms-touch-action: none;
  ####IE10 touch-action: none;
  ####IE11;
}

center a block

#dropDownIcon {
  position: absolute;
  left: 50%;
  transform: translateY(-50%);
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
}

blur the image

.storeNavBg {
  width: 100%;
  height: 19rem;
  background-repeat: no-repeat;
  position: fixed;
  background-size: 100% 100%;
  filter: blur(10px);
}

css transation

.shoppingCart.open > .cartMask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: calc(100vh - 4.2rem);
  background-color: #000;
  opacity: 0.4;
}

.shoppingCart > .cartMask {
  opacity: 0;
  -webkit-transition: opacity 0.3s ease;
  ####for safari transition: opacity 0.3s ease;
}

remove the default shadow style of bootstrap

#searchKey:focus {
  transition: border linear 0.2s, box-shadow linear 0.5s;
  -moz-transition: border linear 0.2s, -moz-box-shadow linear 0.5s;
  -webkit-transition: border linear 0.2s, -webkit-box-shadow linear 0.5s;
  outline: none;
  border-color: rgba(239, 190, 95, 0.75);
  box-shadow: 0 0 8px rgba(239, 190, 95, 0.105);
  -moz-box-shadow: 0 0 8px rgba(239, 190, 95, 0.5);
  -webkit-box-shadow: 0 0 8px rgba(239, 190, 95, 3);
}

ellipsis

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

ellipsis the text after 3lines

li.foodCat a span {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  white-space: pre-wrap;
}

iPhone Safari minimal-ui

flipping from portrait to landscape

prevent event

pointer-events: none;

create toggle

width auto fit

.grid {
  display: -webkit-flex;
  display: -moz-flex;
  display: -o-flex;
  display: -ms-flex;
  display: flex;
}
.col {
  padding: 30px;
}
.fluid {
  flex: 1;
  background-color: #ccc;
}
.fixed {
  background-color: yellow;
}

flex

#area-category .menu-first-group {
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  vertical-align: baseline;
  width: 100%;
  margin: 1rem 0.2rem;
}

#area-category .menu-first-btn {
  -webkit-box-flex: 1;
  -ms-flex: 1 0 auto;
  flex: 1 0 auto;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

change radio to button

position: absolute;
clip: rect(0, 0, 0, 0);
pointer-events: none;

center image

max-width: 100% !important;
max-height: 100% !important;
height: auto !important;
width: auto !important;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;

right align overflow text

white-space: nowrap;
direction: rtl;

Blurry downscaled images in Chrome

image-rendering: -webkit-optimize-contrast;

Image ratio error on safari

Resize image(keep ratio) by max-width will work on Chrome. However, it will still using image original height on some browser, such as Safari.

Percentage ratio layout

.banner {
  padding: 56.25% 0 0;
  position: relative;
}
.banner > img {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
}