Display another page when viewed from mobile

前端 未结 3 760
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 18:07

I have two web pages: mobile.html with mobile.css and desktop.html with desktop.css.

How can I make a redirect to the mobile one (the default page is desktop.html) if sc

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 18:36

    This is not recommended the best way is to use media queries to make your site responsive. By adding the class and detecting the browser width change.

    This text is hidden in mobile

    Now in Css put this line

    @media only screen and (max-width: 500px){
    .mobilehidden{
          display = none;
    }
    }
    

    if you want to do this then you can use JavaScript for this. You can also use php ,css but JavaScript is easier. Simply use this inside script tag

    if (screen.width <= 700) {
         document.location = "samplepage.html";
    }
    

    If you are using bootstrap there is a class for this

    .visible-xs-* 
    .visible-sm-*
    

    The mentioned above sm is for tablets whereas xs is for mobile.

提交回复
热议问题