6

Here's a screenshot of the problem.
To bottom: 1 - Chrome, 2 - Opera, 3 - Firefox, 4 - Edge.

Below I have written executable code.
For convenience, here codepen.

The basic idea: Gallery label and logo in the center position, and the rest - on the sides.
Transform will be used for animation.

Beyond measure I am grateful if you help to understand how to maintain flex in Firefox.
More precisely, I think that align-items: center is not correctly displayed in Firefox. Please help.

.gallerypage {
  margin: 0;
  padding: 0;
  background: #fff;
}

.gallerypage .header {
  position: relative;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-flow: row nowrap;
      -ms-flex-flow: row nowrap;
          flex-flow: row nowrap;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
  -webkit-align-items: center;
      -ms-flex-align: center;
          align-items: center;
  width: 100%;
  height: 100px;
  background: gray;
}

.gallerypage .header a {
  cursor: pointer;
  position: absolute;
  -webkit-flex-shrink: 0;
      -ms-flex-negative: 0;
          flex-shrink: 0;
  text-align: center;
  white-space: pre-wrap;
  text-indent: -6px;
  line-height: 30px;
  font-family: "Kaushan Script", cursive;
  font-size: 30px;
}

.gallerypage .header .sketches {
  background-color: #fff;
  width: 110px;
  -webkit-transform: translate(-400px, 0px);
      -ms-transform: translate(-400px, 0px);
          transform: translate(-400px, 0px);
}

.gallerypage .header .smth {
  background-color: #fff;
  width: 140px;
  height: 60px;
  -webkit-transform: translate(-200px, 0px);
      -ms-transform: translate(-200px, 0px);
          transform: translate(-200px, 0px);
}

.gallerypage .header .gallery {
  position: static;
  text-indent: -14px;
  line-height: normal;
  width: 185px;
  height: 90px;
  background: gold;
  font-size: 60px;
}

.gallerypage .header .logo {
  position: static;
  width: 60px;
  height: 80px;
  background: hotpink;
}

.gallerypage .header .logo .vs-logo {
  display: block;
  -webkit-flex-shrink: 0;
      -ms-flex-negative: 0;
          flex-shrink: 0;
  width: 60px;
  height: 80px;
}

.gallerypage .header .blog {
  background-color: #fff;
  width: 60px;
  height: 38px;
  -webkit-transform: translate(200px, 0px);
      -ms-transform: translate(200px, 0px);
          transform: translate(200px, 0px);
}

.gallerypage .header .about {
  white-space: pre-wrap;
  background-color: #fff;
  width: 100px;
  -webkit-transform: translate(400px, 0px);
      -ms-transform: translate(400px, 0px);
          transform: translate(400px, 0px);
}
<div class="gallerypage">
  <div class="header">
    <a class="sketches">Sketches</a>
    <a class="smth">Something serious</a>
    <a class="gallery">Gallery</a><a class="logo"></a>
    <a class="blog">Blog</a><a class="about">About it</a>
  </div>
/<div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
wokalek
  • 192
  • 2
  • 10
  • possible duplicate: [Absolutely positioned flex item not being removed from normal flow in Firefox](http://stackoverflow.com/q/32991051/3597276) – Michael Benjamin Jan 06 '17 at 16:49
  • related: [Absolute positioning in flexbox](http://stackoverflow.com/q/36191516/3597276) – Michael Benjamin Jan 06 '17 at 16:50
  • @Michael_B, no, here's another problem. – wokalek Jan 06 '17 at 17:01
  • @VostokSisters, I think it is the same problem. Because your absolutely-positioned flex items are not removed from the normal flow in Firefox, they will align differently than in other browsers, where absolute positioning works as expected. – Michael Benjamin Jan 06 '17 at 17:10
  • @Michael_B, I know about `justify-content: space-around;`, it's not what I looking for :) – wokalek Jan 06 '17 at 17:13
  • 1
    That's not what I'm talking about. *In Firefox, absolutely positioned flex items ARE NOT removed from the document flow.* This means they are still considered in-flow flex items and take up space in the container. This will result in a different layout than in Chrome and other browsers. – Michael Benjamin Jan 06 '17 at 17:15
  • @Michael_B, Yes, this is the cause. But knowing this, I still do not understand how to solve my problem ... – wokalek Jan 06 '17 at 17:16
  • @Michael_B, Can you upgrade my [codepen](http://codepen.io/VostokSisters/pen/RKPrvE?editors=1100), please? I do not know how to solve it then. – wokalek Jan 06 '17 at 17:21
  • The layout is not a problem. It's the animations that might take some time. Hopefully somebody else can help you. Otherwise, I'll come back after work and give it a shot. – Michael Benjamin Jan 06 '17 at 17:24
  • It seems that the current behavior of Chrome is against the Flexbox spec, the latest version of which says that `align/justify-items` of the flex container shouldn't affect the position of abspos children: https://bugzilla.mozilla.org/show_bug.cgi?id=874718#c29 – Ilya Streltsyn Jan 06 '17 at 18:27
  • @Michael_B, thanks a lot! I already have a few ideas thanks to you, which I hope will help solve this problem – wokalek Jan 06 '17 at 18:33
  • Wouldn't it be better to center the items with absolute positioning and `auto` margins only, without flexbox-related difficuilties, e.g. like http://codepen.io/SelenIT/pen/LxVxYP ? – Ilya Streltsyn Jan 06 '17 at 18:45
  • @VostokSisters, just to clarify, all you want to fix in your code is the vertical alignment of the 4 side items right? – Ali Abdelfattah Jan 06 '17 at 18:51
  • @AliAbdelfattah, yeah,right, just this 4 side items do not correctly displayed in Firefox... – wokalek Jan 06 '17 at 19:31
  • @IlyaStreltsyn, While there was no answer, I got almost exactly the same [solution](http://dl3.joxi.net/drive/2017/01/06/0001/0403/94611/11/c982533d97.png)! Without the use of flex. Later I will add my decision in the answers. Thank you for your reply! – wokalek Jan 06 '17 at 20:37

1 Answers1

1

Both vertical and horizontal alignment issues are resolved in Firefox. I've also applied a simple animation to make sure it's compatible with what you're trying to do (hover on header to transition the other items).

Link: http://codepen.io/anon/pen/YNXNLN

To fix the vertical center alignment on firefox, add this style (I mean merge, since you already use transform attribute):

a {
 transform: translateY(-50%);
}

But then it will be positioned at the very top on Chrome, so you'll add this style to fix it:

a {
 top: 50%;
}

Same will be done with horizontal alignment "left: 50%" and you already use translateX, so the value will be up to you.

Ali Abdelfattah
  • 348
  • 2
  • 12
  • It just works, basically ... Thanks for answer! But in post I wrote that the transform will be used in the animation. I want set by default, the elements were in the center of header. When you hover header, should be the emergence of transition animation category from the center of the header. – wokalek Jan 06 '17 at 17:32
  • But actially no, it's not what i looking for... [Link](http://dl3.joxi.net/drive/2017/01/06/0001/0403/94611/11/f77698cfb3.png) – wokalek Jan 06 '17 at 17:42
  • This is definitely what I wanted. Thank you so much! It works like on Chrome, and in Firefox. But honestly, I also [decided](http://dl3.joxi.net/drive/2017/01/06/0001/0403/94611/11/c982533d97.png) my problem, and it is without flex. :D Later I will add my decision in the answers, too. – wokalek Jan 06 '17 at 20:18
  • I agree, flexbox is very useful but it's better not to mix it with absolute positioning. – Ali Abdelfattah Jan 06 '17 at 20:20