Summer IT - Haii kali ini saya akan membagikan cara membuat menu website responsive, anda tau kan apa itu responsive web design ? oke coba anda baca kutipan dibawah ini.
Mengutip dari situs smashingmagazine.com, Responsive Web Design adalah sebuah pendekatan yang menunjukkan bahwa desain dan pengembangan harus menanggapi perilaku dan lingkungan pengguna berdasarkan pada ukuran, platform dan orientasi layar. Praktik ini meliputi penggunan perpaduan grid fleksibel dan layout, gambar dan CSS media query. Sebagaimana pengguna saat ini yang beralih dari laptop ke tablet, website secara otomatis harus menyesuaikan resolusi, ukuran gambar dan kemampuan scriptingnya. Dengan kata lain, website harus memiliki teknologi untuk secara otomatis merespon preferensi pengguna yang didasarkan pada resolusi layar gadget yang digunakan (komputer pc, laptop, netbook,tablet, smart phone dan mobile phone).anda sudah mengerti, dari kutipan di atas ?
kalau sudah langsung saja ke tutotial pembuatan menu website responsive.
Jika anda buka dengan PC/Laptop akan tampak seperti ini.
Tampilan versi Desktop |
Dan jika anda buka dengan perangkat mobile, akan tampak seperti ini.
Tampilan versi Mobile |
1. Membuat Menu
Buka aplikasi editor yang anda biasa gunakan.
Lalu ketikan code seperti dibawah ini.
<link href="style.css" type="text/css" rel="stylesheet"/>
<nav class="clearfix">
<ul class="clearfix">
<li><a href="#">Home</a></li>
<li><a href="#">Website</a></li>
<li><a href="#">Forum</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
<nav class="clearfix">
<ul class="clearfix">
<li><a href="#">Home</a></li>
<li><a href="#">Website</a></li>
<li><a href="#">Forum</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
Lalu beri nama index.html
2. Membuat Style Untuk Menu
Buat file CSS dengan nama style.css, kemudian ketikan code seperti dibawah ini.
body {
background-color: #ece8e5;
}
nav {
height: 50px;
width: 100%;
background: #455868;
font-size: 11pt;
font-family: 'PT Sans', Arial, sans-serif;
font-weight: bold;
position: relative;
border-bottom: 2px solid #283744;
}
nav ul {
padding: 0;
margin: 0 auto;
width: 600px;
height: 50px;
}
nav li {
display: inline;
float: left;
}
.clearfix:before,
.clearfix:after {
content: " ";
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
nav a {
color: #fff;
display: inline-block;
width: 100px;
text-align: center;
text-decoration: none;
line-height: 40px;
text-shadow: 0px #283744;
}
nav li a {
border-right: 1px solid #576979;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
nav li:last-child a {
border-right: 0;
}
nav a:hover, nav a:active {
background-color: #8c99a4;
}
background-color: #ece8e5;
}
nav {
height: 50px;
width: 100%;
background: #455868;
font-size: 11pt;
font-family: 'PT Sans', Arial, sans-serif;
font-weight: bold;
position: relative;
border-bottom: 2px solid #283744;
}
nav ul {
padding: 0;
margin: 0 auto;
width: 600px;
height: 50px;
}
nav li {
display: inline;
float: left;
}
.clearfix:before,
.clearfix:after {
content: " ";
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
nav a {
color: #fff;
display: inline-block;
width: 100px;
text-align: center;
text-decoration: none;
line-height: 40px;
text-shadow: 0px #283744;
}
nav li a {
border-right: 1px solid #576979;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
nav li:last-child a {
border-right: 0;
}
nav a:hover, nav a:active {
background-color: #8c99a4;
}
3. Membuat menu responsive dengan css
pertama – tama, tambahkan dulu meta vieport di dalam file index.html
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
kemudian untuk membuat menunya responsive pada layar gadget yang berukuran lebih kecil dari 600px maka ketikkan code berikut dalam file style.css :
@media screen and (max-width: 500px) {
nav {
height: auto;
}
nav ul {
width: auto;
display: block;
height: auto;
}
nav li {
width: 100%;
float: left;
position: relative;
}
nav li a {
border-bottom: 1px solid #576979;
border-right: 1px solid #576979;
}
nav a {
text-align: left;
width: 100%;
text-indent: 25px;
}
}
nav {
height: auto;
}
nav ul {
width: auto;
display: block;
height: auto;
}
nav li {
width: 100%;
float: left;
position: relative;
}
nav li a {
border-bottom: 1px solid #576979;
border-right: 1px solid #576979;
}
nav a {
text-align: left;
width: 100%;
text-indent: 25px;
}
}
pada syntak di atas, kita bisa lihat bahwa CSS memeriksa kondisi layar browser, kemudian jika layar browser itu lebih kecil dari 500px, maka lebar menu akan di bagi menjadi dua, 50% – 50%.
sekarang untuk membuat menu responsive pada ukuran layar di bawah 480px atau dengan kata lain ketika web di buka dengan SmartPhone ukuran sekitar 4,5Inch, tambahkan syntak berikut pada style.css
nav a#pull {
display: none;
}
@media only screen and (max-width : 480px) {
nav {
border-bottom: 0;
border-bottom: 2px solid #283744;
}
nav ul {
display: none;
height: auto;
}
nav a#pull {
color: #fff;
display: inline-block;
width: 100px;
padding-top:5px;
padding-right:40px;
position: right;
}
nav a#pull:after {
content:"";
width: 10px;
height: 10px;
position: right;
top: 50px;
}
}
display: none;
}
@media only screen and (max-width : 480px) {
nav {
border-bottom: 0;
border-bottom: 2px solid #283744;
}
nav ul {
display: none;
height: auto;
}
nav a#pull {
color: #fff;
display: inline-block;
width: 100px;
padding-top:5px;
padding-right:40px;
position: right;
}
nav a#pull:after {
content:"";
width: 10px;
height: 10px;
position: right;
top: 50px;
}
}
kemudian tambahkan code berikut dalam tag <nav> di file index.php
<a href="#" id="pull">Menu</a>
sekarang buka lagi index.php dan tambahkan code berikut
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(function() {
var pull = $('#pull');
menu = $('nav ul');
menuHeight = menu.height();
$(pull).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
});
$(window).resize(function() {
var w = $(window).width();
if (w > 320 && menu.is(':hidden')) {
menu.removeAttr('style');
}
});
});
</script>
<script>
$(function() {
var pull = $('#pull');
menu = $('nav ul');
menuHeight = menu.height();
$(pull).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
});
$(window).resize(function() {
var w = $(window).width();
if (w > 320 && menu.is(':hidden')) {
menu.removeAttr('style');
}
});
});
</script>
oke, sekian tutorial dari saya hari ini, jika ada hal yang mau di tanyakan silahkan di comment saja ya.
Referensi : CariCode.com
19 komentar
Click here for komentarMas kenapa ya yang saya itu kalo di liat versi mobile nya ga ada garis-garis buat buka menu nya gtu ? kaya ga ada toggle navigation padahal di script udah ditulis.. mohon penjelasannya
ReplyYour good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDevops Training in pune
Devops Training in Chennai
Devops Training in Bangalore
AWS Training in chennai
AWS Training in bangalore
Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays.
Replypython training in Bangalore
python training in pune
python online training
python training in chennai
Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
ReplyBlueprism training in velachery
Blueprism training in marathahalli
Blueprism training in btm
This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot.
ReplyData Science course in rajaji nagar | Data Science with Python course in chenni
Data Science course in electronic city | Data Science course in USA
Data science course in pune | Data science course in kalyan nagar
Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.
Replyangularjs Training in btm
angularjs Training in electronic-city
angularjs online Training
angularjs Training in marathahalli
angularjs interview questions and answers
Thanks for making this guide and you have given such a clear breakdown of technology updates. I've seen so many articles, but definitely, this has been the best I?ve read!
ReplySelenium Training in Chennai
Best Selenium Training Institute in Chennai
ios developer training in chennai
.Net coaching centre in chennai
French Classes in Chennai
Big Data Training in Chennai
Best JAVA Training in Chennai
Android Training Institute in Chennai
Best Android Training in Chennai
Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
ReplyMicrosoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training
Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
ReplyJava Training in Chennai | Best Java Training in Chennai
C C++ Training in Chennai | Best C C++ Training in Chennai
Data science Course Training in Chennai | Data Science Training in Chennai
RPA Course Training in Chennai | RPA Training in Chennai
AWS Course Training in Chennai | AWS Training in Chennai
Devops Course Training in Chennai | Best Devops Training in Chennai
Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
ReplyIf you are looking for any Data science Related information please visit our website best course for data science page!
ReplyThe strategy you have posted on this technology helped me to get into the next level and had lot of information in it. The angular js programming language is very popular which are most widely used.
Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
Great post.Thanks for one marvelous posting! I enjoyed reading it;The information was very useful.
Replyjava training in chennai
java training in tambaram
aws training in chennai
aws training in tambaram
python training in chennai
python training in tambaram
selenium training in chennai
selenium training in tambaram
Wow, amazing weblog format! How lengthy have you been running a blog for? you make running a blog look easy. The total glance of your website is wonderful, let alone the content!
Replyangular js training in chennai
angular js training in velachery
full stack training in chennai
full stack training in velachery
php training in chennai
php training in velachery
photoshop training in chennai
photoshop training in velachery
oracle training in chennai
Replyoracle training in omr
oracle dba training in chennai
oracle dba training in omr
ccna training in chennai
ccna training in omr
seo training in chennai
seo training in omr
I am really happy to found such a helpful and fascinating post that is written in well manner. Thanks for sharing such an informative post. keep update your blog.
Replydata science training in chennai
data science training in annanagar
android training in chennai
android training in annanagar
devops training in chennai
devops training in annanagar
artificial intelligence training in chennai
artificial intelligence training in annanagar
First i got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks,
Replydata science training in chennai
data science training in porur
android training in chennai
android training in porur
devops training in chennai
devops training in porur
artificial intelligence training in chennai
artificial intelligence training in porur
Home lifts India | Domestic lifts |Home lifts Malaysia |Home lifts | Vacuum lifts
ReplyBrilliant post! We are connecting to this extraordinary post on our site. Keep up the extraordinary composition.
Replytech news
Great post. keep sharing such a worthy information.
ReplyBlue Prism Training in Chennai
Blue Prism Online Training
ConversionConversion EmoticonEmoticon