I have 4 page links in my nav bar. I want to resize them when using mobile browsers.
This is my JS to detect mobile: function detectmob() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
alert('This be a mobile browser');
style3(); //a function which applies other CSS changes to my page
//Trying to figure out how I'd change the width of my a elements within my nav to 100% width
}
}
CSS:
#topnav ul li a {
width: 175px; //I'd like to change this to 100% using JS based on above condition
height: 40px;
line-height: 53px;
border-bottom: 4px solid #636393;
padding:0px;
color: #fff;
font-size:18px;
font-weight:lighter;
text-align:center;
text-decoration: none;
display: block;
-webkit-transition: .1s all linear;
-moz-transition: .1s all linear;
transition: .1s all linear;
}
HTML:
<nav id="topnav">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="video.html">Trailers</a></li>
<li id='adminPage'><a href="admin.html">Admin</a></li>
</ul>
</nav>
This is what I have tried inside detectmob() if true:
navItems = document.getElementsByTagName('a');
for(var i =0; i < navItems.length;++1){
navItems[1].style.width = "100%";
}
but i got error: Uncaught ReferenceError: Invalid left-hand side expression in prefix operation