如何使div响应屏幕分辨率?

时间:2016-09-07 07:07:08

标签: html css

只有当屏幕尺寸等于我的默认屏幕分辨率时,我的div工作正常(占据所有区域)。否则我得到这个enter image description here

如何使其响应屏幕大小调整?



ul{
		list-style: none;		
}

header{
	width: auto;
	background: url(pictures/heading-zebras-2.png) no-repeat 50% 0;
	-webkit-background-size: cover;
	background-size: cover;
	height: 450px;
}

header h1{
	float: left;
	background-color:rgba(0,0,0,0.5);
	padding: 40px 0 34px 43px;
	width: 437px;
}

.tel {
	display: inline-block;
	background-color:rgba(0,0,0,0.5);
	height: 60px;
	padding: 30px 87px 0 0;
	width: cover;
}

.tel li {
	list-style-type: none;
	display: inline;
}

.tel a{
	font: 28pt/0.64 "Consolas", Arial, Helvetica, sans-serif;
	color: white;
	padding: 0 0 0 50px;
	font-size: 87.5%;
}

<header>
<div><h1><a href="homepage.html"><img src="pictures/header-banner-text.png" alt="banner"></a></h1></div>
    <div class="tel">
		<nav>
			<ul>
			    <li><a href=".html" title="">AMERICAS</a></li>
				<li><a href=".html" title="">AFRICA</a></li>
				<li><a href=".html" title="">EUROPE</a></li>
				<li><a href=".html" title="">AUSTRALIA</a></li>
				<li><a href=".html" title="">ASIA</a></li>
			</ul>
		</nav>
	</div>
</header>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

正是您的固定h1宽度造成了这个问题。如果您正在进行响应式设计,请尝试尽可能少地使用固定值。

html,
body {
    min-height: 100%;
    height: 100%;
    width: auto;
    padding: 0;
    margin: 0;
}

ul {
   list-style: none;
}

header {
	width: 100%;
	background: url(pictures/heading-zebras-2.png) no-repeat 50% 0;
	-webkit-background-size: cover;
	background-size: cover;
	height: 450px;
	display: flex;
}

#banner-div {
	flex: 1;
	display: inline-block;
	background-color: rgba(0, 0, 0, 0.5);
}

header h1 {
	width: 100%;
	padding: 40px 0 34px 43px;
	float: left;
}

.tel {
	flex: 4;
	height: 60px;
	width: 100%;
	display: inline-block;
	padding: 30px 87px 0 0;
	background-color: rgba(0, 0, 0, 0.5);
}

.tel li {
	list-style-type: none;
	display: inline;
}

.tel a {
	font: 28pt/0.64 "Consolas", Arial, Helvetica, sans-serif;
	color: white;
	padding: 0 0 0 50px;
	font-size: 87.5%;
}
<header>
	<div id="banner-div">
    	<h1>
			<a href="homepage.html">
				<img src="pictures/header-banner-text.png" alt="banner">
			</a>
		</h1>
	</div>
	<div class="tel">
    	<nav>
        	<ul>
            	<li><a href=".html" title="">AMERICAS</a></li>
            	<li><a href=".html" title="">AFRICA</a></li>
            	<li><a href=".html" title="">EUROPE</a></li>
                <li><a href=".html" title="">AUSTRALIA</a></li>
	            <li><a href=".html" title="">ASIA</a></li>
    	    </ul>
        </nav>
	</div>
</header>

答案 1 :(得分:0)

如果我很清楚你想要实现的目标,只需采取以下措施:

  1. 你需要将float移到选择器h1中(我们希望保持我们的logo div的高度)
  2. 创建div,将导航和徽标合二为一(我给他上课.all),我们想要整个内容的背景。
  3. 最后,只从标题h1和.tel
  4. 中删除背景颜色

    ul{
    		list-style: none;		
    }
    .all {
    	background-color:rgba(0,0,0,0.5);
    }
    header{
    	width: auto;
    	background: url(pictures/heading-zebras-2.png) no-repeat 50% 0;
    	-webkit-background-size: cover;
    	background-size: cover;
    	height: 450px;
      
    }
    
    header h1{
    	padding: 40px 0 34px 43px;
    	width: 437px;
    }
    
    .tel {
    	display: inline-block;
    	height: 60px;
    	padding: 30px 87px 0 0;
    	width: cover;
    }
    
    .tel li {
    	list-style-type: none;
    	display: inline;
    }
    
    .tel a{
    	font: 28pt/0.64 "Consolas", Arial, Helvetica, sans-serif;
    	color: white;
    	padding: 0 0 0 50px;
    	font-size: 87.5%;
    }
    <header>
      <div class="all">
        <div>
          <h1>
            <a href="homepage.html"><img src="pictures/header-banner-text.png" alt="banner"></a>
          </h1>
        </div>
        <div class="tel">
            <nav>
              <ul>
                <li><a href=".html" title="">AMERICAS</a></li>
                <li><a href=".html" title="">AFRICA</a></li>
                <li><a href=".html" title="">EUROPE</a></li>
                <li><a href=".html" title="">AUSTRALIA</a></li>
                <li><a href=".html" title="">ASIA</a></li>
              </ul>
            </nav>
        </div>
      </div>
    </header>