Solved

Why this small css codes has problem on tablet?

Posted on 2016-08-28
3
73 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
3 Comments
 
LVL 7

Assisted Solution

by:Jason
Jason earned 250 total points
Comment Utility
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
Comment Utility
Why don't just change the "width: 1000px" to "width: 80%"?
0
 

Expert Comment

by:Abdulla Nilam
Comment Utility
Set width property responsively

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

Open in new window


Check JSFiddle Preview
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now