简体   繁体   English

WordPress的div响应移动

[英]Wordpress div responsive on mobile

I customized the home template of this photography site to include 4 divs to highlight the 4 major sections of the photographer's portfolio. 我自定义了该摄影网站的首页模板,其中包括4个div,以突出摄影师作品集的4个主要部分。 They are not responsive when sizing the browser or on mobile devices. 在调整浏览器大小或在移动设备上时,它们没有响应。 What do I have to include in order to make them responsive? 我必须包含哪些内容才能使它们响应? (media queries min max, not certain) (媒体查询数量上限,不确定)

site: http://jeremy.insctest1.com 站点: http//jeremy.insctest1.com

one of the divs: div之一:

div onclick="window.location='/portfolio/architecture/architecture/';" div onclick =“ window.location ='/ portfolio / architecture / architecture /';”“ id="item1" style="width:453px; height:400px; background-image:url(' http://jeremy.insctest1.com/wp-content/uploads/2015/02/arch-home.png '); float: left; margin: 0 20px 20px 0;"> id =“ item1” style =“ width:453px; height:400px; background-image:url(' http://jeremy.insctest1.com/wp-content/uploads/2015/02/arch-home.png ') ; float:left; margin:0 20px 20px 0;“>

                div class="item-title" style="width:inherit; position: relative; top:350px; height: 50px; background-image: linear-gradient(to bottom ,rgba(232,232,232,0.8) 0%, rgba(214,214,214,0.8) 100%);">

            div class='b' style="          
height: 50px;     
width: 453px;     
display: table-cell;     
vertical-align: middle;
text-align: center;">Architecture</div>
                </a>
                </div>
            </div>

First of all you'll need to reorganize your code and add a class which will be able to do the same for all of the divs containing the images assuming that's what you want to make responsive, so you don't need to create a class for each one of these elements, then I'd recommend exchange the onclick="window.location='/portfolio/architecture/architecture/';" 首先,您需要重新组织代码并添加一个类,该类将能够对包含图像的所有div进行相同的处理,前提是您想使之响应,因此您无需创建类对于这些元素中的每一个,我建议交换onclick="window.location='/portfolio/architecture/architecture/';" for a href because you're just using this to navigate through pages so no need to onclick href is the way to do it. for a href因为您只是使用它来浏览页面,因此无需onclick href即可。 all combined should look somethin like this: 所有结合起来应该看起来像这样:

<a href="/portfolio/architecture/architecture/" id="item" class="float-right">
    <img src="http://jeremy.insctest1.com/wp-content/uploads/2015/02/arch-home.png" width="253" height="200"/>
</a>
<a href="/portfolio/architecture/architecture/" id="item" class="float-left">
    <img src="http://jeremy.insctest1.com/wp-content/uploads/2015/02/arch-home.png" width="253" height="200"/>
</a>

and then put your css on your style.css file of the theme which will look something like this: 然后将css放在主题的style.css文件中,该文件如下所示:

#item {
    width:453px;
    height:400px;
    margin: 0 20px 20px 0;
}
.float-left {float: left;}
.float-right {float: right;}
@media only screen and (max-width : 320px) {
    /* Your fix for smaller screen sizes example*/
    #item {
       width:253px;
       height:200px;
    }
    #item img {
       width:253px;
       height:200px;
    }
}

If using images as divs background is still a priority you use the code like this instead: 如果仍然将图像用作divs背景,则可以使用如下代码:

<a href="/portfolio/architecture/architecture/">
    <div id="item1" class="responsive float-left"></div>
</a>
<a href="/portfolio/architecture/architecture/">
    <div id="item2" class="responsive float-right"></div>
</a>

CSS 的CSS

#item1 {
    background-image: url('http://jeremy.insctest1.com/wp-content/uploads/2015/02/arch-home.png');
}
#item2 {
    background-image: url('http://jeremy.insctest1.com/wp-content/uploads/2015/03/portrait-home.png');
}
.responsive {
    width:453px;
    height:400px;
    margin: 0 20px 20px 0;
}
.float-left {float: left;}
.float-right {float: right;}
@media only screen and (max-width : 320px) {
    /* Your fix for smaller screen sizes example*/
    .responsive {
        width:253px;
        height:200px;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM