简体   繁体   English

在CSS中定位图片

[英]Positioning images in CSS

My goal is to position a Facebook and a Twitter button on my website, using CSS. 我的目标是使用CSS在我的网站上放置一个Facebook和一个Twitter按钮。 However, what I want doesn't seem to work. 但是,我想要的东西似乎没有用。

在此处输入图片说明

The Twitter icon always sits below the Facebook icon. Twitter图标始终位于Facebook图标下方。 Also when I resize my browser's window the position of these buttons changes. 同样,当我调整浏览器窗口的大小时,这些按钮的位置也会改变。 What am I doing wrong? 我究竟做错了什么? Here is my CSS: 这是我的CSS:

#social {
   position: fixed;
   _position: absolute;
   z-index: 1000;
   left:70%;
   top: 120px;
   width: 100px;
   height: 50px;
}   

#social .facebook {
   float: left;
   width: 35px;
   height: 35px;
   padding: 0 0px 0 0px; /* top, right, bottom, left */
   margin: 0;
   list-style: none;
}

#social .twitter {
   float: left;
   width: 35px;
   height: 35px;
   padding: 0 0px 0 50px; /* top, right, bottom, left */
   margin: 0;
   list-style: none;
}

#social .facebook, .twitter li {
   list-style: none;
}

#social .facebook, .twitter li a {
   text-decoration: none;
}

#social .facebook, .twitter li a img {
   border: none;
}

The HTML: HTML:

<div id="social">  

<ul class="facebook">
<li><a href="http://www.facebook.com/"><img src="img/facebook-button.png" width="35"    height="35" alt="Facebook" title="Volg ons op Facebook" /></a></li>
</ul>    
<ul class="twitter">
<li><a href="http://www.twitter.com/"><img src="img/twitter-icon.png" width="35" height="35" alt="Twitter" title="Volg ons op Twitter" /></a></li>
</ul>

</div>

Try this? 尝试这个? (IANA css expert, but I got this to look as I think you want it to look) (IANA CSS专家,但我认为这是我认为的样子)

#social {
    z-index: 1000;
    float:right;
    margin-top:120px;
    width:100px;
    height:50px;
}   

#social .facebook {
    width:35px;
    float:left;
    height:35px;
    padding:0 0px 0 0px; /* top, right, bottom, left */
    margin: 0;
    list-style:none;
}

#social .twitter {
    float: left;
    width:35px;
    height:35px;
    padding:0 0px 0 px; /* top, right, bottom, left */
    margin: 0;
    list-style:none;
}

#social .facebook, .twitter li {
    list-style:none;
}

#social .facebook, .twitter li a {
    text-decoration:none;
}

#social .facebook, .twitter li a img {
    border: none;
}

I added a float to the facebook rule, removed the 50px padding from the twitter rule. 我向facebook规则添加了一个float ,从twitter规则中删除了50px填充。

Edit: Mine works using divs. 编辑:我的作品使用divs。 but you use lists, so I think the nested list combination is causing yours to break. 但您使用列表,因此我认为嵌套列表组合导致您的列表中断。

<div id="social">
    <div class="facebook">
        <a href="o-vita.nl/">
            <img src="img/facebook-button.png" width="35" height="35" alt="Facebook" title="Volg ons op Facebook" />
        </a>
    </div>
    <div class="twitter">
        <a href="o-vita.nl/">
            <img src="img/twitter-icon.png" width="35" height="35" alt="Twitter" title="Volg ons op Twitter" />
        </a>
    </div>
</div>

Edit: http://notails.com/development/positioningsocialnetworkingicons.html 编辑: http//notails.com/development/positioningsocialnetworkingicons.html

Hm, can you show me the website? 嗯,你能告诉我这个网站吗? Because I need to know more information about your website structure, however you can try this. 因为我需要了解有关您的网站结构的更多信息,但是您可以尝试一下。

Sorry for my English. 对不起我的英语不好。

HTML: HTML:

<div id="social">
  <ul>
    <li><a href="http://www.facebook.com/"><img src="img/facebook-button.png" width="35"    height="35" alt="Facebook" title="Volg ons op Facebook" /></a></li>
    <li><a href="http://www.twitter.com/"><img src="img/twitter-icon.png" width="35" height="35" alt="Twitter" title="Volg ons op Twitter" /></a></li>
  </ul>
</div>

CSS: CSS:

#social {
  position:fixed;
  _position:absolute;
  z-index:1000;
  left:70%;
  top:120px;
  width:100px;
  height:50px;
}

#social ul{
  list-style:none;
  margin:0;
  padding:0;
}

#social li{
  float:left;
  width:35px;
  height:35px;
  margin:0 3px;
}

#social a{
  text-decoration:none;
}

#social a img {
   border:none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM