W3.CSS مشروط
الشرط هو مربع حوار / نافذة منبثقة يتم عرضها أعلى الصفحة الحالية:
فئات W3.CSS المشروطة
يوفر W3.CSS الفئات التالية للنوافذ المشروطة:
فصل | يعرّف |
---|---|
w3- مشروط | الحاوية المشروطة |
w3- محتوى مشروط | المحتوى المشروط |
إنشاء مشروط
تحدد فئة w3-modal حاوية للشكل .
تحدد فئة المحتوى المشروط w3 المحتوى الشرطي.
يمكن أن يكون المحتوى الشرطي أي عنصر HTML (divs والعناوين والفقرات والصور وما إلى ذلك).
مثال
<!-- Trigger/Open the Modal -->
<button onclick="document.getElementById('id01').style.display='block'"
class="w3-button">Open Modal</button>
<!-- The Modal -->
<div
id="id01" class="w3-modal">
<div class="w3-modal-content">
<div
class="w3-container">
<span onclick="document.getElementById('id01').style.display='none'"
class="w3-button w3-display-topright">×</span>
<p>Some text in the Modal..</p>
<p>Some text in the Modal..</p>
</div>
</div>
</div>
افتح مشروط
استخدم أي عنصر HTML لفتح النموذج. ومع ذلك ، غالبًا ما يكون هذا زرًا أو ارتباطًا.
أضف سمة onclick وأشر إلى معرف النموذج ( id01 في مثالنا) ، باستخدام طريقة document.getElementById ().
إغلاق مشروط
لإغلاق مشروط ، أضف فئة الزر w3 إلى عنصر مع سمة onclick التي تشير إلى معرف الشرطي ( id01 ). يمكنك أيضًا إغلاقه بالنقر خارج النموذج (انظر المثال أدناه).
نصيحة: مرات؛ هو كيان HTML المفضل للرموز القريبة ، بدلاً من الحرف "x".
رأس وتذييل مشروط
استخدم فئات w3-container لإنشاء أقسام مختلفة داخل المحتوى الشرطي:
مثال
<div id="id01" class="w3-modal">
<div class="w3-modal-content">
<header class="w3-container w3-teal">
<span onclick="document.getElementById('id01').style.display='none'"
class="w3-button w3-display-topright">×</span>
<h2>Modal Header</h2>
</header>
<div
class="w3-container">
<p>Some text..</p>
<p>Some text..</p>
</div>
<footer class="w3-container
w3-teal">
<p>Modal Footer</p>
</footer>
</div>
</div>
مشروط كبطاقة
لعرض النموذج كبطاقة ، أضف إحدى فئات w3-card- * إلى حاوية محتوى w3-modal :
مثال
<div class="w3-modal-content w3-card-4">
الوسائط المتحركة
استخدم أيًا من فئات w3-animate-zoom | أعلى | أسفل | يمين | يسار للانزلاق في النموذج من اتجاه معين:
مثال
<div class="w3-modal-content w3-animate-zoom">
<div class="w3-modal-content w3-animate-top">
<div class="w3-modal-content w3-animate-bottom">
<div class="w3-modal-content w3-animate-left">
<div class="w3-modal-content w3-animate-right">
<div class="w3-modal-content w3-animate-opacity">
يمكنك أيضًا التلاشي في لون الخلفية الشرطي عن طريق تعيين فئة w3-animate-opacity على عنصر w3-modal:
مثال
<div class="w3-modal w3-animate-opacity">
صورة مشروطة
اضغط على الصورة لعرضها على شكل شكلي بالحجم الكامل:
مثال
<img src="img_snowtops.jpg" onclick="document.getElementById('modal01').style.display='block'"
class="w3-hover-opacity">
<div id="modal01" class="w3-modal w3-animate-zoom" onclick="this.style.display='none'">
<img class="w3-modal-content" src="img_snowtops.jpg">
</div>
معرض الصور المشروطة
اضغط على الصورة لعرضها بالحجم الكامل:
مثال
<div class="w3-row-padding">
<div class="w3-container w3-third">
<img src="img_snowtops.jpg" style="width:100%" onclick="onClick(this)">
</div>
<div class="w3-container w3-third">
<img
src="img_lights.jpg" style="width:100%" onclick="onClick(this)">
</div>
<div class="w3-container w3-third">
<img
src="img_mountains.jpg" style="width:100%" onclick="onClick(this)">
</div>
</div>
<div id="modal01" class="w3-modal" onclick="this.style.display='none'">
<img class="w3-modal-content" id="img01" style="width:100%">
</div>
<script>
function
onClick(element) {
document.getElementById("img01").src = element.src;
document.getElementById("modal01").style.display = "block";
}
</script>
نموذج تسجيل الدخول المشروط
ينشئ هذا المثال نموذجًا لتسجيل الدخول:
مثال
مشروط مع المحتوى المبوب
ينشئ هذا المثال نموذجًا بمحتوى مبوب:
مثال
Close the Modal
In the examples above, we use a button to close the modal. However, with a little bit of JavaScript, you can also close the modal when clicking outside of the modal box:
Example
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target
== modal) {
modal.style.display = "none";
}
}
Advanced: Lightbox (Modal Image Gallery)
This example shows how to add an image slideshow inside a modal, to create a "lightbox":
Example
Tip: To learn more about slideshows, visit our W3.CSS Slideshow chapter.