Stacking text and images on top of each other

问题: I can't seem to get my text on top of these three logo/icons. I want them to be centered as well. I've tried inline-block, centering text but i might just be doing too much...

问题:

I can't seem to get my text on top of these three logo/icons. I want them to be centered as well. I've tried inline-block, centering text but i might just be doing too much?

html:

    <div class= "sign-up">
        <a>Or Sign Up Using</a>
    </div>

    <div class= "sociallogo">
        <div class="socialcontainer">
            <img src="img/facebook.png">
        </div>
        <div class="socialcontainer">
            <img src="img/twitter.png">
        </div>
        <div class="socialcontainer">
            <img src="img/google.png">
        </div>
    </div>

css:

.sign-up {
    line-height: 1.5;
    color: #777777;
    text-align: center;
    display: inline-block;
    float: left;
}

.sociallogo {
    border-radius: 50%;
    margin: 5px;
    display: inline-block;
    clear: both;
}

.socialcontainer {
    display: inline-block;
    height: 50px;
    width: 50px;
    padding: 2px;
}

回答1:

I changed the display of sociallogo to block and changed the text-align of the classes to get this result: enter image description here

 <div class= "sign-up">
        <a>Or Sign Up Using</a>
    </div>

    <div class= "sociallogo">
        <div class="socialcontainer">
            <img src="img/facebook.png">
        </div>
        <div class="socialcontainer">
            <img src="img/twitter.png">
        </div>
        <div class="socialcontainer">
            <img src="img/google.png">
        </div>
    </div>
<style>
.sign-up {
    line-height: 1.5;
    color: #777777;
    text-align: left;
    display: inline-block;
    width: 100%;
}

.sociallogo {
    text-align: center
    border-radius: 50%;
    margin: 5px;
    display: block;
    clear: both;
    width: 100%;
}

.socialcontainer {
    text-align: center;
    display: inline;
    height: 50px;
    width: 50px;
    padding: 2px;
    width: 100%;
}
</style>

回答2:

Make .sign-up and .sociallogo block rather than inline-block.

Remove float: left from .sign-up.

Add text-align: center to .sociallogo.

.sign-up {
  line-height: 1.5;
  color: #777777;
  text-align: center;
}

.sociallogo {
  border-radius: 50%;
  margin: 5px;
  text-align: center;
}

.socialcontainer {
  display: inline-block;
  height: 50px;
  width: 50px;
  padding: 2px;
}
<div class="sign-up">
  <a>Or Sign Up Using</a>
</div>

<div class="sociallogo">
  <div class="socialcontainer">
    <img src="img/facebook.png">
  </div>
  <div class="socialcontainer">
    <img src="img/twitter.png">
  </div>
  <div class="socialcontainer">
    <img src="img/google.png">
  </div>
</div>


回答3:

I quite like using display: flex for this kind of thing, really useful for positioning and I think you'll find it really easy to use.

You should use display: flex on the container along with flex-direction (can be row or column), but i think you want column here in order to stack them.

And adding align-items: center will centre everything horizontally for you.

I've simplified your code below for you:

.sign-up {
  line-height: 1.5;
  color: #777777;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sociallogo img {
  border-radius: 50%;
  margin: 5px;
  height: 50px;
  width: 50px;
  padding: 2px;
}
<div class="sign-up">
  <a>Or Sign Up Using</a>
  <div class="sociallogo">
    <img src="img/facebook.png">
    <img src="img/twitter.png">
    <img src="img/google.png">
  </div>
</div>


回答4:

Try using width: 100% on both containers, this should solve the problem.

Afther that u can use Transform and margin to center the images.

.sign-up {
  width: 100%;
  line-height: 1.5;
  color: #777777;
  text-align: center;
  display: inline-block;
  float: left;
}

.sociallogo {
  width: 100%;
  border-radius: 50%;
  margin: 5px;
  display: inline-block;
  clear: both;
}

.socialcontainer {
  display: inline-block;
  height: 50px;
  width: 50px;
  padding: 2px;
}
<div class="sign-up">
  <a>Or Sign Up Using</a>
</div>

<div class="sociallogo">
  <div class="socialcontainer">
    <img src="img/facebook.png">
  </div>
  <div class="socialcontainer">
    <img src="img/twitter.png">
  </div>
  <div class="socialcontainer">
    <img src="img/google.png">
  </div>
</div>


回答5:

Try this:

Remove float: left; from .sign-up

and add vertical-align: middle; to both .sign-up and .sociallogo divs

  • 发表于 2019-03-15 00:13
  • 阅读 ( 67 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除