窗口调整大小时CSS样式更改

时间:2016-11-11 13:19:36

标签: html css

我不知道为什么页眉和页脚的大小会在窗口大小上发生变化。在调试/重写代码时,我发现在添加Setting(css:setting-dropdown)或Logout(css:logout-button)div时,CSS会中断。我试图修复它,但我无法弄清楚设置和注销按钮显示在标题宽度之外的原因以及为什么添加这2个div时页眉和页脚的宽度会增加。

感谢您的帮助

html { 
  background: url("backlines.png") no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

body {
    height: 850px;
}

.averios-header {
	position: absolute;
	background-image: -webkit-gradient(linear, 0% 0%, 0% 100%,color-stop(0, rgb(226, 226, 226)),color-stop(0, rgb(254, 254, 254)),color-stop(0.1, rgb(254, 254, 254)),color-stop(1, rgb(219, 219, 219)),color-stop(1, rgb(209, 209, 209)));
	left: 1px;
	top: 0px;
	margin: 0 auto;
	width: 100%;
	/*overflow: auto;*/
	box-shadow: 0px 2px;
}

div#averios-logo{
	width: 300px;
	margin-left:270px;
}

div#loginHeader {
	font-family:'Museo Slab 700';
    margin-top: 360px;
    margin-left: 276px;
    font-size: 26px;
    color: rgba(0, 173, 239, 1);
}

div#underLoginHeader {
    margin-top: 50px;
    margin-left: 278px;
    font-size: 25px;
	font-family: sans-serif;
}
.averios-footer {
    position: absolute;
    background-image: -webkit-gradient(linear, 0% 100%, 0% 0%,color-stop(0, rgb(226, 226, 226)),color-stop(0, rgb(254, 254, 254)),color-stop(0, rgb(254, 254, 254)),color-stop(0, rgb(254, 254, 254)),color-stop(0.176, rgb(254, 254, 254)),color-stop(0.904, rgb(219, 219, 219)),color-stop(1, rgb(209, 209, 209)));
    margin-top: 812px;
    width: 100%;
    height: 65px;
    margin-left: -7px;
    overflow: auto;
}
/*div#header-hr {
	position: absolute;
	background: rgba(0, 173, 239, 1);
	height: 6px;
	width: 100%;
}*/

div#footer-hr {
	position: absolute;
	background: rgba(0, 173, 239, 1);
	height: 6px;
	width: 100%;
}

div#footer-text {
    font-family: sans-serif;
    font-size: 19px;
    margin-top: 25px;
    margin-left: 280px;
	color: rgb(127,130,134);
}

div#forgot-password-link {
    margin-top: 90px;
    font-size: 23px;
    text-decoration: none;
}

a {
    color: rgb(127,130,134);
}

div#welcome-text {
    margin-left: 276px;
    font-family: 'Museo Slab 300';
    font-size: 22px;
}

div#welcome-text p {
    margin: 5px auto;
}

div#dropdown-pulse #dropbutton {
    padding: 16px;
    margin-top: 0;
    margin-right: auto;
    margin-left: 276px;
    margin-bottom: 0;
    border-radius: 50px 50px 50px 50px;
    background: rgba(0, 173, 239, 1);
    color: white;
    width: 230px;
    border: none;
    font-size: 16px;
    position: relative;
    top: 100px;
    text-align: left;
}

img#arrow {
    position: relative;
    top: 110px;
    right: 84px;
}

img#sphere {
    position: relative;
    top: 116px;
    right: 51px;
}

/* SETTING DROPDOWN */

div#setting-dropdown {
    position: absolute;
    margin-left: 1350px;
	height: 0px;
	display: inline-block;
}


div#setting-dropdown-content {
    display: none;
    background: rgba(0, 173, 239, 1);
    width: 237px;
    /* padding: 8px; */
    position: absolute;
    margin-left: -116px;
    margin-top: -22px;
    padding: 15px;
}
div#setting-dropdown p {
    font-size: 22px;
    margin-top: 44px;
    font-family: 'Museo Slab 700';
}

img#setting-blue-arrow {
    position: relative;
    margin-left: 121px;
    top: -44px;
}

div#setting-dropdown-content a {
    color: white;
    text-decoration: none;
    /* display: none; */
    font-size: 19px;
    font-family: 'Museo Slab 300';
    padding: 2px;
}

#setting-dropdown:hover #setting-dropdown-content {
	display:block;
}

/* SOMETHING NEW */

div#setting-dropdown i {
    display: inline-block;
    padding: 5px;
    padding-right: 7px;
    text-align: center;
    border-radius: 10px 10px 0 0;
    padding-bottom: 10px;
}

div#setting-dropdown:hover i {
    background-color: rgba(0, 173, 239, 1);
	color:white;
}

div#logout-button {
    position: absolute;
    margin-left: 1569px;
    margin-top: -90px;
    border-style: none;
}

button#averios-logout {
    background : rgba(255, 255, 255, 1);
    border: none;
    border-radius: 40px 40px 40px 40px;
    width: 135px;
    height: 40px;
    font-size: 19px;
    font-weight: 900;
    font-family: 'Museo Slab 700';
}
<!DOCTYPE html>
<html>
<head>
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="averios.css">
	<link rel="stylesheet" type="text/css" href="font-awesome.css">
	<link rel="stylesheet" type="text/css" href="dropdown.css">
	<link rel="stylesheet" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" />
	
<meta charset="utf-8">
</head>
<body>
<div class="averios-header">
	<div id="setting-dropdown">
		<!-- SETTING DROPDOWN WILL GO HERE -->
		<p> SETTINGS <i class="ion-chevron-down"></i></p>
		<div id="setting-dropdown-content">
			<a href="#">Change Password</a>
			<a href="#">Change Security Settings</a>
		</div>
	</div>
	<div id="averios-logo">
		<img src="averioslogo.png" width="176" height="129">
	</div>
	<div id="logout-button">
		<button id="averios-logout"> LOGOUT </button>
	</div>
</div>

<footer class="averios-footer">
<div id="footer-hr">
</div>
	<div id="footer-text">
		&copy; 2016, All Rights Reserved.
	</div>
</footer>
</body>
</html>

3 个答案:

答案 0 :(得分:1)

我检查了你的代码。有这么多问题。所以,我建议你使用bootsrap框架。你需要编写这么多的css代码,bootstrap为你做这个。

Bootstrap

答案 1 :(得分:1)

这是您的代码的一个非常简单的示例。我已经改变了你的html结构并改变了很多css。请看一下。我还添加了媒体查询以获得更好的视图。如果您有任何疑问,请在评论中提问我。为了更好地理解,您可以了解定位CSS POSITIONING以及Responsive Top Nav的基本示例。祝好运 :)

&#13;
&#13;
/*UseFull Class*/

.img-responsive {
  width: 100%;
  display: block;
  margin: 0 auto;
  height: auto;
}

li {
  list-style: none;
}

a {
  text-decoration: none;
}

body {
  margin: 0;
}


/*Main CSS  Start*/
html {
  background: red no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

/*Header Section*/

.averios-header {
  background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(0, rgb(226, 226, 226)), color-stop(0, rgb(254, 254, 254)), color-stop(0.1, rgb(254, 254, 254)), color-stop(1, rgb(219, 219, 219)), color-stop(1, rgb(209, 209, 209)));
  width: 100%;
  height: 60px;
  box-shadow: 0px 2px;
}

div#averios-logo {
  float: left;
  width: 200px;
  padding-top: 5px;
}

div.right_menu {
  float: right;
}

ul#setting-dropdown {
  display: inline-block;
  position: relative;
}

ul#setting-dropdown li a {
  font-size: 22px;
  font-family: 'Museo Slab 700';
}

div#setting-dropdown-content {
  display: none;
  position: absolute;
  background: rgba(0, 173, 239, 1);
  min-width: 237px;
  right: 0;
  top: 44px;
}

div#setting-dropdown-content a {
  padding: 12px 16px;
  text-align: left;
  color: white;
  text-decoration: none;
  display: block;
  font-size: 19px;
  font-family: 'Museo Slab 300';
}

ul#setting-dropdown:hover #setting-dropdown-content {
  display: block;
}

i.ion-chevron-down {
  display: inline-block;
  padding: 5px 7px 22px 5px;
  border-radius: 10px 10px 0 0;
}

ul#setting-dropdown:hover i {
  background-color: rgba(0, 173, 239, 1);
  color: white;
}

span#logout-button {
  border-style: none;
}

button#averios-logout {
  background: rgba(255, 255, 255, 1);
  border: none;
  border-radius: 40px 40px 40px 40px;
  width: 135px;
  height: 40px;
  font-size: 19px;
  font-weight: 900;
  font-family: 'Museo Slab 700';
}


/*Content Area*/

/*Footer Area*/

.averios-footer {
  position: absolute;
  background: -webkit-gradient(linear, 0% 100%, 0% 0%, color-stop(0, rgb(226, 226, 226)), color-stop(0, rgb(254, 254, 254)), color-stop(0, rgb(254, 254, 254)), color-stop(0, rgb(254, 254, 254)), color-stop(0.176, rgb(254, 254, 254)), color-stop(0.904, rgb(219, 219, 219)), color-stop(1, rgb(209, 209, 209)));
  bottom: 0;
  right: 0;
  left: 0;
  height: 65px;
}

div#footer-hr {
  background: rgba(0, 173, 239, 1);
  height: 6px;
  width: 100%;
}

div#footer-text {
  font-family: sans-serif;
  font-size: 19px;
  text-align: center;
  color: rgb(127, 130, 134);
}


/*Responsive Media Query*/

@media only screen and (max-width:521px) {
  div#averios-logo {
    padding-top: 10px;
    width: 150px;
  }
  ul#setting-dropdown li a {
    font-size: 16px;
  }
  div#setting-dropdown-content a {
    font-size: 14px;
  }
  button#averios-logout {
    border-radius: 25px 25px 25px 25px;
    width: 90px;
    height: 25px;
    font-size: 16px;
    font-weight: 400;
  }
}

@media only screen and (max-width:390px) {
  div#averios-logo {
    padding-top: 15px;
    width: 100px;
  }
  ul#setting-dropdown li a {
    font-size: 14px;
  }
  div#setting-dropdown-content a {
    font-size: 12px;
  }
  button#averios-logout {
    border-radius: 20px 20px 20px 20px;
    width: 70px;
    height: 20px;
    font-size: 14px;
    font-weight: 300;
  }
}
&#13;
<div class="averios-header">
  <div id="averios-logo">
    <img class="img-responsive" src="http://www.clker.com/cliparts/O/v/c/b/i/6/generic-logo-hi.png" />
  </div>
  <div class="right_menu">
    <!-- SETTING DROPDOWN WILL GO HERE -->
    <ul id="setting-dropdown">

      <li> <a href="#">SETTINGS <i class="ion-chevron-down"></i> </a></li>
      <div id="setting-dropdown-content">
        <a href="#">Change Password</a>
        <a href="#">Change Security Settings</a>
      </div>

    </ul>

    <span id="logout-button">
        <button id="averios-logout"> LOGOUT </button>
      </span>

  </div>
</div>
<!--header End-->

<footer class="averios-footer">
  <div id="footer-hr">
  </div>
  <div id="footer-text">
    &copy; 2016, All Rights Reserved.
  </div>
</footer>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

如果分辨率小于1600px,则存在太大的余量

div#logout-button {
    margin-left: 1569px;
}
div#setting-dropdown {
    margin-left: 1350px;
}

不要你想考虑用“正确:价值”来修正这些元素的位置风格参数?或使用“float:right;”两个元素?