HTML / CSS中链接之间的水平空格

时间:2014-02-23 04:10:55

标签: html css

请参阅以下jsfiddle: http://jsfiddle.net/8uFpD/

我希望链接“主页”“我们做什么”“我们是谁”和“捐赠”以在它们之间留出更多的水平空间。我无法弄清楚如何做到这一点,我已经尝试了很多方法(span,div等)

如何在不必使用白色方形图像的情况下添加它们之间的水平空间? (这对我来说似乎很俗气。)

HTML:

<body>
<div class="wrapper">
    <div class="whiteTitleBar">
        <span class="title">My Website</span>
        <span class="navigation">
            <a class="navigation" href="index.html"> Home</a>
            <span class="navigationSpace"/>
            <a class="navigation" href="ourwork.html"> What We Do</a>
            <span class="navigationSpace"/>
            <a class="navigation" href="about.html"> Who We Are</a>
            <span class="navigationSpace"/>
            <a class="navigation" href="donate.html"> Donate</a>
        </span>
    </div>

    <div class="blackHorizontalLine"></div>
    <div class="redYouAreHereBar">HOME</div>
    <div class="blackHorizontalLine"></div>
    <div class="home">
        BLAH BLAH BLAH
    </div>
</div>

</body>

CSS:

body {
font-family:Arial, Helvetica, sans-serif;
margin:0px;
background-image:url('images/bg.jpg');
background-repeat:no-repeat;
background-size: 100% 100%;
}

div.wrapper {
width:862px;
margin-left:auto;
margin-right:auto;
border:2px solid black;
margin-top:20px;
margin-bottom:20px;
}

div.home {
background-image:url('images/bg_home.jpg');
background-repeat:no-repeat;
height:492px;
}

div.homeText {
position:relative;
left:390px;
top:400px;
font-size:xx-large;
color:#ffffff;
text-shadow: 2px 2px 3px black;
}

span.title {
color:#000000;
float:left;
font-size:x-large;
}

span.navigation {
color: #000000;
float:right;
}

span.homeTagline {
font-size: x-large;
position:relative;
left:65px;
text-shadow: 2px 2px 3px black;
}


/* unvisited link */
a.navigation:link {
color:#000000; 
text-decoration:none;
}

/* unvisited link */
a.navigation:visited {
color:#000000; 
text-decoration:none;
}

/* mouse over link */
a.navigation:hover {
color:#FF0000; 
text-decoration:none;
} 

/* mouse over link */
a.navigation:active {
color:#FF0000; 
text-decoration:none;
}  



h1.white {
color:#ffffff;
}

div.whiteTitleBar {
background-color:#ffffff;
height:50px;
padding:10px;
text-shadow: 1px 1px 5px #909090;
}

div.redYouAreHereBar {
background-color:#ff0000;
height:50px;
padding:10px;
font-size:xx-large;
color: #ffffff;
text-shadow: 2px 2px 5px black;
}


div.white {
background-color:#ffffff;
}

div.red {
background-color:#ff0000;
}

div.teal {
background-color: #008080;
}

div.lightGray {
background-color: #D1D0CE;
}

div.grayTransparent {
background-color: #837E7C;
opacity:0.2;
filter:alpha(opacity=20); /* For IE8 and earlier */
}

div.darkGray {
background-color: #404040;
}

div.whiteTransparent {
background-color: #ffffff;
opacity:0.7;
filter:alpha(opacity=70); /* For IE8 and earlier */
}

div.blackBorder {
border:2px solid black;
}

div.blackHorizontalLine {
border-bottom:2px solid black;
}

适用于我的解决方案

我将此添加到css

span.navigationSpace {
    padding-left: 50px;
}

我也对此进行了测试,它也有效(作为替代解决方案):

span.navigationSpace {
    margin-left: 50px;
}

我以为我已经尝试了这些,但也许我只需要删除我的缓存以显示更改并且我以某种方式错过了它?

我选择了Roy的答案,因为它让我尝试了这个。我比其他答案更喜欢这个解决方案,因为它将文本样式与布局样式分开,更加模块化。 (而另一个答案在最右边有一个边缘,我更倾向于没有。)

1 个答案:

答案 0 :(得分:8)

a.navigation-link {
  padding: 0px 10px;
  word-wrap: normal;
  display: inline-block;
}

padding的完整语法为top right bottom left,但有一些简写,您可以在MDN上详细了解。我在上面的示例中使用了top-bottom right-left(所以0px用于顶部和底部,10px用于左侧和右侧。