• January 24, 2022
    li::before {
      /* Increment "x" by 1 */
      counter-increment: x;
      content: "😶 " counter(x) ". ";

    แยก class li และ ใส่ animation

    /เลขหน้า li/
    li.tpsp::before {
    /* Increment “x” by 1 / counter-increment: x; content: /“😶”/ counter(x) /“. “/; color: black; background:gold; padding: 2px 6px 2px 5px; / border-radius:25px;*/
    /animation เปลี่ยนสีพื้น/
    animation-name: example;
    animation-duration: 4s;
    /animation เปลี่ยนสีพื้น/
    @keyframes example {
    from {background-color: red;}
    to {background-color: yellow;}
    <li class=”tpsp“> …

    Get Category name from Post ID

        display: inline-block;
        min-width: 15px;
        text-align: center;
        padding: 3px 7px;
        font-size: 12px;
        font-weight: bold;
        color: #ffffff;
        line-height: 1;
        vertical-align: baseline;
        white-space: nowrap;
        background-color: #777777;
        border-radius: 10px;
    ul > li:before {  
        background-color: red;
        margin-right: 5px;
        padding: 0 5px;
        content: counter(index, decimal);
    li:first-child {
    ul li {
        list-style: none;
    ul > li:nth-child(1):before {  
        background-color: yellow;
    ul > li:nth-child(2):before {  
        background-color: blue;
    ul > li:nth-child(3):before {  
        background-color: orange;
    ทำสี สลับ
    .link-source {
    li:nth-child(odd) .link-source {
        background: green;
    li:nth-child(even) .link-source {
        background: red;
    ทำสี ใช้สูตร
    ul.four li {background-color: silver;}
    ul.four li:nth-child(5n+1),ul.four li:nth-child(5n+3){background-color: black;}
    add :nth-child() with list when three alternative colors repeat to the list?
    ul li:nth-child(3n + 0) {
      background: #1A1A1A;
    ul li:nth-child(3n + 1) {
      background: #F7882F;
    ul li:nth-child(3n + 2) {
      background: #F7C331;
    อื่นๆ https://stackoverflow.com/questions/45365480/change-color-of-nth-child-with-css-or-jquery
    .slick-track  .slick-active:nth-child(odd){
        background: red;
    .slick-track  .slick-active:nth-child(even){
        background: green;
       $( "div li:nth-child(even)" ).css('background','green');
       $( "div li:nth-child(odd)" ).css('background','red');
    /* Selects the second <li> element in a list */
    li:nth-child(2) {
      color: lime;
    /* Selects every fourth element
       among any group of siblings */
    :nth-child(4n) {
      color: lime;
    How to make every `<li>` with different background colors?
    $('li').each(function() {
      var back = ["green","blue","gray","yellow","orange","purple","black"];
      var rand = back[Math.floor(Math.random() * back.length)];
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <!DOCTYPE html>
    <html lang="en">
    <meta charset="UTF-8">
     <div id="dvi1" class="div1">
        <ul id="ul" class="ul">
    var lastPick;
    var rand;
    $('li').each(function() {
    function randomColor() {
      var back = ["green","blue","gray","yellow","orange","purple","pink"];
      rand = back[Math.floor(Math.random() * back.length)];
      lastPick = rand;
      return rand;

    Sort of Random Background Colors

    /* ------------------- */
    /* TEMPLATE        -- */
    /* ----------------- */
    @import url(https://fonts.googleapis.com/css?family=Lato:400,700,900,300);
    @import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css);
    body { 
    	height: 100%; width: 100%; 
    	margin: 0;
    	background-color: #333; 
    	color: whitesmoke; 
    	font-size: 16px; 
    	font-family: 'Lato';
    h1 { font-size: 32px; }
    h2 { font-size: 26px; }
    h3 { font-size: 18px; }
    p { margin: 15px 0; line-height: 24px; color: gainsboro; }
    a { color: dodgerblue; text-decoration: none; border-bottom: 1px dotted; }
    a:hover { color: tomato; }
    .container { 
    	max-width: 960px; 
    	height: 100%;
    	margin: 0 auto; 
    	padding: 20px;
    .flexwrap {
    	margin-top: 40px;
    	display: flex;
    	flex-wrap: wrap;
    	align-items: stretch;
    	justify-content: center;
    /* ------------------- */
    /* PEN STYLES      -- */
    /* ----------------- */
    .rando {
    	width: 25%;
    	min-width: 200px;
    	min-height: 200px;
    .rando:nth-child(odd) { background-color: tomato; }
    .rando:nth-child(even) { background-color: mediumseagreen; }
    .rando:nth-child(3n) { background-color: darkcyan; }
    .rando:nth-child(4n) { background-color: mediumorchid; }
    .rando:nth-child(5n) { background-color: dodgerblue; }
    .rando:nth-child(6n) { background-color: darkorange; }
    .rando:nth-child(7n) { background-color: firebrick; }
    .rando:nth-child(8n) { background-color: lightseagreen; }
    /* Just highlight which one wins out */
    .rando ul li { width: 100px; padding: 5px 10px; }
    .rando ul li:last-of-type { background-color: #333; }
    /* Word List */
    ul.words { column-count: 2; list-style: none; padding-right: 0;}
    ul.words li { 
    	width: 200px; 
    	padding: 5px 10px; 
    	margin-bottom: 5px;
    	text-transform: capitalize;
    ul.words li:nth-child(odd) { background-color: tomato; }
    ul.words li:nth-child(even) { background-color: mediumseagreen; }
    ul.words li:nth-child(3n) { background-color: darkcyan; }
    ul.words li:nth-child(4n) { background-color: mediumorchid; }
    ul.words li:nth-child(5n) { background-color: dodgerblue; }
    ul.words li:nth-child(6n) { background-color: darkorange; }
    ul.words li:nth-child(7n) { background-color: firebrick; }
    ul.words li:nth-child(8n) { background-color: lightseagreen; }
    /* Word List */
    ol.list li { text-indent: 20px; }
    <div class="container">
    	<h1>Sort of Random Background Colors</h1>
    	<p>I'm using nth-child selectors to <b>sort of</b> "randomize" background colors for adjacent elements. If you have a small known number of elements, you can just assign a color individually. But this is meant to get a random effect if you don't know how many elements you'll have, or you don't want to assign colors to a large known number of elements.</p>
    	<p>I think this could be cool for like a blog theme, dynamically populate navigation, or something. It's barely any code and only uses CSS. And you could "randomize" pretty much any property.</p>
    	<p>Scroll down for the math.</p>
    	<div class="flexwrap">
    		<!-- 1 -->
    		<div class="rando">
    		<!-- 2 -->
    		<div class="rando">
    		<!-- 3 -->
    		<div class="rando">			
    				<li>every third</li>
    		<!-- 4 -->
    		<div class="rando">
    				<li>every fourth</li>
    		<!-- 5 -->
    		<div class="rando">			
    				<li>every fifth</li>
    		<!-- 6 -->
    		<div class="rando">
    				<li><s>every third</s></li>
    				<li>every sixth</li>
    		<!-- 7 -->
    		<div class="rando">			
    				<li>every seventh</li>
    		<!-- 8 -->
    		<div class="rando">
    				<li><s>every fourth</s></li>
    				<li>every eighth</li>
    		<!-- 9 -->
    		<div class="rando">			
    				<li>every third</li>
    		<!-- 10 -->
    		<div class="rando">
    				<li>every fifth</li>
    		<!-- 11 -->
    		<div class="rando">			
    		<!-- 12 -->
    		<div class="rando">
    				<li><s>every third</s></li>
    				<li><s>every fourth</s></li>
    				<li>every sixth</li>
    	<p>The mathematical intgeter sequence of the length of the pattern is the <a href="https://oeis.org/A051451">Least Common Multiple where x is a Prime Number</a>. Because after 1, only the prime numbers will have the nth-child(odd) color.</p>
    	<h3>Length of non-repeating patterns starting with 1 color</h3>
    	<ol class="list">
    	<p>As you can see, it gets pretty random pretty fast. This example has 8 colors, so I could have 2,520 items without seeing the pattern repeat.</p>
    	<p>You could certainly repeat colors in the rule, which would allow adjacent colors, and longer unrepeating patterns with fewer colors. You lose the effect, though if you assign the same color to like even and fourth, or third and sixth.</p>
    	<h2>List of 100 random words</h2>
    	<p>From <a href="http://listofrandomwords.com/">List of Random Words</a></p>
    	<ul class="words"> <li>borne</li>
    	<p>P.S. After I figured through this, I googled it and found that this isn't a new concept. But it was fun to come across it and figure it out on my own.</p>
    Random color from array with Sass


    comment สุดท้ายใช้ได้ (รอทดสอบ)
    Generate random color for every list element


ประหยัดเวลากว่า 100 เท่า!

สร้างเว็บไซต์ ดูแลเว็บไซต์