پودمان ۳: صفحات وب تعاملی
سرصفحه فروشگاه صفحه ۱۵۶
کار کارگاهی (ادامه)
محتوای عناصر پاراگراف را بر اساس تصویر زیر تکمیل نمایید. برای نمایش کلمات بهصورت ضخیم (bold )، از تگ مناسب استفاده کنید فایل را ذخیره و نتیجه را در مرورگر بررسی کنید.
برای اصلاح نمای موبایل، کلاس w-75 را از عنصر article حذف کنید و استایل مربوط به آن را به فایل styles.css اضافه کنید:
برای دستگاههایی با پهنای کمتر از 600 پیکسل قانون زیر را در فایل styles.css اضافه کنید:
بیشتر بدانید
طراحی نوار ابزار حاوی لوگو، کادر جستوجو، گزینههای ورود | ثبت نام و سبد خرید
در این کارگاه ناحیهای مشابه تصویر زیر را در بالای نوار منو ایجاد خواهید کرد:
یک لوگو با ارتفاع 70 پیکسل ایجاد کنید و سپس فایل تصویر را با نام logo.jpg در پوشه images سایت ذخیره نمایید.
درون کادر جستوجو باید یک آیکن جستوجو ظاهر شود. برای دانلود آیکن جستوجو از سایت svgrepo.com استفاده کنید و عبارت search را در آن جستوجو کنید. آیکن دلخواه خود را توسط دکمه Edit vector در کوچکترین اندازه و رنگ دلخواه تنظیم کرده و سپس روی دکمه Export کلیک کنید. فایل آیکن را با نام search.svg در پوشه تصاویر سایت (images ) ذخیره نمایید.
صفحه ۱۵۷
بیشتر بدانید (ادامه)
تصویر صفحۀ قبل حاوی لوگو، کادر جستوجو (شامل آیکن جستوجو و کادر متنی)، گزینه ورود| ثبتنام و سبد خرید است. این عناصر را به شکل زیر به صفحه index.html قبل از عنصر nav اضافه کنید:
استایل عناصر را در نمای دسکتاپ به شکل زیر تنظیم کنید:
کلاسهای زیر را به عنصر toolbar اضافه کنید. سپس فایل را ذخیره کرده و نتیجه را در مرورگر بررسی نمایید.
صفحه ۱۵۸
بیشتر بدانید (ادامه)
با تنظیمات CSS فوق، گزینه «ورود|ثبتنام » و لوگو از نمای موبایل حذف میشود، بنابراین این گزینهها باید در جای دیگری نمایش داده شود. بهتر است این گزینهها بهصورت یک لایۀ ثابت در پایین صفحه نمایش داده شوند. بدین منظور کد زیر را قبل از </main> وارد کنید:
کلاس fixed-bottom لایه bottom-toolbar را در پایین صفحه ثابت نگه میدارد.
استایل زیر را برای عنصر bottom-toolbar بنویسید:
استایل زیر را برای نمایش صحیح نوار ابزار در نمای موبایل اضافه کنید:
با این تنظیمات عنصر bottom-toolbar بهصورت شکل زیر در پایین دستگاه موبایل ظاهر میشود.
برای فاصله گرفتن منو از toolbar ، از کلاس mt-3 در برچسب <nav> استفاده کنید.
با توجه به اینکه گزینههای ورود|ثبت نام و سبد خرید به بخش toolbar اضافه شده است، بنابراین عنصر user-actions را از منوی ناوبری (عنصر top-menu ) حذف کنید. سپس استایلهای مربوط به آن را از فایل styles.css حذف کنید. با حذف شدن ناحیه user-action نیازی به ویژگیهای فلکس در کلاس .top-menu نیست. پس ویژگیهای فلکس را هم حذف کنید. در انتها آنچه درون کلاس top-menu باقی میماند ویژگی max-width خواهد بود.
صفحه ۱۵۹
بیشتر بدانید (ادامه)
بهتر است که گزینههای منو در راستای افقی در وسط صفحه توزیع شوند، برای این کار از کلاس justify-content-center در عنصر ul استفاده کنید:
توسط کد فوق تمام ویژگیهای انتخابگر .top-menu ul با کلاسهای بوتاسترپ معادل جایگزین شد. بنابراین ویژگیهای درون انتخابگر .top-menu ul را از فایل styles.css حذف کنید.
انتظار میرود که با تنظمیات فوق نتیجه زیر حاصل شود:
سفارشیسازی کلاسهای بوت استرپ
کلاسهای بوتاسترپ دارای ویژگیها و مقادیر از پیش تعیین شدهای هستند که امکان طراحی سریع عناصر صفحه را فراهم میکنند. گاهی لازم است که عملکرد این کلاسها توسط توسعهدهندۀ صفحات تغییر نماید. این کار توسط CSS و SASS ¹ امکانپذیر است. برای تغییر استایل یک کلاس توسط CSS لازم است که ویژگی کلاس مورد نظر با مقادیر جدید تنظیم شود. در حالت پیشفرض اعمال کلاس بوتاسترپ دارای اولویت بالاتری است. بنابراین برای بالا بردن اهمیت کلاس سفارشی باید از کلمه !important در انتهای مقدار جدید استفاده شود، در غیر اینصورت مقدار جدید اعمال نمیشود.
کار کارگاهی
تغییر استایل کلاس رنگ بوتاسترپ
در این کارگاه رنگ کلاس bg-light را در فایل index.html تغییرخواهید داد. بدین منظور استایل زیر را برای کلاس bg-light به شکل زیر بنویسید:
الحاق فایل styles.css باید بعد از الحاق فایل bootstrap.min.css انجام شود، در غیر اینصورت اولویت اجرا با تنظیمات پیش فرض کلاس بوت استرپ خواهد بود. کلاس bg-light در دو عنصر کادر جستوجو و article مورد استفاده قرار گرفته است. بعد از ذخیرهسازی کد فوق بررسی کنید که آیا تغییر رنگ در این دو عنصر اعمال شده است یا خیر.
پانویس
۱ـ ابزاری است که نوشتن، سازماندهی و نگهداری کدهای CSS را در پروژههای وب سادهتر و حرفهایتر میکند.
Page 156
Workshop (continued)
Complete the content of the paragraph elements based on the image below. Use the right tag to show words in bold (bold). Save the file and check the result in the browser.
To fix the mobile view, remove the w-75 class from the article element and add its style to the file styles.css:
For devices narrower than 600 pixels, add the rule below to the file styles.css:
Learn more
Designing a toolbar with a logo, a search box, the login | sign-up option, and a shopping cart
In this workshop you will create an area like the image below above the menu bar:
Create a logo 70 pixels high and save the image as logo.jpg in the site's images folder.
A search icon must appear inside the search box. To download a search icon, go to svgrepo.com and search for search. Use the Edit vector button to set your chosen icon to the smallest size and a color you like, then click Export. Save the icon file as search.svg in the site's images folder (images).
Page 157
Learn more (continued)
The image on the previous page has a logo, a search box (with a search icon and a text box), the login | sign-up option, and a shopping cart. Add these elements to the page index.html before the nav element, as below:
Set the style of the elements in the desktop view as below:
Add the classes below to the toolbar element. Then save the file and check the result in the browser.
Page 158
Learn more (continued)
With the CSS settings above, the «Login|Sign up » option and the logo are removed from the mobile view, so these options must be shown somewhere else. It is best to show them as a fixed bar at the bottom of the page. For this, enter the code below before </main>:
The fixed-bottom class keeps the bottom-toolbar bar fixed at the bottom of the page.
Write the style below for the bottom-toolbar element:
Add the style below so the toolbar shows correctly in the mobile view:
With these settings, the bottom-toolbar element appears at the bottom of the phone screen as in the figure below.
To put some space between the menu and the toolbar, use the mt-3 class in the <nav> tag.
Since the Login|Sign up and shopping cart options have been added to the toolbar, remove the user-actions element from the navigation menu (the top-menu element). Then remove its styles from the file styles.css. With the user-action area gone, the .top-menu class no longer needs the flex properties, so remove them too. In the end, only the max-width property remains in the top-menu class.
Page 159
Learn more (continued)
It is better to spread the menu options horizontally across the middle of the page; for this, use the justify-content-center class on the ul element:
With the code above, all the properties of the selector .top-menu ul are replaced with the equivalent Bootstrap classes. So remove the properties inside the selector .top-menu ul from the file styles.css.
With the settings above you should get the result below:
Customizing Bootstrap classes
Bootstrap classes have predefined properties and values that make it quick to design page elements. Sometimes the developer needs to change how these classes behave. This can be done with CSS and SASS¹. To change the style of a class with CSS, set the class's property to the new values. By default the Bootstrap class has higher priority, so to give the custom class more weight you must put !important at the end of the new value; otherwise the new value is not applied.
Workshop
Changing the style of a Bootstrap color class
In this workshop you will change the color of the bg-light class in the file index.html. For this, write the style below for the bg-light class:
The file styles.css must be linked after the file bootstrap.min.css; otherwise the Bootstrap class's default settings take priority. The bg-light class is used in two elements, the search box and the article. After saving the code above, check whether the color has changed in these two elements.
Footnotes
A tool that makes writing, organizing, and maintaining CSS code in web projects simpler and more professional.