简体   繁体   English

删除图像之间不需要的空间

[英]Removing unwanted space between images

My problem is in my navigation bar, which can be found here: http://grupocoral.netai.net/ 我的问题出在我的导航栏中,可以在这里找到: http//grupocoral.netai.net/

There is a space between those images and i want to remove it. 这些图像之间有一个空格,我想删除它。 How can I do it? 我该怎么做?

Javascript Code: Javascript代码:

function swap(element, image) {
  element.src = image;
}

And the html code: 和HTML代码:

<div id="navbar"><a href="index.php"><img src="images/homeover.png"></a>
<a href="membros.php"><img src="images/membros.png" onmouseover="swap(this, 'images/membrosover.png');" onmouseout="swap(this, 'images/membros.png');"></a>
<a href="canticos.php"><img src="images/canticos.png" onmouseover="swap(this, 'images/canticosover.png');" onmouseout="swap(this, 'images/canticos.png');"></a>
<a href="celeb.php"><img src="images/celebracoes.png" onmouseover="swap(this, 'images/celebracoesover.png');" onmouseout="swap(this, 'images/celebracoes.png');"></a>
<a href="contactos.php"><img src="images/contactos.png" onmouseover="swap(this, 'images/contactosover.png');" onmouseout="swap(this, 'images/contactos.png');"></a>
</div>

Just in case, navbar CSS code: 以防万一,navbar CSS代码:

#navbar{
    width: 1280px;
    margin: 0 auto;
    height: 40px;
    horizontal-align: center;
    padding:inherit;
}

By the way, do you know any other way of making a menu like that without JS? 顺便说一下,你知道在没有JS的情况下制作菜单的其他任何方式吗?

Thanks, langel 谢谢,langel

It's due to the white space in your code. 这是由于代码中的空白区域。 Remove the white space between your links and that should clear it up. 删除链接之间的空白区域,并清除它。

In other words, change your HTML block of navigation to: 换句话说,将您的HTML导航栏更改为:

<div id="navbar"><a href="index.php"><img src="images/homeover.png"></a><a href="membros.php"><img src="images/membros.png" onmouseover="swap(this, 'images/membrosover.png');" onmouseout="swap(this, 'images/membros.png');"></a><a href="canticos.php"><img src="images/canticos.png" onmouseover="swap(this, 'images/canticosover.png');" onmouseout="swap(this, 'images/canticos.png');"></a><a href="celeb.php"><img src="images/celebracoes.png" onmouseover="swap(this, 'images/celebracoesover.png');" onmouseout="swap(this, 'images/celebracoes.png');"></a><a href="contactos.php"><img src="images/contactos.png" onmouseover="swap(this, 'images/contactosover.png');" onmouseout="swap(this, 'images/contactos.png');"></a>    </div>

Inline elements like these are whitespace dependent, which means that browsers will render some whitespace between them. 像这样的内联元素依赖于空格,这意味着浏览器将在它们之间呈现一些空格。

to counter this you can either run all your elements together on one line 为了解决这个问题,你可以在一行上运行所有元素

<a href="#">link</a><a href="#">link</a>

or block the closing and opening tags 或阻止关闭和打开标签

<a href="#">
     link</a><a href="#">
</a>
<a href="#">
     link</a><a href="#">
</a>

:) :)

This keeps my code clean and it removes the whitespaces in the code. 这使我的代码保持干净,并删除代码中的空格。

<a><img src="" /></a><!-- 
--><a><img src="" /></a><!-- 
--><a><img src="" /></a><!-- 
--><a><img src="" /></a>

to remove the space just remove the break line between the anchor ex: 删除空格只需删除锚点之间的断行:

and i suggest to use the css without the js : 我建议使用没有js的CSS:

<div id="navbar">
<a class="home" href="#"></a><a href="" class="member"></a>....
</div>

CSS : CSS:

#navbar a{display:inline-block;margin:0;}
#navbar a.member{background:url(images/member.png) no-repeat 0 0}
#navbar a.member:hover{background:url(images/memberhover.png) no-repeat 0 0}

You do have an alternative option to your javascript image swap. 你有一个替代选项来javascript图像交换。 You can use the CSS :hover in combination with background-image . 您可以将CSS :hoverbackground-image结合使用。

dabblet example: http://dabblet.com/gist/2253898 dabblet例子: http ://dabblet.com/gist/2253898

CSS: CSS:

#Membros{
    background-image:url('http://grupocoral.netai.net/images/membros.png');
    width:240px;
    height:40px;
}
#Membros:hover {
    background-image:url('http://grupocoral.netai.net/images/membrosover.png');
}

HTML HTML

<a href="index.php"><div id="Membros"></div></a>

I hope this helps! 我希望这有帮助!

By the way, do you know any other way of making a menu like that without JS? 顺便说一下,你知道在没有JS的情况下制作菜单的其他任何方式吗?

Yes, here is an example , I've used one of your background image link with 'Home' on it, you should use only one image without any text label on it. 是的,这是一个例子 ,我使用了一个带有'Home'的背景图像链接,你应该只使用一个没有任何文字标签的图像。

您也可以使用:hover css伪类来改变背景,使用:hover css伪类来改变背景,但是即使在JS被禁用时它也会使这个菜单工作css_pseudo_classes

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

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