স্লাইডশো এইচ টি এম এল এবং সি এস এস এর child selector কি
CSS এর selector নিয়ে সব সময় কাজ করা হয়। বিভিন্ন ধরনের selector আছে , এসব selector দিয়ে HTML পেজের element select করা যায় এবং নিজের ইচ্ছেমত style করা যায় ।
ভাল css style করার জন্য এবং code এর complexity কমানোর জন্য child selector বিষয়টি সম্পর্কে প্রোগ্রামারকে অবশ্যই ভাল ধারণা থাকতে হবে। আমরা HTML এ একটি tag মধ্যে অন্য আরো অনেক tag ব্যবহার করে থাকি ।
যেমন : <div><p></p><h2></h2></div> .
এক্ষেত্রে css এ div এর চাইল্ড সিলেক্টর হবে p, h2 . css file এ h2 এর জন্য চাইল্ড সিলেক্টর লিখতে হবে div>h2 .
তাহলে div > h2 এর জন্য css করা হলে শুধুমাত্র h2 এর জন্যই css design apply হবে।
একই ভাবে যদি অনেক গুলো <p> tag থেকে প্রথম ও শেষ <p> tag এর design আলাদা করতে চাই তাহলে তার জন্য first-child , last-child selector use করতে হবে।
HTML ও CSS এর code নিচে দেয়া হল ।
<html> <head> <title>http://bestearnidea.com</title> <style> h1:first-child{ background-color: #ff66bb; color: whitesmoke; font-family: monospace; padding: 10px 5px; font-weight: bold; } p:last-child{ background-color: #ee44ff; color: whitesmoke; font-family: monospace; padding: 10px 5px; font-weight: bold; } h2{ font-family:Arial, Helvetica, sans-serif; color:#0b4a6a; background:#d3b677; color:red; border:#ff22ff 5px solid; padding:10px; text-align: center; } </style> </head> <body > <div> <h1> online earning site will help you how to earn money. </h1> <p> Earn money from your mobile websites. </p> </div> <div> <h2> bestearnidea.com This online earning site will help you how to earn money. </h2> </div> </body> </html> <h1><center>Slideshow Html</center></h1> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * {box-sizing: border-box;} body {font-family: Verdana, sans-serif;} .mySlides {display: none;} img {vertical-align: middle;} /* Slideshow container */ .slideshow-container { max-width: 1000px; position: relative; margin: auto; } /* Caption text */ .text { color: #f2f2f2; font-size: 15px; padding: 8px 12px; position: absolute; bottom: 8px; width: 100%; text-align: center; } /* Number text (1/3 etc) */ .numbertext { color: #f2f2f2; font-size: 12px; padding: 8px 12px; position: absolute; top: 0; } /* The dots/bullets/indicators */ .dot { height: 15px; width: 15px; margin: 0 2px; background-color: #bbb; border-radius: 50%; display: inline-block; transition: background-color 0.6s ease; } .active { background-color: #717171; } /* Fading animation */ .fade { -webkit-animation-name: fade; -webkit-animation-duration: 1.5s; animation-name: fade; animation-duration: 1.5s; } @-webkit-keyframes fade { from {opacity: .4} to {opacity: 1} } @keyframes fade { from {opacity: .4} to {opacity: 1} } /* On smaller screens, decrease text size */ @media only screen and (max-width: 300px) { .text {font-size: 11px} } </style> </head> <body> <h2>Automatic Slideshow</h2> <div class="slideshow-container"> <div class="mySlides fade"> <div class="numbertext">1 / 3</div> <img src="http://www.bestearnidea.com/wp-content/uploads/2017/06/2-FA-Password-e1512155773695.jpg" style="width:100%"> <div class="text">Bestearnidea Slideshow-1</div> </div> <div class="mySlides fade"> <div class="numbertext">2 / 3</div> <img src="http://www.bestearnidea.com/wp-content/uploads/2017/07/Easy-10-Steps-to-Search-Engine-Optimization.jpg" style="width:100%"> <div class="text">Bestearnidea Slideshow-2</div> </div> <div class="mySlides fade"> <div class="numbertext">3 / 3</div> <img src="http://www.bestearnidea.com/wp-content/uploads/2018/02/Web-Design-and-Development.jpg" style="width:100%"> <div class="text">Bestearnidea Slideshow-3</div> </div> </div> <br> <div style="text-align:center"> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> </div> <script> var slideIndex = 0; showSlides(); function showSlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } slideIndex++; if (slideIndex > slides.length) {slideIndex = 1} for (i = 0; i < dots.length; i++) { dots[i].className = dots[i].className.replace(" active", ""); } slides[slideIndex-1].style.display = "block"; dots[slideIndex-1].className += " active"; setTimeout(showSlides, 2000); // Change image every 2 seconds } </script> </body> </html>
একটা editor open করে উপরের code টুকু লিখে file মেনু থেকে Save as এ ক্লিক করে
File name: index.html দিয়ে save করে index.html ফাইলটি browser দিয়ে open করলে output এর ছবির মত দেখাবে।
পরবর্তী tutorial এ আরও child selector নিয়ে কাজ দেখানো হবে।
সাথে এইচ টি এম এল স্লাইডশো কোড দিয়ে দিলাম
ধন্যবাদ।