Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align horizontally elements without using Flexbox?

Is there a way to align the web components next to each other without using Flexbox. I know it an awesome tool but unfortunately it doesn't work with IE 9 or 10. I want the text inside the link to appear right next to the images. JSFiddle shows the working code but with FlexBox, how can I achieve this without using Flexbox?

Code:

<display:setProperty name="paging.banner.full" value='<span class="pagelinks"> <a href="{1}"> <img src="../images/integration/FastLeft.jpg"/> </a> <a href="{2}"> <img src="../images/integration/SlowLeft.jpg"/> </a> | Page {5} of {6} | <a href="{3}">  <img src="../images/integration/SlowRight.jpg"/> </a> <a href="{4}"> <img src="../images/integration/FastRight.jpg"/> </a></span>'/>
        <display:setProperty name="paging.banner.first" value='<span class="pagelinks"> <img src="../images/integration/FastLeft.jpg"/> <img src="../images/integration/SlowLeft.jpg"/> | Page {5} of {6} | <a href="{3}"> <img src="../images/integration/SlowRight.jpg"/> </a> <a href="{4}"> <img src="../images/integration/FastRight.jpg"/> </a></span>'/>
        <display:setProperty name="paging.banner.last" value='<span class="pagelinks"> <a href="{1}"> <img src="../images/integration/FastLeft.jpg"/> </a> <a href="{2}"> <img src="../images/integration/SlowLeft.jpg"/> </a> | Page {5} of {6} | <img src="../images/integration/SlowRight.jpg"/> <img src="../images/integration/FastRight.jpg"/> </span>'/>

CSS

.pagelinks {
float: right;
margin-right: 48%;
color: #828282;
display: table-cell;
vertical-align: middle;
display: flex;
align-items: center;
justify-content: center; 
}

.pagelinks a {
text-decoration: none;
}

.pagelinks img {
 border: 1px solid transparent;
}

.pagelinks img:hover {
 border-radius: 3px;
 border: 1px solid #828282;
} 

JSFiddle

like image 464
Mike Avatar asked Jun 20 '26 11:06

Mike


1 Answers

For IE10 and below (maybe till IE7/8),

you have 2 solutions:

inline-block

you can use display:inline-block and vertical-align:middle in img, and wrap it all with a div using some width and margin:auto to center it horizontally

div {
  width: 50%;
  /* change the value as you prefer, even in px */
  margin: auto;
  text-align: center;
  /*demo*/
  border: 1px solid red;
}

.pagelinks {
  color: #828282;
}

.pagelinks a {
  text-decoration: none;
}

.pagelinks img {
  border: 1px solid transparent;
  display: inline-block;
  vertical-align: middle;
}

.pagelinks img:hover {
  border-radius: 3px;
  border: 1px solid #828282;
}
<div>
  <span class="pagelinks"> <a href="{1}"> <img src="../images/integration/FastLeft.jpg"/> </a> <a href="{2}"> <img src="../images/integration/SlowLeft.jpg"/> </a> | Page {5} of {6} | <a href="{3}">  <img src="../images/integration/SlowRight.jpg"/> </a> <a href="{4}"> <img src="../images/integration/FastRight.jpg"/> </a></span>
</div>

table/table-cell

applying display:table to .page-links and vertical-align:middle to img, and again wrapping it in a div to center.

div {
  width: 50%;
  margin: auto;
}

.pagelinks {
  color: #828282;
  display: table;
  width: 100%;
  text-align: center;
  /*demo*/
  border: 1px solid red;
}

.pagelinks a {
  text-decoration: none;
}

.pagelinks img {
  border: 1px solid transparent;
  vertical-align: middle;
}

.pagelinks img:hover {
  border-radius: 3px;
  border: 1px solid #828282;
}
<div>
  <span class="pagelinks"> <a href="{1}"> <img src="../images/integration/FastLeft.jpg"/> </a> <a href="{2}"> <img src="../images/integration/SlowLeft.jpg"/> </a> | Page {5} of {6} | <a href="{3}">  <img src="../images/integration/SlowRight.jpg"/> </a> <a href="{4}"> <img src="../images/integration/FastRight.jpg"/> </a></span>
</div>
like image 108
dippas Avatar answered Jun 22 '26 01:06

dippas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!