0

I am having difficulty aligning my text in the center of this box I created. This is my second day working with CSS so I imagine there's some issues with my code.

Let me show you my materials.

Here is my HTML:

<div class="row">
    <div class="section1">     
        <table class="featuredclub" id="featuredclub-comments">
            <tr>
                <td width="10%" class="rating">
                    <div class="ratingnumber">
                        <span class="ratingpositiontext">
                            <span style="margin-top:15px">#1</span>
                        </span>
                    </div>
                </td>
                <td width="15%" style="margin-left:0px;margin-top:1px" class="imagetd">
                    <div class="ratingimage">
                        <div style="margin-top:6px">
                            <img style="height:80px;width:80px" class="featuredavatar" src="/img/featuredtmp.png" />
                        </div>
                    </div>
                </td>
                <td width="75%" style="text-align:left;margin-left:10px">
                    <span class="featuredclubname"><xsl:value-of select="/*/hundreds/numcomments/featuredclub/name"/></span>
                    <span class="featuredclubaddress"><xsl:value-of select="/*/hundreds/numcomments/featuredclub/address"/></span>
                    <span class="featuredclublocality"><xsl:value-of select="/*/hundreds/numcomments/featuredclub/city"/>, <xsl:value-of select="/*/hundreds/numcomments/featuredclub/state"/> <xsl:value-of select="/*/hundreds/numcomments/featuredclub/zip"/></span>
                    <span class="featuredclubphone"><xsl:value-of select="/*/hundreds/numcomments/featuredclub/phone"/></span>
                </td>
            </tr>
        </table>
    </div>
</div>

Here is my CSS:

@CHARSET "ISO-8859-1";

span.value {
    margin-right:-10px;
}
.viewallbutton{
    display:inline;
    margin-top:2px;
    margin-left:2px;
}
h2.sectionlabel{
    display:inline-block;
}
.banner{
  position: relative;
  background-color: #ffffff;
  width: 1200px;
  height: 62px;
  margin: 0px auto;
  padding-top:15px;
  padding-bottom:0px;
  padding-left:25px;
  padding-right:25px;
  box-sizing: border-box;
  /**
  border-top: 1px solid #d0d0d0;
  border-left: 1px solid #d0d0d0;
  border-right: 1px solid #d0d0d0;
  border-bottom:none;
  */
  border:0px;
  border-bottom:1px solid #f0f0f0;
  font: 14px/20px Arial, Helvetica, Sans-serif;
}
.banner h2{
  font: 32px/32px DinWebCond, Sans-serif;
  color: #120006;
  margin: 0px 0px 5px 0px;
  text-transform: uppercase;
  padding-top:5px;
  padding-bottom:15px;
}
div.banner-container1{
    width:90%;
    height:50px;
    background-color:#f0f0f0;
    padding-left:25px;
}
div.banner-container2{
    width:90%;
    height:50px;
    background-color:#f0f0f0;
    padding-left:25px;
    /**padding-left:25px;*/
}
div.banner-container div.innerclubbox{
    background-color:#ffffff;   
}
.tabledatalabel{
  font: 20px/24px DinWebCond, Sans-serif;
  color: #606060;
  margin: 0px 0px 5px 0px;
  /**text-transform:capitalize;*/
  padding-top:5px;  
}
.row {
  position: relative;
  /**height: 750px;*/
  height: 450px;
  background-color: #ffffff;
  width: 1200px;
  margin: 0px auto;
  /**padding-top:20px;*/
  padding-top:10px;
  padding-bottom:0px;
  padding-left:0px;
  /**padding-right:25px;*/
  box-sizing: border-box;
  /**border: 1px solid #d0d0d0;*/
  font: 14px/20px Arial, Helvetica, Sans-serif;     
}
p .clear{
  clear:both;
}

.section1 .featuredclub{
    width:100%;
    height:100px;
    background-color:#f0f0f0;
    font:14px/20px AdlWebNorm, Sserif;  
}

.section1 table.featuredclub,
.section2 table.featuredclub{
    width:100%;
    height:100px;
    background-color:#f0f0f0;
    font:14px/20px AdlWebNorm, Sserif;
    margin-top:-5px;
    /**margin-left:25px;*/
    margin-bottom:10px;
}

.section1 table.featuredclub .rating,
.section2 table.featuredclub .rating {
    /**margin-top:-5px;
    margin-left:25px;
    margin-bottom:10px;*/
    /**background-color:#ffffff;*/
    width:71px;
    height:71px;
}

.section1 table.featuredclub .image,
.section2 table.featuredclub .image {
    /**margin-top:-5px;
    margin-left:25px;
    margin-bottom:10px;*/
    /**background-color:#ffffff;*/
    width:71px;
    height:71px;
    margin-left:0px;
}
.ratingnumber{
    font-size: 42px;
    margin-left:20px;
    width:80px;
    height:80px;
    background-color:#ffffff;
}
.ratingpositiontext{
    margin-right:15px;
    margin-top:55px;
}
.section1 table.featuredclub .rating div.ratingimage,
.section2 table.featuredclub .rating div.ratingimage{
    font-size: 26px;
    margin-left:0px;
    width:80px;
    height:80px;
    background-color:#ffffff;
}
.section1 .featuredclub .featuredtext{
    width:100%;
    height:100px;
    background-color:#f0f0f0;
    font:14px/20px AdlWebNorm, Sserif;
    display:inline-block;   
}

.section1 .featuredclub span p.rating{  
    margin-top:-5px;
    margin-left:25px;
    margin-bottom:10px;
    background-color:#ffffff;
    width:71px;
    height:71px;
    /**display:inline;*/
}

.section1 .featuredclub span p.text{    
    margin-top:-5px;
    margin-left:5px;
    margin-bottom:10px;
    background-color:#ffffff;
    /**width:71px;*/
    height:71px;
    display:inline;
}

.section2 .featuredclub{
    width:100%;
    height:100px;
    background-color:#f0f0f0;
    font:14px/20px AdlWebNorm, Sserif;
}

.section1 .featuredclub span.featuredclubname,
.section2 .featuredclub span.featuredclubname
{
    clear:both;
    color:#120006;
    float:left;
    font: 22px/22px DinWebCond, Sans-serif;
}
.section1 .featuredclub span.featuredclubaddress,
.section2 .featuredclub span.featuredclubaddress
{
    clear:both;
    float:left;
    font: 14px/20px AdlWebNorm, Serif;
    color: #000000;
}
.section1 .featuredclub span.featuredclublocality,
.section2 .featuredclub span.featuredclublocality
{
    clear:both;
    float:left;
    font: 14px/20px AdlWebNorm, Serif;
    color: #000000;
}
.section1 .featuredclub span.featuredclubphone,
.section2 .featuredclub span.featuredclubphone
{
    clear:both;
    float:left;
    font: bold 12px/12px Arial, Helvtica, Sans-serif;
    margin-top:2px;
}

.section2 .featuredclub span p.rating,
{
    margin-top:-5px;
    margin-left:25px;
    margin-bottom:10px;
    background-color:#ffffff;
    width:71px;
    height:71px;
}

.section1 .featuredclub p.rating img.featuredavatar{
    margin-top:-27px;
    width:70px;
    height:70px;
    margin-left:69px;
}

.section2 .featuredclub p.rating img.featuredavatar{
    margin-top:-27px;
    width:70px;
    height:70px;
    margin-left:69px;
}

.section1 .featuredclub span p.rating span.rating-number-box
{
    text-align:center;
    font-size: 36px;
    color:#bd673a;
    margin-top:20px;
}

.section2 .featuredclub span p.rating span.rating-number-box
{
    text-align:center;
    font-size: 36px;
    color:#bd673a;
    margin-top:20px;
}

.section1 .featuredclub span{
    /**margin-left:25px;*/  
}

.section2 .featuredclub span{
    /**margin-left:25px;*/  
}

.section1 {
  width:50%;
  /**border-right: 1px solid #d0d0d0;*/
  float:left;  
  box-sizing: border-box;   
}

td {
    font:14px/20px AdlWebNorm, Sserif;
}

.section2 {
  width:50%;
  /**border-right: 1px solid #d0d0d0;*/
  float:left;  
  box-sizing: border-box;
}

.section1 h2{
  font: 22px/24px DinWebCond, Sans-serif;
  color: #120006;
  margin: 0px 0px 5px 0px;
  text-transform: uppercase;
  padding-left:25px;
  padding-bottom:10px;
}

.section2 h2{
  font: 22px/24px DinWebCond, Sans-serif;
  color: #120006;
  margin: 0px 0px 5px 0px;
  text-transform: uppercase;
  padding-left:25px;
  padding-bottom:10px;
}

td {
    text-align:right;
}
td.imagetd{
    text-align:left;
}

.progress-bar .horizontal {
  float: left;
  height: 45px;
  width: 100%;
  /**padding: 12px 0;*/
}

.progress-track {
  position: relative;
  width: 30%;
  height: 13px;
  background: #FFFFFF;
  float:right;
  margin-left:-20px;
}

.progress-fill {
  position: relative;
  background: #2272af;
  height: 13px;
  width: 50%;
  color: #2272af;
  text-align: center;
  font-family: "Lato","Verdana",sans-serif;
  font-size: 12px;
  line-height: 20px;
  /**border-radius:0px 5px 5px 0px;*/
  border-radius:0px 0px 0px 0px;
}

/**tr td { padding-top: 1px }*/

Here are some images of the resulting HTML:

alexs

If you look the numeric value is on the top right. I need it in the center

I've been working on this for a few hours and haven't gotten anywhere with it.

Any help would be greatly appreciated

P. Frank
  • 5,691
  • 6
  • 22
  • 50
somejkuser
  • 8,856
  • 20
  • 64
  • 130
  • Please, provide jsfiddle. – Alex Nov 11 '15 at 15:44
  • 1
    Possible duplicate of [Vertically center text in a 100% height div?](http://stackoverflow.com/questions/4753678/vertically-center-text-in-a-100-height-div) and a host of other answers found by searching SO. This question, and similar, are asked almost every day. – Rob Nov 11 '15 at 15:47

2 Answers2

1

You can set line-height of the span equal to the height of the parent element. line-height property is for typographical vertical spacing. To understand it, when you add a new word inside the span, the item will wrap to next line and will be spaced equidistant from each other with 80px as a distance parameter.

.section1 .featuredclub span {
   line-height: 80px;
}

JSfiddle Demo

@CHARSET "ISO-8859-1";
 span.value {
  margin-right: -10px;
}
.viewallbutton {
  display: inline;
  margin-top: 2px;
  margin-left: 2px;
}
h2.sectionlabel {
  display: inline-block;
}
.banner {
  position: relative;
  background-color: #ffffff;
  width: 1200px;
  height: 62px;
  margin: 0px auto;
  padding-top: 15px;
  padding-bottom: 0px;
  padding-left: 25px;
  padding-right: 25px;
  box-sizing: border-box;
  /**
  border-top: 1px solid #d0d0d0;
  border-left: 1px solid #d0d0d0;
  border-right: 1px solid #d0d0d0;
  border-bottom:none;
  */
  border: 0px;
  border-bottom: 1px solid #f0f0f0;
  font: 14px/20px Arial, Helvetica, Sans-serif;
}
.banner h2 {
  font: 32px/32px DinWebCond, Sans-serif;
  color: #120006;
  margin: 0px 0px 5px 0px;
  text-transform: uppercase;
  padding-top: 5px;
  padding-bottom: 15px;
}
div.banner-container1 {
  width: 90%;
  height: 50px;
  background-color: #f0f0f0;
  padding-left: 25px;
}
div.banner-container2 {
  width: 90%;
  height: 50px;
  background-color: #f0f0f0;
  padding-left: 25px;
  /**padding-left:25px;*/
}
div.banner-container div.innerclubbox {
  background-color: #ffffff;
}
.tabledatalabel {
  font: 20px/24px DinWebCond, Sans-serif;
  color: #606060;
  margin: 0px 0px 5px 0px;
  /**text-transform:capitalize;*/
  padding-top: 5px;
}
.row {
  position: relative;
  /**height: 750px;*/
  height: 450px;
  background-color: #ffffff;
  width: 1200px;
  margin: 0px auto;
  /**padding-top:20px;*/
  padding-top: 10px;
  padding-bottom: 0px;
  padding-left: 0px;
  /**padding-right:25px;*/
  box-sizing: border-box;
  /**border: 1px solid #d0d0d0;*/
  font: 14px/20px Arial, Helvetica, Sans-serif;
}
p .clear {
  clear: both;
}
.section1 .featuredclub {
  width: 100%;
  height: 100px;
  background-color: #f0f0f0;
  font: 14px/20px AdlWebNorm, Sserif;
}
.section1 table.featuredclub,
.section2 table.featuredclub {
  width: 100%;
  height: 100px;
  background-color: #f0f0f0;
  font: 14px/20px AdlWebNorm, Sserif;
  margin-top: -5px;
  /**margin-left:25px;*/
  margin-bottom: 10px;
}
.section1 table.featuredclub .rating,
.section2 table.featuredclub .rating {
  /**margin-top:-5px;
    margin-left:25px;
    margin-bottom:10px;*/
  /**background-color:#ffffff;*/
  width: 71px;
  height: 71px;
}
.section1 table.featuredclub .image,
.section2 table.featuredclub .image {
  /**margin-top:-5px;
    margin-left:25px;
    margin-bottom:10px;*/
  /**background-color:#ffffff;*/
  width: 71px;
  height: 71px;
  margin-left: 0px;
}
.ratingnumber {
  font-size: 42px;
  margin-left: 20px;
  width: 80px;
  height: 80px;
  background-color: #ffffff;
}
.ratingpositiontext {
  margin-right: 15px;
  margin-top: 55px;
}
.section1 table.featuredclub .rating div.ratingimage,
.section2 table.featuredclub .rating div.ratingimage {
  font-size: 26px;
  margin-left: 0px;
  width: 80px;
  height: 80px;
  background-color: #ffffff;
}
.section1 .featuredclub .featuredtext {
  width: 100%;
  height: 100px;
  background-color: #f0f0f0;
  font: 14px/20px AdlWebNorm, Sserif;
  display: inline-block;
}
.section1 .featuredclub span p.rating {
  margin-top: -5px;
  margin-left: 25px;
  margin-bottom: 10px;
  background-color: #ffffff;
  width: 71px;
  height: 71px;
  /**display:inline;*/
}
.section1 .featuredclub span p.text {
  margin-top: -5px;
  margin-left: 5px;
  margin-bottom: 10px;
  background-color: #ffffff;
  /**width:71px;*/
  height: 71px;
  display: inline;
}
.section2 .featuredclub {
  width: 100%;
  height: 100px;
  background-color: #f0f0f0;
  font: 14px/20px AdlWebNorm, Sserif;
}
.section1 .featuredclub span.featuredclubname,
.section2 .featuredclub span.featuredclubname {
  clear: both;
  color: #120006;
  float: left;
  font: 22px/22px DinWebCond, Sans-serif;
}
.section1 .featuredclub span.featuredclubaddress,
.section2 .featuredclub span.featuredclubaddress {
  clear: both;
  float: left;
  font: 14px/20px AdlWebNorm, Serif;
  color: #000000;
}
.section1 .featuredclub span.featuredclublocality,
.section2 .featuredclub span.featuredclublocality {
  clear: both;
  float: left;
  font: 14px/20px AdlWebNorm, Serif;
  color: #000000;
}
.section1 .featuredclub span.featuredclubphone,
.section2 .featuredclub span.featuredclubphone {
  clear: both;
  float: left;
  font: bold 12px/12px Arial, Helvtica, Sans-serif;
  margin-top: 2px;
}
.section2 .featuredclub span p.rating,
{
  margin-top: -5px;
  margin-left: 25px;
  margin-bottom: 10px;
  background-color: #ffffff;
  width: 71px;
  height: 71px;
}
.section1 .featuredclub p.rating img.featuredavatar {
  margin-top: -27px;
  width: 70px;
  height: 70px;
  margin-left: 69px;
}
.section2 .featuredclub p.rating img.featuredavatar {
  margin-top: -27px;
  width: 70px;
  height: 70px;
  margin-left: 69px;
}
.section1 .featuredclub span p.rating span.rating-number-box {
  text-align: center;
  font-size: 36px;
  color: #bd673a;
  margin-top: 20px;
}
.section2 .featuredclub span p.rating span.rating-number-box {
  text-align: center;
  font-size: 36px;
  color: #bd673a;
  margin-top: 20px;
}
.section1 .featuredclub span {
  /**margin-left:25px;*/
}
.section2 .featuredclub span {
  /**margin-left:25px;*/
}
.section1 {
  width: 50%;
  /**border-right: 1px solid #d0d0d0;*/
  float: left;
  box-sizing: border-box;
}
td {
  font: 14px/20px AdlWebNorm, Sserif;
}
.section2 {
  width: 50%;
  /**border-right: 1px solid #d0d0d0;*/
  float: left;
  box-sizing: border-box;
}
.section1 h2 {
  font: 22px/24px DinWebCond, Sans-serif;
  color: #120006;
  margin: 0px 0px 5px 0px;
  text-transform: uppercase;
  padding-left: 25px;
  padding-bottom: 10px;
}
.section2 h2 {
  font: 22px/24px DinWebCond, Sans-serif;
  color: #120006;
  margin: 0px 0px 5px 0px;
  text-transform: uppercase;
  padding-left: 25px;
  padding-bottom: 10px;
}
td {
  text-align: right;
}
td.imagetd {
  text-align: left;
}
.progress-bar .horizontal {
  float: left;
  height: 45px;
  width: 100%;
  /**padding: 12px 0;*/
}
.progress-track {
  position: relative;
  width: 30%;
  height: 13px;
  background: #FFFFFF;
  float: right;
  margin-left: -20px;
}
.progress-fill {
  position: relative;
  background: #2272af;
  height: 13px;
  width: 50%;
  color: #2272af;
  text-align: center;
  font-family: "Lato", "Verdana", sans-serif;
  font-size: 12px;
  line-height: 20px;
  /**border-radius:0px 5px 5px 0px;*/
  border-radius: 0px 0px 0px 0px;
}
/**tr td { padding-top: 1px }*/

.section1 .featuredclub span {
  line-height: 80px;
}
<div class="row">
  <div class="section1">
    <table class="featuredclub" id="featuredclub-comments">
      <tr>
        <td width="10%" class="rating">
          <div class="ratingnumber">
            <span class="ratingpositiontext">
      <span style="margin-top:15px">#1</span>
            </span>
          </div>
        </td>
        <td width="15%" style="margin-left:0px;margin-top:1px" class="imagetd">
          <div class="ratingimage">
            <div style="margin-top:6px">
              <img style="height:80px;width:80px" class="featuredavatar" src="/img/featuredtmp.png" />
            </div>
          </div>
        </td>
        <td width="75%" style="text-align:left;margin-left:10px">
          <span class="featuredclubname"><xsl:value-of select="/*/hundreds/numcomments/featuredclub/name"/></span>
          <span class="featuredclubaddress"><xsl:value-of select="/*/hundreds/numcomments/featuredclub/address"/></span>
          <span class="featuredclublocality"><xsl:value-of select="/*/hundreds/numcomments/featuredclub/city"/>, <xsl:value-of select="/*/hundreds/numcomments/featuredclub/state"/> <xsl:value-of select="/*/hundreds/numcomments/featuredclub/zip"/></span>
          <span class="featuredclubphone"><xsl:value-of select="/*/hundreds/numcomments/featuredclub/phone"/></span>
        </td>
      </tr>
    </table>
  </div>
</div>
m4n0
  • 29,823
  • 27
  • 76
  • 89
0

I guess using padding in the ratingnumber will work

.ratingnumber{
    font-size: 42px;
    margin-left:20px;
    width:80px;
    height:80px;
    background-color:#ffffff;
    padding-left:    ;
    padding-top:     ;
}
hash-set
  • 186
  • 1
  • 12