wullxz
wullxz

Reputation: 19540

Force max-width 100% on div and contents

I'm trying to display information for a plant right next to it and I want to force the information to stay right of the image of the plant as long as the screen has a specific min width.

Problem is: if the information contains a line that's longer than the normal width of 100% of leftover width-space in the parent div, the information div is shown below the image.

Example with good line length (no div wrap): https://jsfiddle.net/o3sjug9q/
Example with too much line length (div wrapped around): https://jsfiddle.net/seL72mt9/

How do I force the details div to wrap his text rather than wrapping itself to the next line?

<div class="outer">
<div class="slidecontainer row" id="biodivslider" data-id="1">
<div class="sliderbtn nowrap" onclick="bwdpic()">&lt;</div>
<div class="wrap">
  <div class="detailimg"><img src="http://www.nachhaltiger-weinbau.net/wp-content/plugins/biodivslider/img/Milchsterne/Dolden-Milchstern_Ornithogalum_umbellatum-Tci_2004.jpg" class="detailimg"></div>
  <div class="details">
    <p><span class="detailslabel">Name:</span><br>Milchsterne</p>
    <p><span class="detailslabel">Lateinischer Name:</span><br>(Ornithogalum spec.), O. umbellatum, O. nutans</p>
    <p><span class="detailslabel">Standort:</span><br>mäßig trocken, sandig, Wärmezeiger, mäßig stickstoffreich</p>
  </div>
</div>
<div class="sliderbtn nowrap" onclick="fwdpic()">&gt;</div>
</div>

</div>

CSS:

div.outer {
  width: 833px;
  height: 491px;
  background: lightblue;
}
div.slidecontainer {
  max-height: 300px;
}

div.row {
  display: table;
  width: 100%;
  table-layout: fixed;
  border-spacing: 10px;
  max-height: 300px;
}

div.row > div {
  float: none;
  display: table-cell;
  height: 100%;
  width: 100%;
}

div.row > div.wrap > div {
  float: left;
}
#
div.detailimg {
  height: 300px;
  width: 300px;
}

img.detailimg {
  display: block;
  max-height: 300px;
  max-width: 300px;
}

div.details {
  max-width: 100%;
  vertical-align: middle;
  word-wrap: break-word;
  overflow: visible;
}

span.detailslabel {
  font-size: smaller;
  font-weight: bold;
}

div.details > p {
  line-height: 90%;
  word-wrap: break-word;
  overflow: visible;
}

div.sliderbtn {
  font-size: 50px;
  font-weight: 900;
  min-height: 300px;
  height: 100%;
  width: 60px !important;
  line-height: 300px;
  text-decoration: none;
  vertical-align: middle;
  text-align: center;
  cursor: pointer;
}

Upvotes: 0

Views: 8157

Answers (2)

Michael
Michael

Reputation: 673

change

div.details {
max-width: 100%;
vertical-align: middle;
word-wrap: break-word;
overflow: visible;
}

to

div.details {
max-width: 50%;
vertical-align: middle;
word-wrap: break-word;
overflow: visible;
}

if you use different sizes for your images change max-width in the CSS class of your images aswell to 50%

Upvotes: 0

Johannes
Johannes

Reputation: 67799

https://jsfiddle.net/tjepuh1L/

1.) erase overflow: visible; from div.details and from div.details > p

2.) Define the max-width of div.details as calc(100% - 300px)

Upvotes: 1

Related Questions