css - 使用 CSS 和 HTML 定位文本和图像

标签 css text-formatting

您好,我目前正在制作一个简单的网站以获得更多 HTML 和 CSS 经验,目前我在页眉中的位置存在一个简单的问题。我试图让 Logo 和文本位于特定位置,但我不知道如何利用我的 CSS 技能有效地实现它。基本上我目前有这个:

Current Version

这是我想要的带有 Logo 的文本格式: Photoshop version

我不确定如何在 CSS 中设置此格式,并且一直在 W3 学校上查找信息以获取信息并且学到了很多但还不足以令人遗憾地解决这个问题。我可以找出与所需版本相匹配的颜色样式,但我无法弄清楚如何将文本和 Logo 放置在它们应该位于的位置。

这是我目前拥有的 CSS 和 HTML(非常基础):

#header {
    background-color:#011836;
    color:#ECE7E7;
    padding-top: 5px;
    padding-left: 5px;
    padding-right: 5px;
    padding-bottom: 5px;
    line-height: .1px;
}
.logo{
    position: relative;
    left: 5px;
    top:5px;
    bottom:0px;
}
.headerText{
    text-indent: 160px;
    bottom:20px;
    font-family: "Verdana";
  
}
#nav {
    line-height:30px;
    background-color:#179fe8;
    color:white;
    height:50px;
    padding: 5px;
}
.button{
    background-color: #179fe8;
    border: none;
    color: white;
    padding: 15px 25px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 12px;
    margin: 4px 4px;
    cursor: pointer;
    -webkit-transition-duration: 0.4s;
    transition-duration: 0.4s;
}

.button2:hover{
    box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
#section {
    width:350px;
    float:left;
    padding:10px;
}
#footer {
    background-color:#011836;
    color:white;
    font-family: "Verdana";
    clear:both;
    text-align:center;
    padding:5px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>

<div id="header">

    <img class="logo" src="http://imgur.com/O2qNi6p" alt="Clarence White Logo" width="168" height="168">

    <h1 class="headerText" style= "display:inline;">BIOENGINEERING CLUB </h1>
    <h5 class="headerText">UNIVERSITY OF MAINE</h5>
</div>

<div id="nav">
<button href="about.html" class="button button2">ABOUT</button>
<button href="projects.html" class="button button2">PROJECTS</button>
<button href="resume.html" class="button button2">RESUME</button>
</div>

<div id="section">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.</p>
</div>

<div id="footer">

</div>

</body>
</html>

任何关于如何更好地实现样式的指导将不胜感激!请耐心等待我,我正在重新学习这一切,感谢您抽出宝贵时间!

最佳答案

#header {
  background-color:#011836;
  color:#ECE7E7;
  padding: 5px;
  position:relative;             /* ADDED */
}
#header:after{                   /* ADDED */
  content:"";
  display: table;
  clear:both;
}
.headerText{                     /* CHANGED */
  position:absolute;
  bottom:0;
  left:200px;
}
.logo{
  position: relative;
  float:left;                    /* ADDED */
  left: 5px;
  top:5px;
}

#nav {
  line-height:30px;
  background-color:#179fe8;
  color:white;
  height:50px;
  padding: 5px;
}
.button{
  background-color: #179fe8;
  border: none;
  color: white;
  padding: 15px 25px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 12px;
  margin: 4px 4px;
  cursor: pointer;
  -webkit-transition-duration: 0.4s;
  transition-duration: 0.4s;
}

.button2:hover{
  box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
#section {
  width:350px;
  float:left;
  padding:10px;
}
#footer {
  background-color:#011836;
  color:white;
  font-family: "Verdana";
  clear:both;
  text-align:center;
  padding:5px;
}
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
  </head>
  <body>

    <div id="header">

      <img class="logo" src="http://imgur.com/O2qNi6p" alt="Clarence White Logo" width="168" height="168">
      <div class="headerText"> <!-- CREATED AN ABSOLUTE POS. PARENT -->
        <h1>BIOENGINEERING CLUB </h1>
        <h5>UNIVERSITY OF MAINE</h5>
      </div>
    </div>

    <div id="nav">
      <button href="about.html" class="button button2">ABOUT</button>
      <button href="projects.html" class="button button2">PROJECTS</button>
      <button href="resume.html" class="button button2">RESUME</button>
    </div>

    <div id="section">
      <h2>London</h2>
      <p>London is the capital city of England. It is the most populous city in the United Kingdom,
        with a metropolitan area of over 13 million inhabitants.</p>
      <p>Standing on the River Thames, London has been a major settlement for two millennia,
        its history going back to its founding by the Romans, who named it Londinium.</p>
    </div>

    <div id="footer">

    </div>

  </body>
</html>

关于css - 使用 CSS 和 HTML 定位文本和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514818/

相关文章:

ruby - 如何在 Ruby 中将数组数组转换为一个字符串

css - CSS 中的双冒号 (::) 是什么意思?

css - 使用 css 显示其他元素时捕获元素

html - HTML 和 CSS 宽度属性有什么区别?

Java改变系统换行符

python - 未找到打印搜索的问题

html - 不要使用 CSS 缩进第一段的第一行

css - Windows 上的 Firefox 10 上带有边框的奇怪行为

javascript - 如何在需要时突出显示替代隐藏复选框输入的复选框伪元素

javascript - 如何在 JavaScript 中输出带有前导零的数字?