Center List in side a div

点点圈 提交于 2019-12-12 03:42:47

问题


I'm trying to center my list with images inside a div. This is what I'm getting (icons way too small and not centered).

this is the css ive got and the html

       <div id="social">

                <ul>
                    <li><img src="img/footertwitter.png" alt="placeholder+image"></li>
                    <li><img src="img/footerfacebook.png" alt="placeholder+image"></li>
                    <li><img src="img/footeremail.png" alt="placeholder+image"></li>
                </ul>

            </div>


        #social {
margin: 0 auto;
text-align: center;
width: 90%;
max-width: 1140px;
position: relative;
  }

    #social ul {
/*margin: 0 0 3em 0!important;*/
padding: 0!important;

}

  #social ul li {
list-style-type: none;
display: inline-block;
margin-left: 1.5em;
margin-right: 1.5em;
  }

回答1:


In your rule for the ul consider setting the display property to block and the margins to auto. If I understand correctly what you're trying to accomplish, that should center things for you while retaining the margins you assigned.

The updated CSS would look like:

#social 
{
  margin: 0 auto;
  text-align: center;
  width: 90%;
  max-width: 1140px;
  position: relative;
}

#social ul 
{
  padding: 0;
  margin:auto;
  display: block;
}

#social ul li 
{
  list-style-type: none;
  display: inline-block;
  margin-left: 1.5em;
  margin-right: 1.5em;
}

This fiddle shows the changes in action. Hope that helps.




回答2:


  1. You can simply increase the icon size according to your need:

    social ul li img {

    width:50px; 
    height:50px;
    

    }

  2. Give a fixed width to ul and then put it in the center using the following code:

    social ul {

    width:300px; /*Example*/
    display:block;
    margin:0 auto;
    

    }



来源:https://stackoverflow.com/questions/16670713/center-list-in-side-a-div

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!