I have a website running on desktop very well.
But when I resize it to mobile resolution it going crazy. And I want to make another new html file(it's whole different design) and make it for only specific resulotions.
But I have stuck with the question how do i do that?.
I make research and found some answers to help me but couldn't figure it out.
I tried hiding the body when they run website on mobile with
@media only screen
and (max-device-width : 667px)
and (orientation : portrait)
and (-webkit-min-device-pixel-ratio : 2)
{
#body-mobile{
display: inline-block;
}
#body-pc{
display: none;
}
}
but there is a mistake that i cant create 2 bodies on same html. So is there any way to make another html or any another way to do it?
CodePudding user response:
You can do it like this:
.desktop_container {
display: block;
}
.mobile_container {
display: none;
}
@media only screen and (max-width: 667px) {
.desktop_container {
display: none;
}
.mobile_container {
display: block;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="styles.css" />
<script type="module" src="script.js"></script>
</head>
<body>
<div >
<div>Desktop</div>
<!-- PUT ALL DESKTOP CONTENT HERE -->
</div>
<div >
<div>Mobile</div>
<!-- PUT ALL MOBILE CONTENT HERE -->
</div>
</body>
</html>
CodePudding user response:
Instead of having two <body>
, you can have <body><div id="body-mobile"></div><div id="body-pc"></div>
.
Usually all you want to check is max-width
:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="body-mobile">...</div>
<div id="body-pc">...</div>
</body>
</html>
I would suggest using e.g. Bootstrap CSS framework for easier responsive integration:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
</head>
<body>
<div >...</div>
<div >...</div>
</body>
</html>