Absolute left position: 50% do not occupy a position in the middle

I have a div div and inside I have <span>an absolute position for the wrapper, since this is an icon from Icomoon, and I need to be part of the background. And then, at the same level as <span>, another div and inside that, I have <h1>, a <p>, a <input>and a <span>.

I positioned the absolute value <span>for the wrapping (which has a relative position), but although I want to put it in the middle, it just needs to be left: 26%, which is not 50%! So the problem arises when I resize the screen so that it does not stay in the middle of the wrapper.

I was wondering why this could be caused? I posted another post a while ago because I wanted to include this issue in JSFiddle, but I couldn't figure out how to include font files in JSFiddle so that the icons would not appear there.

Does anyone have a slight idea of ​​what I can do to fix this?

.containerOfSites {
  display: block;
  height: auto;
  float: none !important;
  margin: 0 auto;
}

.wrapPortalItem {
  padding: 0;
}

.insideWrapItem {
  text-align: center;
  border: 3px solid black;
  padding: 15px;
  position: relative;
}

.portalItem {
  background-color: rgba(255, 255, 255, 0.75);
  padding-top: 3%;
  padding-bottom: 10%;
  font-family: 'Open Sans', sans-serif;
  position: relative;
}

.portalItem p {
  margin-bottom: 40%;
  font-size: 30px;
  padding: 5px;
}

.portalItem p>span {
  font-weight: 900;
}

.portalItem span.viewMorePs {
  text-decoration: none;
  font-size: 18px !important;
  z-index: 999;
}

.portalItem h1 {
  color: #B5D803;
  font-weight: 900;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #fff;
}

.insideWrapItem span[class^="iconI-"] {
  position: absolute;
  color: white;
  bottom: 12%;
  left: 26%;     /* <- */
  font-size: 14em !important;
}
<div id="portalPage" class="col-md-24">
  <div class="containerOfSites col-md-18 col-sm-24">
    <div class="wrapPortalItem col-md-8">
      <div class="insideWrapItem">
        <span class="iconI-iconDA_automotive img-responsive"></span>
        <div class="portalItem portA ">
          <h1>AUTOMOTIVE</h1>
          <p>web sites<br /> for the<br /> <span> automotive<br /> </span> market</p>
          <a href="http://motors06.denison-automotive.co.uk/denison/"><span class="viewMorePsGreen">GO</span></a>
        </div>
      </div>
    </div>

    <div class="wrapPortalItem col-md-8">
      <div class="insideWrapItem">
        <span class="iconI-iconDA_web"></span>
        <div class="portalItem">
          <h1>DESIGN</h1>
          <p>web sites<br /> for the small &<br /> large business<br /> for<span> all sectors</span></p>
          <a href="http://motors06.denison-automotive.co.uk/denison/denison-2/web-sites/"><span class="viewMorePsGreen">GO</span></a>

        </div>
      </div>
    </div>
    <div class="wrapPortalItem col-md-8">
      <div class="insideWrapItem">
        <span class="iconI-iconDA_yourbrand"></span>
        <div class="portalItem">
          <h1>BRANDING</h1>
          <p><span>branding<br /> </span> and<br /> design</p>

          <a href="http://motors06.denison-automotive.co.uk/denison/denison-2/branding/"><span class="viewMorePsGreen">GO</span></a>
        </div>
      </div>
    </div>
    <div class="clearfix"></div>
  </div>
</div>
Run codeHide result
+4
source share
3 answers

It's hard to say for sure without seeing any code, but I think your problem is that your left edge sits at 50%, but you want the center to sit in the center of its parent?

Try something similar on span (in addition to any other styles):

span {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

This should move half of its own width so that it remains.

+10

, CSS:

left:0;
right:0;
margin:0 auto;

: http://jsfiddle.net/ucjt51Lc/

left: 50% , , .

+1

Please specify the font files in jsFiddle. On the left side is a panel, click "External Resources", paste the font URL there and click the plus sign. (I wanted to add this as a comment, but StackOverflow did not allow this because I have not earned 50 reputation points yet ...)

0
source

All Articles