• Thế Giới Giải Mã

    Bí ẩn nhân loại Leonardo Da Vinci

  • Thế Giới Giải Mã

    Anh hùng thầm lặng Nikola Tesla

  • Thế Giới Giải Mã

    Thần đèn Thomas Edison

  • Thế Giới Giải Mã

    Người thôi miên Adolf Hitler

Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

22 June 2023

clientY vs pageY

 Đưa ra một điểm trong trang clientY và pageY là khoảng cách tính bằng pixel từ điểm đến đầu chế độ xem và trang.

Ở đây, trang là toàn bộ trang được hiển thị có thể có thanh cuộn, trong khi chế độ xem là phần hiển thị của trang.

┌─────────────────────────────┬─┐◀︎─── Web page      ▲
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | pageY
| | | |
=============================┼─┤ ▲ |
| | | | | |
| | | | | |
| Scroll bar──────────▶︎ | | | | clientY
| | | Browser | |
| | | window | |
| ● Point | | | ▼ ▼
| | | |
| | | |
=============================┼─┤ ▼
| | |
| | |
| | |
└─────────────────────────────┴─┘

19 June 2023

Box sizing - css

box-sizing: content-box; /* default */
box-sizing: border-box; /* với đường viền và lề */
box-sizing: inherit; /* lấy giá trị từ cha của nó */


Content-box
Các thuộc tính width height được đo chỉ bao gồm content chứ không bao gồm padding, border hoặc margin.

paddingborder và margin sẽ nằm ngoài hộp => width, height không tính padding, margin, border

// Content box
◀︎──── 200px ────▶︎

┌───────────────────────────────────────────────────────┐
| |
| ┌───────────────────────────────────────┐ |
| | | |
| | ┌───────────────┐ | |
| Border| Padding | Content | | |
| | | | | |
| 5px | 10px | 200px | 10px | 5px |
|◀︎─────▶︎|◀︎─────────▶︎|◀︎─────────────▶︎|◀︎─────────▶︎|◀︎─────▶︎|
| | | | | |
| | └───────────────┘ | |
| | | |
| └───────────────────────────────────────┘ |
| |
└───────────────────────────────────────────────────────┘


border-box
Các thuộc tính width height bao gồm padding border, nhưng không bao gồm margin.


padding và border sẽ ở bên trong hộp => width, height tính cả padding + border

// Border box
◀︎──────────────────────── 200px ────────────────────────▶︎

┌───────────────────────────────────────────────────────┐
| |
| ┌───────────────────────────────────────┐ |
| | | |
| | ┌───────────────┐ | |
| Border| Padding | Content | | |
| | | | | |
| 5px | 10px | 170px | 10px | 5px |
|◀︎─────▶︎|◀︎─────────▶︎|◀︎─────────────▶︎|◀︎─────────▶︎|◀︎─────▶︎|
| | | | | |
| | └───────────────┘ | |
| | | |
| └───────────────────────────────────────┘ |
| |
└───────────────────────────────────────────────────────┘

08 January 2023

Draw and Fill a polygon and triangle in HTML5

Draw Polygon <Vẽ hình đa giác>
2023
<!DOCTYPE HTML>
<html>
<head>
<title>An example to draw an polygon</title>
<script type="text/javascript">
    function drawPolygon() {
        var canvas = document.getElementById('canvasbox');
        if (canvas.getContext) {
            var objctx = canvas.getContext('2d');
 
            objctx.beginPath();
            objctx.moveTo(75, 50);
            objctx.lineTo(175, 50);
            objctx.lineTo(200, 75);
            objctx.lineTo(175, 100);
            objctx.lineTo(75, 100);
            objctx.lineTo(50, 75);
            objctx.closePath();
            objctx.fillStyle = "rgb(200,0,0)";
            objctx.fill();
 
 
        } else {
            alert('You need HTML5 compatible browser to see this demo.');
        }
    }
</script>
</head>
<body onload="drawPolygon();">
   <canvas id="canvasbox"></canvas>
</body>
</html>
Draw Triangle <Vẽ hình tam giác>
2023
<!DOCTYPE HTML>
<html>
<head>
<title>An example to draw an polygon</title>
<script type="text/javascript">
    function drawPolygon() {
        var canvas = document.getElementById('canvasbox');
        if (canvas.getContext) {
            var objctx = canvas.getContext('2d');
            objctx.beginPath();
            // polygon [x,y, x,y, x,y.....];
objctx.moveTo(50, 50); //x,y objctx.lineTo(50, 125); objctx.lineTo(150, 125); objctx.closePath(); objctx.stroke(); } else { alert('You need HTML5 compatible browser to see this demo.'); } } </script> </head> <body onload="drawPolygon();"> <canvas id="canvasbox"></canvas> </body> </html>

beginPath() Mỗi khi phương thức này được gọi, danh sách sẽ được đặt lại và chúng ta có thể bắt đầu vẽ các hình mới.

moveTo(x, y) điều này sẽ đặt vị trí khởi động của đường dẫn. Trong ví dụ trên, chúng ta đang vẽ đường đi từ (75,50) điểm.

lineTo(x, y) sẽ vẽ đường thẳng trong đó x và y sẽ là điểm cuối. Phương thức này có hai đối số – x và y, – là tọa độ của điểm cuối và điểm bắt đầu của đường phụ thuộc vào điểm cuối của đường dẫn được vẽ trước đó hoặc tọa độ di chuyển tới(x,y). Ví dụ objctx.lineTo(175, 50) sẽ vẽ đường thẳng từ điểm đầu (75,50) đến điểm cuối (175,50).

closePath() sẽ đóng hình bằng cách vẽ một đường thẳng từ điểm hiện tại đến điểm bắt đầu. Nếu hình đã được đóng hoặc chỉ có một điểm trong danh sách, chức năng này sẽ không làm gì.

fillStyle sẽ đặt thuộc tính nền nhưng sẽ không lấp đầy.

fill() sẽ tô hình dạng theo fillStyle. Nếu không có kiểu tô màu thì nó sẽ tô màu đen.

Ví dụ ta có toạ độ của qrcode sau khi quét camera -> Ta cần vẽ đa giác
2023
// Draw the barcodes area.
scanner.onFrameRead = results => {
  // Reset the width and height and empty the canvas
  canvas.width = video.videoWidth;
  canvas.height = video.videoHeight;
  let ctx = canvas.getContext('2d');
  // Set color
  ctx.fillStyle = 'rgba(254,180,32,0.3)';
  for(var result of results){
    // Get localization 
    // polygon [x,y, x,y, x,y.....];
    let x1 = result.LocalizationResult.X1;
    let x2 = result.LocalizationResult.X2;
    let x3 = result.LocalizationResult.X3;
    let x4 = result.LocalizationResult.X4;
    let y1 = result.LocalizationResult.Y1;
    let y2 = result.LocalizationResult.Y2;
    let y3 = result.LocalizationResult.Y3;
    let y4 = result.LocalizationResult.Y4;
    // Draw
    ctx.beginPath();
    ctx.moveTo(x1, y1);
    ctx.lineTo(x2, y2);
    ctx.lineTo(x3, y3);
    ctx.lineTo(x4, y4);
    ctx.fill();
  }
};
DEMO nhanh 
2023
<!DOCTYPE html>
<html>
  <body>
  
    <canvas id="canvas" width="1116" height="837" style="border:3px solid #000;">
    Your browser does not support the HTML canvas tag.</canvas>
    
    <script>
        var canvas = document.getElementById('canvas');
        var ctx = canvas.getContext('2d');
        
        // polygon [x,y, x,y, x,y.....];
        var poly = [0, 294.69374999999997, 0, 294, 256, 0, 256.33124999999995, 0] ;
        
        // copy array
        var shape = poly.slice(0);
        
        ctx.fillStyle = '#f00'
        ctx.beginPath();
        ctx.moveTo(shape.shift(), shape.shift());
        while(shape.length) {
          ctx.lineTo(shape.shift(), shape.shift());
        }
        ctx.closePath();
        ctx.fill();
        ctx.stroke();
    </script>
  
  </body>
</html>


11 February 2022

Tạo slider chỉ bằng 14 dòng CSS

Tạo slider chỉ với HTML và CSS

Html
2022
<main class="slides">
      <section class="section-1"></section>
      <section class="section-2"></section>
      <section class="section-3"></section>
</main>
CSS
2022
/* Hide the scroll bars */
body {
  overflow-y: hidden;
}

.slides {
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  display: flex;
  overflow-x: scroll;
/*   width: 500px; */
/*   height: 300px; */
}

section {
  height: 100vh;
  min-width: 100vw;
  background-repeat: no-repeat;
  background-size: cover;
  scroll-snap-align: start;
}

.section-1 {
  background-image: url("https://images.unsplash.com/photo-1478104718532-efe04cc3ff7f");
}

.section-2 {
  background-image: url("https://images.unsplash.com/photo-1472437774355-71ab6752b434");
}

.section-3 {
  background-image: url("https://images.unsplash.com/photo-1572985025058-f27aeca1b8bf");
}

27 June 2021

Form dot line CSS - SCSS

.header_bill {
  ul {
    list-style-type: none;
    padding-left0;
  }
  ul li {
    border-bottom2px dotted #ccc;
    line-height1.7em;
    text-align: right;
    clear: both;
    margin0.5em 0 0 0;
    padding-top10px;
  }

  span.definition {
    float: left;
    font-weight600;
  }

  span {
    padding0;
    border2px solid #fff;
    height20px;
    display: flex;
    justify-content: center;
  }
}


<div class="header_bill">
    <ul>
        <li>
            <span class="definition">Tờ trình nội bộ:</span>
            <span class="defined">SH987HK6KYS</span>
        </li>
        <li>
            <span class="definition">Ngày yêu cầu:</span>
            <span class="defined">27-06-2021</span>
        </li>
        <li>
            <span class="definition">Mục đích:</span>
            <span class="defined">Mua máy in</span>
        </li>
        <li>
            <span class="definition">Loại nghiệp vụ:</span>
            <span class="defined">Mua TSCĐ</span>
        </li>
        <li>
            <span class="definition">Diễn giải:</span>
            <span class="defined">Máy in canon 2021</span>
        </li>
    </ul>
</div>

Radio button ticker CSS - Custom icon

 


.checkbox-custom,
.radio-custom {
  opacity0;
  position: absolute;
}

.checkbox-custom,
.checkbox-custom-label,
.radio-custom,
.radio-custom-label {
  display: inline-block;
  vertical-align: middle;
  margin5px;
  cursor: pointer;
}

.checkbox-custom-label,
.radio-custom-label {
  position: relative;
}

.checkbox-custom + .checkbox-custom-label:before,
.radio-custom + .radio-custom-label:before {
  content"";
  background: #fff;
  border2px solid #ddd;
  display: inline-block;
  vertical-align: middle;
  width20px;
  height20px;
  padding2px;
  margin-right10px;
  text-align: center;
}

.checkbox-custom:checked + .checkbox-custom-label:before {
  content"\f00c";
  font-family"FontAwesome";
  background: rebeccapurple;
  color: #fff;
}

.radio-custom + .radio-custom-label:before {
  border-radius50%;
}

.radio-custom:checked + .radio-custom-label:before {
  content"\f00c";
  font-family"FontAwesome";
  color: #bbb;
}

.checkbox-custom:focus + .checkbox-custom-label,
.radio-custom:focus + .radio-custom-label {
  outline1px solid #ddd; /* focus style */
}



<form>
    <h3>Radio Buttons</h3>
    <div>
        <input id="radio-1" class="radio-custom" name="radio-group" type="radio" checked>
        <label for="radio-1" class="radio-custom-label">First Choice</label>
    </div>
    <div>
        <input id="radio-2" class="radio-custom"name="radio-group" type="radio">
        <label for="radio-2" class="radio-custom-label">Second Choice</label>
    </div>
    <div>
        <input id="radio-3" class="radio-custom" name="radio-group" type="radio">
        <label for="radio-3" class="radio-custom-label">Third Choice</label>
    </div>
  
    <h3>Checkboxes</h3>
    <div>
        <input id="checkbox-1" class="checkbox-custom" name="checkbox-1" type="checkbox" checked>
        <label for="checkbox-1" class="checkbox-custom-label">First Choice</label>
    </div>
    <div>
        <input id="checkbox-2" class="checkbox-custom" name="checkbox-2" type="checkbox">
        <label for="checkbox-2" class="checkbox-custom-label">Second Choice</label>
    </div>
    <div>
        <input id="checkbox-3" class="checkbox-custom" name="checkbox-3" type="checkbox">
        <label for="checkbox-3"class="checkbox-custom-label">Third Choice</label>    
    </div>
    </div>
</form>

26 June 2021

Blinking background color animation CSS

 Demo

@keyframes blink-up {
  from {
    background: #215448;
  }
  to {
    background: none;
  }
}

@keyframes blink-down {
  from {
    background: #613e45;
  }
  to {
    background: none;
  }
}

.cell-blink-up {
  color: inherit;
  text-decoration: blink;
  animation-name: blink-up;
  -webkit-animation-name: blink-up;
  animation-duration0.6s;
  -webkit-animation-duration0.6s;
  animation-iteration-count1;
  -webkit-animation-iteration-count1;
  animation-timing-function: ease-in-out;
  -webkit-animation-timing-function: ease-in-out;
  animation-direction: alternate;
  -webkit-animation-direction: alternate;
}

.cell-blink-down {
  color: inherit;
  text-decoration: blink;
  animation-name: blink-down;
  -webkit-animation-name: blink-down;
  animation-duration0.6s;
  -webkit-animation-duration0.6s;
  animation-iteration-count1;
  -webkit-animation-iteration-count1;
  animation-timing-function: ease-in-out;
  -webkit-animation-timing-function: ease-in-out;
  animation-direction: alternate;
  -webkit-animation-direction: alternate;
}

02 March 2021

Fade animation css

Fade animation css
Test mouse hover
Test mouse hover

Fade animation css
2021
@keyframes fadeCard {
  from {
    opacity: 0;
    transform: translateY(50px);
  }
  to {
    opacity: 1;
    transform: translateY(0px);
  }
}

.container {
  animation: fadeCard 1s ease forwards;
  transition: transform 0.4s ease-out;
}

12 August 2020

Cursor Grab And Grabbing CSS Drag - CSS Custom Cursors

Grab And Grabbing CSS


Example: Grab And Grabbing CSS

2020
.drag {
padding: 40px;
background: #000;
cursor: grab;
cursor: -moz-grab;
cursor: -webkit-grab;
}
.drag:active {
cursor: grabbing;
cursor: -moz-grabbing;
cursor: -webkit-grabbing;
}

CSS Custom Cursors




Icon custom:

body {
  	/*(Cursor image must be 32*32 pixles)*/
	cursor: url(CURSOR_URL), auto;
}

Class custom:

.alias {cursor: alias;}
.all-scroll {cursor: all-scroll;}
.auto {cursor: auto;}
.cell {cursor: cell;}
.context-menu {cursor: context-menu;}
.col-resize {cursor: col-resize;}
.copy {cursor: copy;}
.crosshair {cursor: crosshair;}
.default {cursor: default;}
.e-resize {cursor: e-resize;}
.ew-resize {cursor: ew-resize;}
.grab {cursor: grab;}
.grabbing {cursor: grabbing;}
.help {cursor: help;}
.move {cursor: move;}
.n-resize {cursor: n-resize;}
.ne-resize {cursor: ne-resize;}
.nesw-resize {cursor: nesw-resize;}
.ns-resize {cursor: ns-resize;}
.nw-resize {cursor: nw-resize;}
.nwse-resize {cursor: nwse-resize;}
.no-drop {cursor: no-drop;}
.none {cursor: none;}
.not-allowed {cursor: not-allowed;}
.pointer {cursor: pointer;}
.progress {cursor: progress;}
.row-resize {cursor: row-resize;}
.s-resize {cursor: s-resize;}
.se-resize {cursor: se-resize;}
.sw-resize {cursor: sw-resize;}
.text {cursor: text;}
.url {cursor: url(myBall.cur),auto;}
.w-resize {cursor: w-resize;}
.wait {cursor: wait;}
.zoom-in {cursor: zoom-in;}
.zoom-out {cursor: zoom-out;}

10 April 2020

So sánh SASS vs LESS

Biến
// Sass
$background: #000000; 
body {
    background-color: $background;
}

// LESS
@background: #00000; 
body {
    background-color: @background;
}

Mixin

// Sass
 @mixin border-radius($radius) { 
    -webkit-border-radius: $radius; 
    -moz-border-radius: $radius; 
    -ms-border-radius: $radius; 
    border-radius: $radius; } 

.box1 { 
    @include border-radius(10px); 
}

// wynik CSS
.box1 { 
    -webkit-border-radius: 10px; 
    -moz-border-radius: 10px; 
    -ms-border-radius: 10px; 
    border-radius: 10px; 
}
// LESS
.box1 { 
    color:red; 
} 

.boxClass { 
    .box1; 
}

// wynik CSS
.box1 { 
    color: red; 
} 

.boxClass { 
    color: red; 
}
Trong LESS chuyển các đối số cho cấu trúc (đặc biệt trống nếu chúng ta không muốn bất kỳ lớp nào được hiển thị):
// LESS
.class1() { 
    color:red; 
} 

.boxClass { 
    .class1(); 
}

// wynik CSS
.boxClass { 
    color: red; 
}


// LESS
.class2(@color) { 
    color:@color; 
} 

.boxClass { 
    .class2(blue); 
}

// wynik CSS
.boxClass { 
    color: blue;
}

Hàm +, -, *, /

// Sass
$base-line-height: 16px * 1.5; 

@function emCalc($size-in-pixels, $base : $base-font-size) { 
    @return $size-in-pixels / $base * 1em; 
} 

h1 { 
    font-size: emCalc(72px); 
    margin-bottom: emCalc($base-line-height, 72px); 
}

// LESS
@color: #888; 
@width: 10px; 

div { 
    border-top-color: 
    @color + #111; 
    border-right-color: @color - 100; 
    border-bottom-color: @color * 2; 
    border-left-color: @color / 2.5; 
    border-width: @width / 5; 
}

Thừa kế

// Sass
.box2 { 
    color: red; 
}

.box1 { 
    @extend .box2; 
    background: blue; 
} 

// LESS
.box2 { 
    color: red; 
}

.box1 { 
    &:extend(.box2); 
    background: blue; 
} 

Vòng lặp

// Sass
@for $i from 0 through 2 { 
    .mb-#{$i*10} { 
        margin-bottom: 10px * $i; 
    } 
} 

@for $i from 0 to 2 { 
    .mt-#{$i*10} { 
        margin-top: 10px * $i; 
    } 
}


// wynik CSS
.mb-0 { 
    margin-bottom: 0px; 
} 

.mb-10 { 
    margin-bottom: 10px; 
} 

.mt-0 { 
    margin-top: 0px; 
} 

.mt-10 { 
    margin-top: 10px; 
}
// Sass
@each $icon in facebook, gplus, twitter { 
    .icon-#{$icon} { 
        background-image: url('/img/icon/#{$icon}.png'); 
    } 
} 

$vehicles: (car, plane, bike); 
@each $icon in $vehicles { 
    .icon-#{$icon} { 
        background-image: url('/img/icon/#{$icon}.png'); 
    } 
}

// wynik CSS
.icon-facebook { 
    background-image: url("/img/icon/facebook.png"); 
} 
.icon-gplus { 
    background-image: url("/img/icon/gplus.png"); 
} 
.icon-twitter { 
    background-image: url("/img/icon/twitter.png"); 
}
.icon-car { 
    background-image: url("/img/icon/car.png"); 
}
.icon-plane { 
    background-image: url("/img/icon/plane.png"); 
}
.icon-bike { 
    background-image: url("/img/icon/bike.png"); 
}
// Sass
$i: 10; 
@while $i >= 0 { 
    .p-#{$i*10} { 
        padding: 10px * $i; 
    } 
    $i: $i - 2; 
}

// wynik CSS
.p-100 { 
    padding: 100px; 
} 
.p-80 { 
    padding: 80px; 
} 
.p-60 {
    padding: 60px; 
} 
.p-40 { 
    padding: 40px; 
} 
.p-20 { 
    padding: 20px; 
} 
.p-0 { 
    padding: 0px; 
}
LESS:
// LESS
.loop(@counter) when (@counter > 0) { 
    .loop((@counter - 1)); 
    width: (10px * @counter); 
} 

div { 
    .loop(5); 
}

// wynik CSS
div { 
    width: 10px; 
    width: 20px; 
    width: 30px; 
    width: 40px; 
    width: 50px;
}
// LESS
.generate-columns(@n, @i: 1) when (@i =< @n) { 
    .column-@{i} { 
        width: (@i * 100% / @n); 
    } 
    .generate-columns(@n, (@i + 1)); 
}

.generate-columns(4);

// wynik CSS
.column-1 {
    width: 25%; 
} 
.column-2 { 
    width: 50%; 
} 
.column-3 { 
    width: 75%; 
} 
.column-4 { 
    width: 100%; 
}

 

BACK TO TOP

Xuống cuối trang