Jon2713 Jon2713 - 3 months ago 20
CSS Question

Text stuck in middle of div instead of far left

As you can see i goes straight to the middle instead of the starting point of the div. I have set a

margin
and
width
for my
div
and when I do input an
<H1>
tag, the text just
floats
to the middle of the
div
instead of the far left where the
div
begins. I have set the
width
so it can start at that starting point not
45px
to the left.

This is the HTML

<div id="topbar">
<div id="logo"> <img src="Pictures/bbc.png"> </div>
<div id="signin" class="border-part"> </div>
<div> <img id="logo-image" src="Pictures/signin.png">
<p class="signin-text">Sign in</p>
</div>
<div id="dash"> <img id="dash-image" src="Pictures/bash2.png"> </div>
<div> <img id="bell"src="Pictures/bell3.png"> </div>
<div class="border-part stuff-section"> News </div>
<div class="border-part stuff-section"> Sport </div>
<div class="border-part stuff-section"> Weather </div>
<div class="border-part stuff-section"> iPlayer </div>
<div class="border-part stuff-section"> TV </div>
<div class="border-part stuff-section"> Radio </div>
<div class="border-part stuff-section"> More </div>
<div class="seacher-border">
<input id="search-box" type="text" placeholder="Search">
<img id="search-pic" src="Pictures/search.png"> </div>
</div>
<div id="second-bar">
<div id="newsbar">
<h1>NEWS</h1>
</div>
</div>


This is my CSS

#topbar {
width: 1080px;
margin: 0 auto;
height: 40px;
}
body {
margin: 0;
padding: 0;
font-family: Helmet, Freesans, Helvetica, Arial, sans-serif;
;
}
#logo {
margin-top: 8px;
float: left;
margin-right: 8px;
}
.border-part {
float: left;
height: 100%;
border-left: 1px #CCCCCC solid;
}
#logo-image {
width: 20px;
margin: 12px;
float: left;
}
.signin-text {
margin: 14px;
font-size: 90%;
font-weight: bold;
float: left;
}
#dash-image {
padding-left: 50px;
float: left;
height: 40px;
}
#bell {
margin: 8px;
height: 28px;
float: left;
}
.stuff-section {
font-weight: bold;
font-size: 90%;
padding: 13px 15px 0 15px;
height: 27px;
}
.seacher-border {
float: left;
height: 100%;
border-left: 1px #CCCCCC solid;
margin-left: 20px;
}
#search-box {
margin: 10px;
font-weight: bold;
background-color: #E4E4E4;
font-size: 14px;
border: none;
height: 24px;
float: left;
}
#search-pic {
position: relative;
right: 10px;
top: 10px;
height: 25px;
}
#second-bar {
background-color: #BB1919;
width: 100%;
height: 80px;
}
#newsbar {
width: 1080px;
margin: 0 auto;
background-color: blue;
}
h1 {
padding: 0;
margin: 0;
float;
}

Answer

Just add clear: both to h1:

#topbar {
  width: 1080px;
  margin: 0 auto;
  height: 40px;
}

body {
  margin: 0;
  padding: 0;
  font-family: Helmet, Freesans, Helvetica, Arial, sans-serif;
  ;
}

#logo {
  margin-top: 8px;
  float: left;
  margin-right: 8px;
}

.border-part {
  float: left;
  height: 100%;
  border-left: 1px #CCCCCC solid;
}

#logo-image {
  width: 20px;
  margin: 12px;
  float: left;
}

.signin-text {
  margin: 14px;
  font-size: 90%;
  font-weight: bold;
  float: left;
}

#dash-image {
  padding-left: 50px;
  float: left;
  height: 40px;
}

#bell {
  margin: 8px;
  height: 28px;
  float: left;
}

.stuff-section {
  font-weight: bold;
  font-size: 90%;
  padding: 13px 15px 0 15px;
  height: 27px;
}

.seacher-border {
  float: left;
  height: 100%;
  border-left: 1px #CCCCCC solid;
  margin-left: 20px;
}

#search-box {
  margin: 10px;
  font-weight: bold;
  background-color: #E4E4E4;
  font-size: 14px;
  border: none;
  height: 24px;
  float: left;
}

#search-pic {
  position: relative;
  right: 10px;
  top: 10px;
  height: 25px;
}

#second-bar {
  background-color: #BB1919;
  width: 100%;
  height: 80px;
}

#newsbar {
  width: 1080px;
  margin: 0 auto;
  background-color: blue;
}

h1 {
  padding: 0;
  margin: 0;
  clear: both;
}
<div id="topbar">
  <div id="logo"> <img src="Pictures/bbc.png"> </div>
  <div id="signin" class="border-part"> </div>
  <div> <img id="logo-image" src="Pictures/signin.png">
    <p class="signin-text">Sign in</p>
  </div>
  <div id="dash"> <img id="dash-image" src="Pictures/bash2.png"> </div>
  <div> <img id="bell" src="Pictures/bell3.png"> </div>
  <div class="border-part stuff-section"> News </div>
  <div class="border-part stuff-section"> Sport </div>
  <div class="border-part stuff-section"> Weather </div>
  <div class="border-part stuff-section"> iPlayer </div>
  <div class="border-part stuff-section"> TV </div>
  <div class="border-part stuff-section"> Radio </div>
  <div class="border-part stuff-section"> More </div>
  <div class="seacher-border">
    <input id="search-box" type="text" placeholder="Search">
    <img id="search-pic" src="Pictures/search.png"> </div>
</div>
<div id="second-bar">
  <div id="newsbar">
    <h1>NEWS</h1>
  </div>
</div>