简体   繁体   English

如何将div放在响应式旋转div之上?

[英]How to place div on top of responsive rotated div?

I'm trying to get this design: 我正试图让这个设计: 网站设计

but I'm having trouble with the logo and the swirls, I don't know how to add them. 但是我遇到了徽标和漩涡的问题,我不知道如何添加它们。 I've tried with absolute positioning, but when resizing the website, the logo and swirls end up somewhere different than the image squares. 我尝试过绝对定位,但在调整网站大小时,徽标和漩涡最终会出现与图像正方形不同的地方。

How can I add the swirls and the logo? 如何添加漩涡和徽标?

JSFiddle: http://jsfiddle.net/uHsJv/1/ JSFiddle: http //jsfiddle.net/uHsJv/1/
When you want to edit the JS fiddle, in the images folder on my website you can find the following images: 当你想编辑JS小提琴时,在我网站上的images文件夹中你可以找到以下图像:
- the logo (images/logo.png or images/logogroot.png) - 徽标(images / logo.png或images / logogroot.png)
- the two swirls on the top including logo (images/boven.png) - 顶部的两个漩涡,包括logo(images / boven.png)
- the two swirls on the bottom (images/onder.png) - 底部的两个漩涡(images / onder.png)
- the complete 'background' (images/achtergrond.png) - 完整的'背景'(images / achtergrond.png)

Current HTML: 目前的HTML:

<div class="outer"><div class="middle"><div class="wrap"> <!-- Open .wrap -->

    <div class="box side left"><!-- Open .box -->
        <a href="#" class="boxInner innerLeft"><!-- Open .boxInner -->
            <div class="overlay hover"></div>
        </a><!-- Close .boxInner -->
    </div><!-- Close .box -->


    <div class="boxWrap"> <!-- Open .boxWrap -->
      <div class="leftUp"><!-- Open .box -->
        <a href="#" class="boxInner innerLeftUp"><!-- Open .boxInner -->
            <div class="overlay blue"></div>
        </a><!-- Close .boxInner -->
      </div><!-- Close .box -->
      <div class="leftDown"><!-- Open .box -->
        <a href="#" class="boxInner innerLeftDown"><!-- Open .boxInner -->
            <div class="overlay blue"></div>
        </a><!-- Close .boxInner -->
      </div><!-- Close .box -->
    </div> <!-- Close .boxWrap -->

    <div class="box"><!-- Open .box -->
        <a class="boxInner innerMiddle"><!-- Open .boxInner -->
        <div class="overlay white"></div>
        </a><!-- Close .boxInner -->
    </div><!-- Close .box -->

    <div class="boxWrap"> <!-- Open .boxWrap -->
      <div class="rightUp"><!-- Open .box -->
        <a href="#" class="boxInner innerRightUp"><!-- Open .boxInner -->
            <div class="overlay blue"></div>
        </a><!-- Close .boxInner -->
      </div><!-- Close .box -->
      <div class="rightDown"><!-- Open .box -->
        <a href="#" class="boxInner innerRightDown"><!-- Open .boxInner -->
            <div class="overlay blue"></div>
        </a><!-- Close .boxInner -->
      </div><!-- Close .box -->
    </div> <!-- Close .boxWrap -->

    <div class="box side right"><!-- Open .box -->
        <a href="#" class="boxInner innerRight"><!-- Open .boxInner -->
            <div class="overlay hover"></div>
        </a><!-- Close .boxInner -->
    </div><!-- Close .box -->

</div></div></div><!-- Close .wrap -->

Current CSS: 目前的CSS:

body {
    margin: 0;
    padding: 0;
    background-color:#1b1b1b;
}

.outer{
    display: table;
    position: absolute;
    height: 100%;
    width: 100%;
}
.middle{
    display: table-cell;
    vertical-align: middle;
}
.wrap {
    margin-left: auto;
    margin-right: auto; 
    height:100%;
    overflow: hidden;

    -webkit-box-align:center;
    -webkit-box-pack:center;
    display:-webkit-box;    
}

.box {
    float: left;
    position: relative;
    width: 24.45%;
    padding-bottom: 24.45%;

    margin:auto;

    top: 0; left: 0; bottom: 0; right: 0;
    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    -o-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
}

.side {
    width: 17.57%;
    padding-bottom: 17.57%;
}

.left{
    left:3%;
}

.right{
    left:-3%;
}

.boxWrap{
    float: left;
    position: relative;
    width: 11.49%;

    margin:auto;
    padding:0;

    top: 0; left: 0; bottom: 0; right: 0;
}

.leftUp, .leftDown, .rightUp, .rightDown{
    width: 100%;
    padding-bottom:100%;
    position:relative;

    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    -o-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
}

.leftUp, .leftDown{
    margin-left:7%;
}

.rightUp, .rightDown{
    margin-left:-7%;
}

.leftDown, .rightDown{
    margin-top:38%;
}

.boxInner {
    position: absolute;
    left: 10px;
    right: 10px;
    top: 10px;
    bottom: 10px;
    overflow: hidden;

    margin:0;
    padding:0;

    background-size:cover;
    background-repeat: no-repeat;
}

.innerLeft{
    background-image:url('../images/home_links.png');
}
.innerMiddle{
    background-image:url('../images/home_midden.png');
}
.innerRight{
    background-image:url('../images/home_rechts.png');
}

.innerLeftUp{
    background-image:url('../images/home_linksB.png');
}
.innerLeftDown{
    background-image:url('../images/home_linksO.png');
}
.innerRightUp{
    background-image:url('../images/home_rechtsB.png');
}
.innerRightDown{
    background-image:url('../images/home_rechtsO.png');
}

.overlay{
    height:100%;
    z-index:2;
    overflow:hidden;
    margin:0;
    padding:0;
}

.blue{
    background: rgba(0,101,147,0.40);
}

.blue:hover{
    background: rgba(185,185,185,0.40);
}

.hover:hover{
    background: rgba(245,245,245,0.40);
}

.blue:active, .hover:active{
    background: rgba(178,46,47,0.40);
}

I placed the decorative images inside the center .box element and straightened them by giving them the opposite rotation to their parent, ie rotate:-45deg. 我将装饰图像放在中心.box元素中,并通过向它们的父级提供相反的旋转来拉直它们,即旋转:-45deg。

The main problem with this approach is that elements rotate about their centre and the location of the centre depends on the element's width. 这种方法的主要问题是元素围绕其中心旋转,中心的位置取决于元素的宽度。 In responsive designs, this means that the location of the centre depends on the page width ie it can move. 在响应式设计中,这意味着中心的位置取决于页面宽度,即它可以移动。

To counter this, I placed 2 wrapper elements around the image. 为了解决这个问题,我在图像周围放置了两个包装元素。 The outer wrapper (.straight) is given a width of 1%. 外包装(.straight)的宽度为1%。 This makes it narrow enough that slight changes in its width don't noticeably affect the positioning of its contents. 这使得它足够窄,宽度的微小变化不会显着影响其内容的定位。 This outer wrapper is then rotated by -45deg. 然后将该外包装旋转-45度。

The inner wrapper (.straight div) has a width of 10,000%. 内包装(.straight div)的宽度为10,000%。 This gives the inner wrapper a width equal to the width of the .box element (1% x 10000% = 100%). 这使内包装的宽度等于.box元素的宽度(1%x 10000%= 100%)。 The decorative image can then be placed in this image wrapper and sized, positioned etc... as normal. 然后可以将装饰图像放置在该图像包装中并且正常地定尺寸,定位等。

I did this twice, once for the top image and once for the bottom image. 我做了两次,一次用于顶部图像,一次用于底部图像。 The css for the top image is here, the bottom image was positioned similarly: 顶部图像的CSS位于此处,底部图像的位置相似:

.straight{
  color:white;
  position:absolute;
  width:1%;
  height:1%;
  -webkit-transform: rotate(-45deg);
    -moz-transform: rotate(-45deg);
    -o-transform: rotate(-45deg);
    -ms-transform: rotate(-45deg);
    transform: rotate(-45deg);
    text-align:center;
}
.straight.top div{
  width:10000%;
  left:-5000%;
  top:-2000%;
  position:relative;
}

http://jsfiddle.net/John_C/8kFkR/ http://jsfiddle.net/John_C/8kFkR/

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

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