Web_Basic
  • Introduction
  • Web Component
  • HTML basic
  • CSS basic
    • Inline element 與 Block element
    • 實用CSS 技巧
    • CSS Grid 教學
  • CSS Advance
    • Adobe spectrum
    • CSS Tricks
    • Contain block
    • OOCSS、SMACSS、BEM、SEM、BIO
    • z-index
    • Flexbox教學
    • 使用Materialize css
    • 使用Semantic UI
    • 使用Bootstrap
    • Ant design
    • Less
    • Animation
    • 簡單的特效
    • SCSS
  • Javascript basic
  • 開始寫一個網站前
    • 寫一個靜態網站2
    • 寫一個靜態網站
  • 部屬到github pages
  • 做一個OX小遊戲
  • 做一個貪食蛇小遊戲
  • canvas
  • Regexp
  • SVG
  • Sublime快捷鍵
  • Deploy Blog 使用 Hexo
  • 域名設定
    • 註冊域名信箱
      • 使用AWS SES
      • mailgun
    • subdomain,清除DNS快取
  • 使用cloudflare
  • 使用VNC server
  • SEO
    • Sitemap
    • search console
  • 遠端連線
  • HTML LiveReload
  • ngrok 與 local tunnel
  • Service worker 與 Cache
  • Zeplin 搭配 Sketch
  • 測試 IE 網頁相容性
  • 網站產生器
Powered by GitBook
On this page
  • 1.使用純CSS做一個Modal,之後點擊外框即可消失
  • 2.字體大小 RWD
  • 元素保持置底
  • 左右兩邊各一個 scroll bar

Was this helpful?

  1. CSS basic

實用CSS 技巧

PreviousInline element 與 Block elementNextCSS Grid 教學

Last updated 4 years ago

Was this helpful?

1.使用純CSS做一個Modal,之後點擊外框即可消失

html

     <div >
       <input  className="modal-state" id="modal-1" type="checkbox" />  
       <div className="modalbg" style={{width: '100%', height: '100%', background: 'rgba(0,0,0, .6)', position: 'fixed', top: '0', left: '0'}}>
         <div className="modalWhite" style={{zIndex:'100',width: '50%', height: '50%', background: 'white', position: 'fixed', top: '25%', left: '25%'}} ></div> 
         <label className="modal__bg" htmlFor="modal-1"></label>
       </div>     
     </div>

css

.modal__bg {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  cursor: pointer;
}

.modalbg {
  visibility: hidden;
}

.modalWhite {
  visibility: hidden;
}

.modal-state {
  display: none;
}

.modal-state:checked ~ .modalbg > .modalWhite {
  visibility: visible;
}

.modal-state:checked ~ .modalbg {
  visibility: visible;
}

之後可使用以下,即可呼叫出Modal

document.getElementById('modal-1').click()

2.字體大小 RWD

html {
 font-size: 1vw
}

讓最外層用 vw,內層元素用rem來相對於最 root 的比例。

div {
  font-size: 1.2rem
}

em是用來相對直接外層元素的大小,rem是相對根元素。

元素保持置底

<div class="container">
  <div class="left">

  </div>
  <div class="right">
    <div class="progress">I'm progress bar</div>
</div>
.container {
  display: flex;
  width: 500px;
  height: 1200px;
}

.left {
  flex: 1;
  background: blue;
}

.right {
  flex: 1;
  background: yellow;
  transform: scale(1);
}

.progress {
  width: 100%;
  position: fixed;
  background: gray;
  bottom: 0;
}

左右兩邊各一個 scroll bar

兩邊設定 height: 100vh; overflow-y: scroll;

https://codepen.io/EasonWang01/pen/VwKXRPR