2

I have problems with divs. I would like the link "Go" to be right aligned and vertically middle of its parent div. I have tried several ways, but no success yet.

And here you can see my HTML and CSS code:

div.row {
  position: relative;
  border-bottom: 1px dotted #999999;
}
div.list div.name {
  float: left;
  width: 40%;
}
div.list div.info {
  float: left;
  width: 60%;
}
div.list div.action {
  display: inline-block;
  text-align: right;
  vertical-align: middle;
}
<div class="list">
  <div class="row">
    <div class="name">
      <span>1</span>
      <br />
      <a href="1.php">1</a>
      <br />(2015-09-30)
    </div>

    <div class="info">
      <b>Place:</b>
      <br />Now 6
      <br />Later 32

      <div class="action">
        <a href="1go.php">Go</a>
      </div>
    </div>
  </div>
</div>

So, if you have better ideas and know how I could solve my problem, I would love to hear.

If possible, I'm looking for a cross-browser solution. No JavaScript/jQuery allowed this time.

xms
  • 429
  • 5
  • 24
  • When you say cross-browser, do you include old browser versions? Flexbox is by far the easiest solution, but older versions of IE will have trouble. – Cameron Aug 04 '16 at 21:38
  • Possible duplicate of [vertical alignment of elements in a div](http://stackoverflow.com/questions/79461/vertical-alignment-of-elements-in-a-div) – Cameron Aug 04 '16 at 21:40
  • No flexbox, thanks. It would be nice if the page worked in IE 7. – xms Aug 04 '16 at 21:42

1 Answers1

1

For a parent with a dynamic height and cross browser functionality, you will need to use an older CSS2 trick, using display: table-cell inside a display: table div. This explains it in more detail

HTML

<div class = "info-left">
    <b>Place:</b>
    <br />Now 6
    <br />Later 32
  </div>

CSS

.info{
  display: table;
}

div.info div.action{
  display: table-cell;
  vertical-align: middle;
}

Here's a fiddle

Community
  • 1
  • 1
Tony Scialo
  • 5,457
  • 11
  • 35
  • 52