我正在努力使我的网站完全响应。
但是我遇到了一些错误。以下是我需要处理的一些事情:
在768px视口上,我需要用颜色隐藏整个背景图像,然后使img.hide类下的单个图像显示为居中。
如果可能的话,我还需要将所有内容放在较小的视口上,以便放置一些填充物以使其看起来很好。
在smalelr视口上将文字设为白色。
这是我的HTML:
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
html, body {
height: 100%;
}
body {
font: 15px 'Lato', Helvetica, sans-serif;
color: #0f594d;
background-color: #fff;
}
header {
background-color: #34495e;
z-index: 999;
position: relative;
height: 100%;
}
header h1 {
font: 45px 'Lato', Helvetica, sans-serif;
color: #fff;
font-weight: 300;
border: 1px solid #fff;
padding: 20px 25px;
text-align: center;
position: absolute;
bottom: auto;
right: auto;
left: 30.3%;
top: 42%;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
#nav li {
margin: 0 0 15px 0;
}
#nav {
list-style: none;
position: fixed;
right: 20px;
z-index: 999999;
top: 260px;
}
.background-fixed {
background-size: cover;
position: relative;
padding: 45px 20px 0;
background-repeat: no-repeat;
background-position: center center;
}
.background-fixed h3 {
font-family: "Lato", Arial, serif;
font-size: 45px;
color: #fff;
margin-bottom: 16px;
font-weight: 300;
border: 1px solid #fff;
width: 100%;
padding: 10px 15px;
text-align: center;
}
.background-fixed p {
font-family: "Lato", Arial, serif;
font-size: 18px;
}
.background-fixed.img-1 {
background-color: #2dcc70;
}
.background-fixed.img-2 {
background-color: #e84c3d;
}
.background-fixed.img-3 {
background-color: #d25400;
}
.background-fixed.img-4 {
background-color: #9b58b5;
}
footer{
background: #172029;
padding: 15px 0;
}
footer p{
text-align: center;
color: #fff;
font-weight: 300;
}
img.hide{
display: none;
}
@media only screen and (min-width: 1048px) {
.background-fixed {
background-attachment: fixed;
}
.main-content {
width: 30%;
left: 8%;
}
}
@media only screen and (min-width: 768px) {
.background-fixed {
height: 100%;
padding: 0;
}
.background-fixed.img-1 {
background-image: url("../img/img-1.jpg");
}
.background-fixed.img-2 {
background-image: url("../img/img-2.jpg");
}
.background-fixed.img-3 {
background-image: url("../img/img-3.jpg");
}
.background-fixed.img-4 {
background-image: url("../img/img-4.jpg");
}
.main-content {
width: 38%;
position: absolute;
left: 8%;
bottom: auto;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
}
.main-content h3 {
font-size: 45px;
font-weight: 300;
}
.main-content p {
font-weight: 300;
font-size: 18px;
line-height: 1.8;
color: #fff;
}
}
@media only screen and (max-width: 480px){
img.hide{
display: block;
margin: 0 auto;
width: 50%;
}
}
.animate {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.fx {
-webkit-animation-name: tada;
animation-name: tada;
}
section#mhide {
display: none;
text-align: center;
}
@-webkit-keyframes tada {
0% {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
10%, 20% {
-webkit-transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
}
30%, 50%, 70%, 90% {
-webkit-transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
}
40%, 60%, 80% {
-webkit-transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
}
100% {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
}
@keyframes tada {
0% {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
10%, 20% {
-webkit-transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
}
30%, 50%, 70%, 90% {
-webkit-transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
}
40%, 60%, 80% {
-webkit-transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
}
100% {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
}
CSS:
{{1}}
检查我的JSFIDDLE:https://jsfiddle.net/ax0u48d6/
答案 0 :(得分:0)
正如@ 5ervant所提到的,这最好是3个问题。虽然让我解决其中一个,然后我们可以找到其他人。我先谈谈中心事物。我注意到你的标题h1左边有30.3%的左边。这是一次集中化的尝试吗?你不必把它定位:绝对,但是如果你想,这里的代码是让它一直居中。
header h1 {
font: 45px 'Lato', Helvetica, sans-serif;
color: #fff;
font-weight: 300;
border: 1px solid #fff;
padding: 20px 25px;
text-align: center;
position: absolute;
bottom: auto;
right: auto;
left: 25%;
top: 42%;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
width: 50%;
box-sizing: border-box;
}
我添加了盒子大小,宽度,并改变了你的左边。现在它总是居中。
在第一个问题中,我真的不知道你在问什么。至于你的上一个问题,你正在设置正文中的默认颜色,这就是为什么它在较小的视口上变为绿色。只需修复你的身体标签css,使文字始终为白色。
body {
font: 15px 'Lato', Helvetica, sans-serif;
color: #fff;
background-color: #fff;
}