【问题标题】:How to make my website work on tablets?如何让我的网站在平板电脑上运行?
【发布时间】:2016-11-30 13:54:20
【问题描述】:

我终于在手机、横向和纵向上运行了我的网站,但我仍然无法在平板电脑上运行它!

我已经使用媒体查询让我的网站在手机上运行,​​这就是我所做的:

@media screen and (max-width: 1024px) {
	
	body{
		position: relative;
		left: 100px;
	}
	.pintro{
		position: relative;
		top: 180px;
		width: 500px;
	}
	.hintro{
		position: relative;
		top: 180px;
	}
	
    /* The rest of my code */
}



@media screen and (max-width: 1024px) and (max-height: 400px) {
	body{
		font-family: 'Noto Sans', sans-serif;
		background: url("nature-blur-tree-greenex.jpg") no-repeat center center fixed;
		width: 100%;	
		max-width: 900px;
		margin: 0 auto;
		position: relative;
		right: 8%;
	}
	
	.pintro{
		position: relative;
		line-height: 50px;		
		left: -100px;
	}

	/* The rest of my code */
}

然后我尝试用平板电脑这样做,形式如下:

@media only screen and (min-device-width: 768px){
	.footer{
		position: reltive;
		top: 1000px;
	}
}

但是,那没有用。如果有人向我提供媒体查询,我可以将其放入我的 CSS 中,以便我的网站在平板电脑上运行,我将不胜感激。

谢谢。

【问题讨论】:

标签: css media-queries tablet


【解决方案1】:

尝试使用这个codepen

/* Smartphones (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen 
and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@media only screen 
and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}

/* Desktops and laptops ----------- */
@media only screen 
and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@media only screen 
and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
/* iPhone 6 landscape */
@media only screen and (min-device-width: 375px)
  and (max-device-width: 667px)
  and (orientation: landscape)
  and (-webkit-min-device-pixel-ratio: 2)
{ }

/* iPhone 6 portrait */
@media only screen
  and (min-device-width: 375px)
  and (max-device-width: 667px)
  and (orientation: portrait)
  and (-webkit-min-device-pixel-ratio: 2)
{ }

/* iPhone 6 Plus landscape */
@media only screen
  and (min-device-width: 414px)
  and (max-device-width: 736px)
  and (orientation: landscape)
  and (-webkit-min-device-pixel-ratio: 3)
{ }

/* iPhone 6 Plus portrait */
@media only screen 
  and (min-device-width: 414px) 
  and (max-device-width: 736px) 
  and (orientation: portrait) 
  and (-webkit-min-device-pixel-ratio: 3)
{ }

/* iPhone 6 and 6 Plus */
@media only screen
  and (max-device-width: 640px),
  only screen and (max-device-width: 667px),
  only screen and (max-width: 480px)
{ }

/* Apple Watch */
@media
  (max-device-width: 42mm)
  and (min-device-width: 38mm)
{ }

【讨论】:

  • 谢谢!这应该会派上用场!
  • 不客气,我还没有遇到 90 个网站的问题。
猜你喜欢
  • 2014-04-07
  • 1970-01-01
  • 2012-08-31
  • 2014-02-15
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
相关资源
最近更新 更多