Solved

Why this small css codes has problem on tablet?

Posted on 2016-08-28
3
137 Views
Last Modified: 2016-08-29
Hello;

I have this html and css codes,and want that  <div class="test"></div> be below of header div in middle,it is ok on desktop but in tablet in state of portrait the header div doesnot fit the screen and have horizontal scroll,please let me know that how can i fix it?
Thanks

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test-tablet</title>
<style>
body {
	margin-left: auto;
	margin-top: 0px;
	margin-right: auto;
	margin-bottom: 0px;
	padding:0px;
}
.header{
	min-height:50px;
    width: 100%;
	background-color: #bb0700;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px;
	-moz-box-sizing: border-box; 
    -webkit-box-sizing:border-box;
	box-sizing: border-box;
	}
 .test{
	height:35px;
    width: 1000px;
    background-color: red;
	padding: 0px;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px; 
		 
 }
 </style>
</head>

<body>
<div class="header">
     </div>
<div class="test">
 </div>
</body>
</html>

Open in new window

0
Comment
Question by:MOSTAGHASSI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Assisted Solution

by:Jason
Jason earned 250 total points
ID: 41774006
The width of test is causing the problem. It's too long for your tablet. I tried it on my phone and ran into the same problem.

.test{
    width: 1000px;
}

Open in new window


One way to fix it is to make the site responsive. For example: You could have a 1000px length for resolutions typically found on Desktops and something smaller (200px length) for mobile.

<style>
body {
	margin-left: auto;
	margin-top: 0px;
	margin-right: auto;
	margin-bottom: 0px;
	padding:0px;
}
.header{
	min-height:50px;
    width: 100%;
	background-color: #bb0700;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px;
	-moz-box-sizing: border-box; 
    -webkit-box-sizing:border-box;
	box-sizing: border-box;
	}

/* For Desktop PCs */
@media screen and (max-width: 3840px) {
 .test{
	height:35px;
    width: 1000px;
    background-color: red;
	padding: 0px;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px; 
		 
 }
}

/* Tablets and smartphones */
@media screen and (max-width: 800px) {
 .test{
	height:35px;
    width: 200px;
    background-color: red;
	padding: 0px;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px; 
		 
 }
}
 </style>

Open in new window

0
 
LVL 9

Accepted Solution

by:
Brian Tao earned 250 total points
ID: 41774232
Why don't just change the "width: 1000px" to "width: 80%"?
0
 

Expert Comment

by:Abdulla Nilam
ID: 41774302
Set width property responsively

 .test{
	height:35px;
width: 100%;
}

Open in new window


Check JSFiddle Preview
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question