0

I have a body consisting of 2 navigation bars(top), top-graphic(middle) flexbox and a content flexbox(bottom).

Within the top-graphic flexbox I want to insert a black box in which I can put text. When I make this box, it doesnt overflow the top of the parent box, however it overflows the bottom and the right side of the parent, continueing into my content box when I resize the page. I want my box to stay inside the boundaries of its parent element and take my parent into respect when I set my width/height, so that it doesnt overlap the content flexbox when I resize the website.

.nav {
  display: flex;
  flex: 1;
  background-color: white;
  flex-direction: column;
}
.topnav {
  flex: 1;
  background-color: white;
  border-bottom: ridge 1px;
}
.bottomnav {
  flex: 1;
  background-color: white;
}
.topgraphic {
  overflow: hidden;
  position: relative;
  flex: 2;
  background-color: lightblue;
  z-index: -2;
}
.topgraphic img {
  background-size: cover;
  background-repeat: no-repeat;
  position: absolute;
  width: 100%;
  height: 100%;
  -moz-box-shadow: inset 0px 12px 15px -12px #696868;
  -webkit-box-shadow: inset 0px 12px 15px -12px #696868;
  box-shadow: inset 0px 12px 15px -12px #696868;
  z-index: -1;
}
.topgraphic .textbox {
  box-sizing: inherit;
  position: absolute;
  margin-right: 5%;
  margin-bottom: 10%;
  width: 30%;
  height: 80%;
  background-color: rgba(0, 0, 0, 0.6);
}
.content {
  z-index: -5;
  flex: 7;
  background-color: white;
  min-height: 25%;
}
<div class="nav">
    <div class="topnav"></div>
    <div class="bottomnav"></div>
</div>
<div class="topgraphic">
    <img alt="TopGraphic" class="auto-style1" src="Images/Topgraphic.jpg" />
    <asp:Image ID="Image1" runat="server" />
    <div class="textbox">
        <!-- <div class="topText">
        <h1>Demonstration</h1>
        </div> -->
    </div>
</div>
Ash
  • 2,108
  • 2
  • 17
  • 22
  • A demo of the actual probelm would be useful..however, I'm not seeing the poing of using absolute positioning with flexbox...but perhaps I'm missing something. – Paulie_D Nov 20 '15 at 10:18
  • uhm, i can give you an example of what im trying to achieve. www.elbek-vejrup.dk on this page you can see that there is an image on the top, in which there is a blue textbox with a transparency. this is exactly what im trying to achieve give me a moment, i can try to paste my code into a jsfiddle –  Nov 20 '15 at 10:22
  • https://jsfiddle.net/5rkx5u93/ –  Nov 20 '15 at 10:32
  • Pasting the code into the fiddle doesn't really help without an actual image and ASP is of no use.. It's not really clear what you are trying to do. – Paulie_D Nov 20 '15 at 10:34
  • As I mentioned before though, applying `position:absolute` will make `flex` **not work** – Paulie_D Nov 20 '15 at 10:38
  • http://imageshack.dk//viewimage.php?file=/imagesfree/OS615945.png I guess this demonstrates the problem, as you can see my margin exceeds its parent box. –  Nov 20 '15 at 10:39
  • You need to make a working demo for us to be able to help. And one direct thing is that your `.topgraphic` rule need `display: flex` for its `flex: 2` to work. – Asons Nov 20 '15 at 10:40
  • ...and remove all the positioning... – Paulie_D Nov 20 '15 at 10:40
  • @Paulie_D A general statement saying _`position: absolute` doesn't work with `flex`_ is not quite true. – Asons Nov 20 '15 at 10:46
  • Close enough...though if you add postion absolute to a flexbox it loses it's *flexiness*. – Paulie_D Nov 20 '15 at 10:50
  • so does that mean i will have to say display:flex for each of my elements even though my wrapper that sits on the body has the display:flex paramemter? If i remove position:absolute from my wrapper, everything collapses. . –  Nov 20 '15 at 10:50
  • First, we don't know your body wrapper has `display: flex` as that is not in your sample, second, add a working demo so we can help out ... surely you understand that now, and grabbing some working code generated in your browser should be quite simple to do. – Asons Nov 20 '15 at 11:19
  • https://jsfiddle.net/9gjhr9xL/1/ this is the entire masterpage i have so far. By working demo im not quite sure what you imply. –  Nov 20 '15 at 11:30
  • @Paulie_D If you check this answer you'll see what I mean: http://stackoverflow.com/a/33119202/2827823 – Asons Nov 20 '15 at 11:54
  • Try using width:auto – Ajay Makwana Nov 20 '15 at 12:19

1 Answers1

0

As it's a little bit difficult to really understand what your a looking for, I here made a guess based on your existing code.

Is this an overall layout you are looking for?

* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  color: gray;
  padding: 1%;
}
.outer {
  display: flex;
  flex-flow: column;
  height: 98%;
  width: 90%;
  margin: 0 auto;
  box-shadow: 0px 0px 10px 0px #696868;
}
.top { 
  display: flex;
  flex-flow: column;
  background-color: white;
}
.middle { 
  background-color: lightblue;
  background-image: url(http://lorempixel.com/400/100/sports/9/);
  background-size: cover;
  background-repeat: no-repeat;
  clear: right;
}
  .middle .textbox {
     float: right;
     width: 30%;
     height: 70px;
     background-color: rgba(0,0,0,0.7);
  }
.content {
  position: relative;
  flex: 1 0 auto;
  height: 0;
}
.content-inner {
  background-color: white;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
}
<div class="outer">
  <div class="top">
    <div class="top">top top</div>
    <div class="bottom">top bottom</div>
  </div>
  <div class="middle">
      <div class="textbox">
          text box
      </div>
    </div>
  <div class="content">
    <div class="content-inner">content</div>
  </div>
</div>
Asons
  • 84,923
  • 12
  • 110
  • 165
  • Yes somewhat, now the margin in the topgraphic box doesnt overflow. But what happens if i insert a picture in the top graphic and want to make this black box float on top of the picture with a right parameter? –  Nov 20 '15 at 13:21
  • @JeppeC Updated my answer, better now? – Asons Nov 20 '15 at 13:36