我的图片没有在我的响应式网页上调整大小

时间:2017-07-01 06:59:34

标签: html css image

我目前正在创建一个自适应网页,但是当我从手机切换到桌面时,我的背景图片并没有改变它的高度。我无法发现这个问题,并希望得到一些帮助。抱歉,我无法使用stackoverflow第一次将图像放到这里。感谢。



@media only screen and (min-width: 600px) {
    /* For tablets: */
    .col-t-1 {width: 8.33%;}
    .col-t-2 {width: 16.66%;}
    .col-t-3 {width: 25%;}
    .col-t-4 {width: 33.33%;}
    .col-t-5 {width: 41.66%;}
    .col-t-6 {width: 50%;}
    .col-t-7 {width: 58.33%;}
    .col-t-8 {width: 66.66%;}
    .col-t-9 {width: 75%;}
    .col-t-10 {width: 83.33%;}
    .col-t-11 {width: 91.66%;}
    .col-t-12 {width: 100%;}
    .backgroundimg {
        background-image: url(images/group.jpg);
        color: deepskyblue;
        text-shadow: 1.5px 1.5px 1.5px deepskyblue;
    }
}
@media only screen and (min-width: 768px) {
    /* For desktop: */
    .col-1 {width: 8.33%;}
    .col-2 {width: 16.66%;}
    .col-3 {width: 25%;}
    .col-4 {width: 33.33%;}
    .col-5 {width: 41.66%;}
    .col-6 {width: 50%;}
    .col-7 {width: 58.33%;}
    .col-8 {width: 66.66%;}
    .col-9 {width: 75%;}
    .col-10 {width: 83.33%;}
    .col-11 {width: 91.66%;}
    .col-12 {width: 100%;}
    .dimensions{
        height: 800px;
        color: deepskyblue;
        text-shadow: 1.5px 1.5px 1.5px deepskyblue;
    }

}

/* For mobile phones: */
.row::after {
    content: "";
    clear: both;
    display: table;
}
[class*="col-"] {
    float: left;
    padding: 15px;
}

.right{
    float: right;
}
.left{
    float: left;
}


body {
  margin: 0;
  padding: 0;
  
  /* make it look decent enough */
  background: #232323;
  color: #cdcdcd;
  font-family: "Avenir Next", "Avenir", sans-serif;
}

a {
  text-decoration: none;
  color: #232323;
  
  transition: color 0.3s ease;
}

a:hover {
  color: tomato;
}

#menuToggle {
  display: block;
  position: relative;
  top: 25px;
  left: 10px;
  
  z-index: 1;
  
  -webkit-user-select: none;
  user-select: none;
}

#menuToggle input{
  display: block;
  width: 50px;
  height: 42px;
  position: absolute;
  top: 5px;
  left: 5px;
  
  cursor: pointer;
  
  opacity: 0; /* hide this */
  z-index: 2; /* and place it over the hamburger */
  
  -webkit-touch-callout: none;
}

/*
 * Just a quick hamburger
 */
#menuToggle span{
  display: block;
  width: 40px;
  height: 6px;
  margin-bottom: 5px;
  position: relative;
  
  background: #cdcdcd;
  border-radius: 3px;
  
  z-index: 1;
  
  transform-origin: 4px 0px;
  
  transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
              background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
              opacity 0.55s ease;
}

#menuToggle span:first-child{
  transform-origin: 0% 0%;
}

#menuToggle span:nth-last-child(2){
  transform-origin: 0% 100%;
}

/* 
 * Transform all the slices of hamburger
 * into a crossmark.
 */
#menuToggle input:checked ~ span{
  opacity: 1;
  transform: rotate(45deg) translate(-2px, -1px);
  background: #232323;
}

/*
 * But let's hide the middle one.
 */
#menuToggle input:checked ~ span:nth-last-child(3){
  opacity: 0;
  transform: rotate(0deg) scale(0.2, 0.2);
}

/*
 * Ohyeah and the last one should go the other direction
 */
#menuToggle input:checked ~ span:nth-last-child(2){
  opacity: 1;
  transform: rotate(-45deg) translate(0, -1px);
}

/*
 * Make this absolute positioned
 * at the top left of the screen
 */
#menu{
  position: absolute;
  width: 300px;
  margin: -100px 0 0 -50px;
  padding: 50px;
  padding-top: 125px;
  height: 100vh;
  background: #ededed;
  list-style-type: none;
  -webkit-font-smoothing: antialiased;
  /* to stop flickering of text in safari */
  
  transform-origin: 0% 0%;
  transform: translate(-100%, 0);
  
  transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}

#menu li {
  padding: 10px 0;
  font-size: 22px;
}

/*
 * And let's fade it in from the left
 */
#menuToggle input:checked ~ ul{
  transform: scale(1.0, 1.0);
  opacity: 1;
}
.sans{
    font-family: 'Josefin Sans', sans-serif;
}
.slab{
    font-family: 'Josefin Slab', serif;   
}
.flower{
    font-family: 'Indie Flower', cursive;
}
.lobster{
    font-family: 'Lobster', cursive;
}
.comfortaa{
    font-family: 'Comfortaa', cursive;
}
.marker{
    font-family: 'Permanent Marker', cursive;
}
.actor{
    font-family: 'Actor', sans-serif;
}
.scada{
    font-family: 'Scada', sans-serif;
}

.container {
    width: 100%;
    height: 110px;
    background-color:darkslateblue;
}

.align {
    text-align: justify;
}

p2 {
    margin-right: 2%;
}

p {
    text-align: center;
    font-size: 180%;
    height: 200px
}

.backgroundimg {
    background-image:url(images/group.jpg);
    background-position: center;
    background-size:cover;
}
.dimensions{
    height: 300px;
    color: deepskyblue;
    text-shadow: 1.5px 1.5px 1.5px deepskyblue;
}

<!doctype html>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="script.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Actor|Comfortaa|Indie+Flower|Lobster|Permanent+Marker|Scada:700i|Josefin+Sans|Josefin+Slab" rel="stylesheet">
</head>

<body>
    <div class="container">                 
      <div id="menuToggle" class=" col-m-1">
        <input type="checkbox" />
        <span></span>
        <span></span>
        <span></span>
        <ul id="menu" class="sans">
          <a href="index.html"><li>Home</li></a>
          <a href="Itinerary.html"><li>Itenery</li></a>
          <a href="contact.html"><li>Contact</li></a>
        </ul>
        </div>
        <div class="col-m-1">
            <img src="images/nasalogo.png">
        </div>
        <div class = "col-8 col-m-8 comfortaa">
            <h1>2018 NASA Trip</h1>
        </div>
    </div>
    <div class="col-12 align marker backgroundimg dimensions">
        <p>If you had one chance would you capture it?</p>
    </div>
    <div class="col-12 align sans">
        <p2>The 2018 NASA trip aims to give students who are interested in science a once in a lifetime oppotunity, the chance to get a close look at the worlds leading space agency.The 2018 NASA trip aims to give students who are interested in science a once in a lifetime oppotunity, the chance to get a close look at the worlds leading space agency.The 2018 NASA trip aims to give students who are interested in science a once in a lifetime oppotunity, the chance to get a close look at the worlds leading space agency.The 2018 NASA trip aims to give students who are interested in science a once in a lifetime oppotunity, the chance to get a close look at the worlds leading space agency.The 2018 NASA trip aims to give students who are interested in science a once in a lifetime oppotunity, the chance to get a close look at the worlds leading space agency.The 2018 NASA trip aims to give students who are interested in science a once in a lifetime oppotunity, the chance to get a close look at the worlds leading space agency.</p2>
    </div>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:1)

Media query应位于css的末尾。

为什么它应该在最后的原因。

CSS从上到下阅读。低于其他css的所有内容都将覆盖其上的内容,即最后设置的规则,即将执行的规则。

因此,如果您的@media查询位于顶部,那么下面编写的媒体查询的css类将覆盖所有样式。

答案 1 :(得分:0)

<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 divimage "></div>

尝试添加代码中的所有类并使div标签(上面的名称为divimage)赋予其属性期望高度和宽度&amp;其他你想要像边框和所有

第二个原因可以 @media查询应该位于您编写的css属性的另一端。 在最后写这个的原因是: - css从上到下读取。所有低于其他css的东西都会覆盖它的顶部。 例子:如果您的@media查询位于顶部,则在媒体查询下面编写的CSS类将覆盖在css表中实现的所有样式

答案 2 :(得分:0)

要更改背景尺寸,请

  background-size: 768px 800px. 

虽然我更喜欢%到px。如果您想用图片覆盖背景,可以尝试

     background:url('your path') no-repeat center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
     background-size: cover;