0

我知道这是一个错误且令人困惑的标题,但我对这段代码感到困惑。我基本上是一名 UI 设计师,与一位非常优秀的开发人员密切合作,不幸的是,由于一些家庭问题,我的开发人员下周左右没有时间,我有一个非常紧迫的项目要完成。我是css的新手,所以这段代码真的很乱,我真的希望并祈祷你们能帮助我。

所以这就是问题所在,我正在设计一个响应式网站,桌面版已经准备好。在较小分辨率的版本中,我面临以下问题。本节

<div class="promo_container">

<div class="promo one"><div class="content"><h3>Dashboard</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud</p></div>
</div>
<div class="promo two"><div class="content"><h3>Accounts</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud</p></div>
</div>
<div class="promo three"><div class="content"><h3>Forecast</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud</p></div>
</div>
</div>

有了这个用于桌面版的 css

.promo_container {
    max-width: 980px;
    position: relative;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    height: auto;
    padding-top: 75px;
    height: 350px;
    display: block;
}


.promo.one {
    background: url(../images/promo1.jpg);
    background-repeat: no-repeat;
    float: left;
    background-position: 0px 3px;
    width: 326px;
    display: inline-block;
}

.promo.two { background: url(../images/promo2.jpg); 
background-repeat: no-repeat;
float: left;
    background-position: 0px 3px;
    width: 326px;}

.promo.three { background: url(../images/promo3.jpg);
background-repeat: no-repeat; 
float: left;
    background-position: 0px 3px;
    width: 326px;;
}

.promo_container .promo .content {
    padding-top: 140px;
    padding-right: 50px;
    padding-bottom: 0px;
    padding-left: 0px;
    line-height: 2em;
}

工作正常,但是当我使用这个 css 作为平板电脑分辨率时

@media only screen and (min-width: 550px) and (max-width: 800px){

.promo_container {
    width: 100%;


    margin-right: auto;
    margin-left: auto;
    padding: 0px;
    height: auto;
    position:relative;
     overflow: auto;
}

.promo.one { background: url(../images/promo1.jpg);
background-repeat: no-repeat;
float: none;
    background-position: 0px 3px;
    width:200px; 
    height: 200px;
    margin-left: auto;
    margin-right: auto;

}

.promo.two { background: url(../images/promo2.jpg); 
background-repeat: no-repeat;
clear: both;
    background-position: 0px 3px;
    width: auto;
margin-top: 20px;
margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;}

.promo.three { background: url(../images/promo3.jpg);
background-repeat: no-repeat; 
float: none;
    background-position: 0px 3px;
    width: auto;
margin-top: 20px;
margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    }

.promo_container .promo .content {
    padding-top: 140px;
    padding-right: 50px;
    padding-bottom: 0px;
    padding-left: 0px;
    line-height: 2em;
}
}

结果是这些促销都堆叠在屏幕左侧虽然我希望它们位于页面的中心。(我希望可以附加图像,但我还没有在 stackoverflow 上的权限。)

现在第二个问题是,正如您所看到的,我已将 OVERFLOW 设置为自动,原因是这些促销来自下一个 div 的内容,即

<div class="testimonial">
<div class="testimonial-content"><p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.<br/><br/><b>-Lorem Consecteular</b></p></div>
</div>

使用 CSS

.testimonial {
    width: 100%;
    background-repeat: repeat-x;
    height: auto;
    background-color: #f4f4f4;


}
.testimonial .testimonial-content {
    height: auto;
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
}
.testimonial-content p {
    padding-top: 10px;
}

他们没有相同的父 div,并且溢出设置为自动,促销带有他们自己的滚动条,所以你能指出我在哪里犯了错误。正如我所说,我的朋友们我是新手,所以也许我在这里犯了几个(或者更多:() 错误,但如果有人能帮助我,我将不胜感激。

4

1 回答 1

0

关于您希望最终解决方案是什么,这里有很多假设,但我会尽我所能回答。

听起来你是第一次学习一些 CSS,所以我会快速提供一些指针,但也会很快给你答案,这听起来像是你更感兴趣的。

我在分享的代码中做了几件事。

您可以让内容决定高度,以使您的页面真正灵活。如果你必须在你的宣传片上设置一个高度,那没关系,但是 .promo_container 的高度现在可以由你的 .promo 元素的高度来决定。

您可以在您的 .promo 类上声明常见的东西,然后在每个 .promo.one、.promo.two、.promo.three 项目上声明特定的东西。

当您输入媒体查询时,您只需撤消覆盖您已经声明的属性。因此,无需再次为 .promo_container 列出完全相同的属性。(例如,margin-right:auto;和 margin-left:auto;)

关于浮点数的行为方式以及盒子模型如何响应浮点数,还有很多需要了解。如果您有兴趣,请在有更多时间时在此处阅读。http://css-tricks.com/the-css-box-model/

我看到的主要问题之一是您没有在媒体查询中的每个 .promo 项目上设置 float:none ,因此其中一些仍在尝试浮动。您在媒体查询中的 .promo 项目上使用了 clear 和 float 的混合,但它没有完成工作。

最后,根据您的需要,我会考虑将您的媒体查询更改为包含 max-width: 980px,以便您的 .promos 在浏览器达到该宽度时立即垂直堆叠。

无论如何,这应该让你开始。同样,很难说出您正在寻找什么最终结果,但希望您可以使用并从中学习。

所以,试试这个开始...

一些可以尝试的 CSS

.promo_container {
    max-width: 980px;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    height: auto;
    padding-top: 75px;
    display: block;
    overflow: hidden;
    margin-bottom: 80px;
}

.promo {
    float: left;
    width: 326px;
    background-position: 0px 3px;
}


.promo.one {
    background-repeat: no-repeat;
}

.promo.two { 
    background-position: 0px 3px;
}

.promo.three {
    background-position: 0px 3px;
}

.promo_container .promo .content {
    padding-top: 140px;
    padding-right: 50px;
    padding-bottom: 0px;
    padding-left: 0px;
    line-height: 2em;
}

/* Media query for Promos */
@media only screen and (min-width: 550px) and (max-width: 800px){

    .promo_container {
        width: 100%;
        margin-right: auto;
        margin-left: auto;
        padding: 0px;
    }

    .promo {
        float: none;
        margin: 0 auto;
        margin-bottom: 20px;
    }
}


/* Testimonies */
.testimonial {
    width: 100%;
    background-repeat: repeat-x;
    height: auto;
    background-color: #f4f4f4;
}

.testimonial .testimonial-content {
    height: auto;
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
    padding: 30px;
}

.testimonial-content p {
    padding-top: 10px;
}

祝你好运。

于 2013-02-02T05:40:31.397 回答