CSS将标语添加到标题中

时间:2016-07-22 23:34:10

标签: html css

我有一个标题包含一个网站名称(在左侧部分)和一个水平导航菜单(在右侧部分)。我的目标是在网站名称下添加一个口号。同时,网站名称的底部仍应与菜单元素的底部完全匹配,唯一的变化就是添加口号。

以下是我的标题和带有预期结果的图片:https://jsfiddle.net/1nc9ch3x/1/

请给我一个如何弄明白的提示。提前谢谢!



body {
  background: url(http://i.imgur.com/Asbdvgw.png);
  font-family: 'Open Sans', sans-serif;
}
header {
  width: 950px;
  margin: auto;
  position: relative;
  background: #fff;
  overflow: hidden;
}
.wrapper {
  width: 950px;
  margin: 0 auto;
}
header .logo {
  display: inline;
  border-left: 1px dashed #333333;
  padding: 0 0 25px 10px;
  text-decoration: none;
  float: left;
  font-size: 30px;
  color: #cc3333;
  margin: 25px 0px;
}
header nav {
  float: right;
  margin: 25px 0px;
}
header nav ul {
  margin-top: 0px;
}
header nav ul li {
  display: block;
  float: left;
}
header nav ul li a {
  text-decoration: none;
  color: #333333;
  font-size: 17px;
  padding-top: 15px;
  padding-bottom: 15px;
  transition: all .2s linear;
  -webkit-transition: all .2s linear;
  -moz-transition: all .2s linear;
  -o-transition: all .2s linear;
}
header nav ul li a.active,
header nav ul li a:hover {
  color: #cc3333;
  border-top: 1px dashed #cc3333;
  border-bottom: 1px dashed #cc3333;
}
header li {
  display: inline;
  border-left: 1px dashed #cc3333;
  padding: 10px 25px 10px 25px;
}
header li:first-child {
  border: none;
}

<header>
  <div class="wrapper">
    <div class="logo">
      Name
    </div>
    <nav>
      <ul>
        <li><a href="#">Category 1</a>
        </li>
        <li><a href="#">Category 2</a>
        </li>
        <li><a href="#">Category 3</a>
        </li>
        <li><a href="#">Category 4</a>
        </li>
      </ul>
    </nav>
  </div>
</header>

<br>
<br>
<center><font color="#fff">My goal:</font>
  <br>
  <br>
  <img src="http://i.imgur.com/aW7k0QI.png">
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:1)

要实现您想要的就像将以下代码放在 <div class="logo"> 中一样简单:

<p id = "slogan">Slogan should be right here</p>

然后,您可以进入CSS文件并对 #slogan 进行必要的更改。如下所示:

#slogan {
    color: #0c0c0c;
    font-size: 16px;
    display: block;
    margin-top: 5px;
}

您可以查看this working demo或以下代码段。

<强>段:

&#13;
&#13;
body {
  background: url(http://i.imgur.com/Asbdvgw.png);
  font-family: 'Open Sans', sans-serif;
}
header {
  width: 100%;
  height: 100px;
  margin: auto;
  position: relative;
  background: #fff;
  overflow: hidden;
}
.wrapper {
  width: 950px;
  margin: 0 auto;
}
header .logo {
  display: inline;
  border-left: 1px dashed #333333;
  padding: 0 0 25px 10px;
  text-decoration: none;
  float: left;
  font-size: 30px;
  color: #cc3333;
  margin: 25px 0px;
}
header nav {
  float: right;
  margin: 25px 0px;
}
header nav ul {
  margin-top: 0px;
}
header nav ul li {
  display: block;
  float: left;
}
header nav ul li a {
  text-decoration: none;
  color: #333333;
  font-size: 17px;
  padding-top: 15px;
  padding-bottom: 15px;
  transition: all .2s linear;
  -webkit-transition: all .2s linear;
  -moz-transition: all .2s linear;
  -o-transition: all .2s linear;
}
header nav ul li a.active,
header nav ul li a:hover {
  color: #cc3333;
  border-top: 1px dashed #cc3333;
  border-bottom: 1px dashed #cc3333;
}
header li {
  display: inline;
  border-left: 1px dashed #cc3333;
  padding: 10px 25px 10px 25px;
}
header li:first-child {
  border: none;
}

#slogan {
  margin-top: 5px;
  color: #0c0c0c;
  font-size: 16px;
  display: block;
}
&#13;
<header>
  <div class="wrapper">
    <div class="logo">
      Name
      <p id="slogan">Slogan should be right here</p>
    </div>

    <nav>
      <ul>
        <li><a href="#">Category 1</a>
        </li>
        <li><a href="#">Category 2</a>
        </li>
        <li><a href="#">Category 3</a>
        </li>
        <li><a href="#">Category 4</a>
        </li>
      </ul>
    </nav>
  </div>
</header>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

这应该可以解决问题:左小提琴:https://jsfiddle.net/1nc9ch3x/3/
HTML:

<div class="logo">
   Name<span>Slogan</span>
</div>

CSS:

header .logo {
  position:relative;
}
header .logo span {
  white-space:nowrap;
  color:black;
  font-size:18px;
  position:absolute;
  bottom:0;
  left:10px;
}

答案 2 :(得分:0)

Here是一个更新的小提琴。

关键CSS:

https://graph.facebook.com/v2.7/search?type=adgeolocation&location_types=["city"]&country_code=US&q=hou&access_token= 

和HTML:

header .slogan {
  color: #000;
  font-size: 20px;
  display: block;
}

答案 3 :(得分:0)

获取代码:

HTML:

<header>
  <div class="wrapper">
    <div class="logo">
      <h4>
      Name
      </h4>
      <p>your slogan here</p>


    </div>
    <nav>
      <ul>
        <li><a href="#">Category 1</a></li>
        <li><a href="#">Category 2</a></li>
        <li><a href="#">Category 3</a></li>
        <li><a href="#">Category 4</a></li>
      </ul>
    </nav>
  </div>
</header>

<br><br>
<center><font color="#fff">My goal:</font><br><br>
<img src="http://i.imgur.com/aW7k0QI.png">

的CSS:

body { 
    background: url(http://i.imgur.com/Asbdvgw.png);
    font-family: 'Open Sans', sans-serif;
  margin:0;
}

header {
    width: 950px;
    margin: auto;
    position: relative;
    background: #fff;
    overflow: hidden;
}

.wrapper {
    width: 950px;
    margin: 0 auto;
}
header .logo{
  border-left: 1px dashed #333333;
  padding:5px 10px;
}
header .logo h4{

    padding: 0px ;
    text-decoration: none;
    font-size: 30px;
    color: #cc3333;
    padding: 10px;
  padding-bottom:0;
}
.logo h4{
  margin:0;
  padding:0;
}
.logo p{
  color:rgba(0,0,0,0.7);
  margin:0;
  padding:0 10px;
}
header nav{
    position:absolute;
    right:0;
    top:0;
    margin: 0px 0px;
}

header nav ul{
    margin: 0px;
}

header nav ul li{
    display: block;
    float: left;
    margin: 0px;
}

header nav ul li a{
    text-decoration: none;
    color: #333333;
    font-size: 17px;
    padding-top: 15px;
    padding-bottom: 15px;
    transition: all .2s linear;
    -webkit-transition: all .2s linear;
    -moz-transition: all .2s linear;
    -o-transition: all .2s linear;
}

header nav ul li a.active,
header nav ul li a:hover{
    color: #cc3333;
    border-top: 1px dashed #cc3333;
    border-bottom: 1px dashed #cc3333;
}

header li {
display: inline;
border-left: 1px dashed #cc3333;
padding: 10px 25px 10px 25px;
}

header li:first-child {
border: none;
}