1

I am stuck on this as the div with an id "img-section" below does not properly work in my css file. For some reason,CSS stylings are not applied to #img-section but instead, #bottom-section wraps the entire section of the imgs that I cannot independently change any of the bottom section inside divs.

Here is my html and CSS which strangely work by having a border on the very top of the img section and right below another border in the title section. I want this border to appear on the bottom of the img section but no luck.

<html>
<head>
    <title>hello</title>
    <meta charset = "utf-8" />
    <style type="text/css">

  img {
    width:30%;
    float:left;
    margin: 1.66%
  }

  #title-section {

    font-family:serif;
    font-size:15px;
    text-align:center;
    text-transform:lowercase;
    margin-left:1.66%;
    margin-bottom:10px;
    border-bottom:7px solid black;
    border-top:7px solid black;
    width:96.68%;

      }

/*  hr {border-top:7px solid black;
    width:96.68%;
    margin-left:1.66%;

  }*/

  #bottom-section {
    border-top:7px solid black;
    width:96.68%;
    margin-left:1.66%;
  }


</style>

</head>

<body>
<div id="title-section">
  <h1 >h e l l o</h1>

  <h3 ><ins>[ ma - own - compilation - of - all - things - cool ]</ins></h3>

  <h4>by Mimicat</h4>
</div>

<div id="img-section">
   <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_04_1024x1024.jpg?1060797035744706564" >
   <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_03_1024x1024.jpg?4506725020023455500" >
   <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_05_1024x1024.jpg?3752376622799079790" >
     <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_04_1024x1024.jpg?1060797035744706564" >
   <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_03_1024x1024.jpg?4506725020023455500" >
   <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_05_1024x1024.jpg?3752376622799079790" >
     <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_04_1024x1024.jpg?1060797035744706564" >
   <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_03_1024x1024.jpg?4506725020023455500" >
   <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_05_1024x1024.jpg?3752376622799079790" >
</div>


  <div id="bottom-section">
      <form>
          <p><strong>Did you enjoy this collection?</strong></p>
          <p>Hell yeah! <input type="checkbox" checked> Nah - <input type="checkbox"> </p>
          <p><input type="submit"></p>
      </form>
  </div>
</body>
</html>

Anything wrong with my code? How can I fix this problem? I want to make a border under images or on the top of the div#bottom-section, but when I put border-top inside #bottom-section, it creates a border right below the div#title-section instead, and it drives me nuts. Any suggestions? Thank you!

Bobby
  • 1,585
  • 3
  • 19
  • 42
Mimicat
  • 21
  • 6

4 Answers4

2

The issue is that all the child elements of #img-section are floated, so #img-section has no height. To fix this you need what is referred to as a "clearfix" some examples here. Working example of your code here

JustH
  • 1,372
  • 8
  • 8
1

Have you tried using:

<div class="img-section">

rather than an id? Then in css:

.img-section{
}

Also, do you have a copy of your css? Just so we can see if there is anything unusual going on there.

LJW
  • 11
  • 1
  • I did change it to div.img-section as you suggested, but I am in no luck. For some reason, my css file does not recognize it and again, the div#bottom-section wraps the entire img section :( I have just added my CSS file :) – Mimicat Jul 02 '16 at 01:38
1

Your images float so you will want/need to clearfix their container.

.clearfix:after {
    content:"";
    display:block;
    clear:both;
}

#title-section {
  font-family: serif;
  font-size: 15px;
  text-align: center;
  text-transform: lowercase;
  margin-left: 1.66%;
  margin-bottom: 10px;
  border-bottom: 7px solid black;
  border-top: 7px solid black;
  width: 96.68%;
}

img {
  width: 30%;
  float: left;
  margin: 1.66%
}

#bottom-section {
  border-top: 7px solid black;
  width: 96.68%;
  margin-left: 1.66%;
}
<div id="title-section">
  <h1>h e l l o</h1>
  <h3>
    <ins>[ ma - own - compilation - of - all - things - cool ]</ins>
  </h3>
  <h4>by Mimicat</h4>
</div>

<div id="img-section" class="clearfix">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_04_1024x1024.jpg?1060797035744706564">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_03_1024x1024.jpg?4506725020023455500">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_05_1024x1024.jpg?3752376622799079790">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_04_1024x1024.jpg?1060797035744706564">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_03_1024x1024.jpg?4506725020023455500">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_05_1024x1024.jpg?3752376622799079790">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_04_1024x1024.jpg?1060797035744706564">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_03_1024x1024.jpg?4506725020023455500">
  <img src="http://cdn.shopify.com/s/files/1/0698/9609/files/PSNY_RUNWAY_05_1024x1024.jpg?3752376622799079790">
</div>


<div id="bottom-section">
  <form>
    <p><strong>Did you enjoy this collection?</strong>
    </p>
    <p>Hell yeah!
      <input type="checkbox" checked>Nah -
      <input type="checkbox">
    </p>
    <p>
      <input type="submit">
    </p>
  </form>
</div>
JonSG
  • 10,542
  • 2
  • 25
  • 36
  • The same answer was posted before! – Aboozar Rajabi Jul 02 '16 at 02:48
  • @AboozarRajabi, your downvote is inappropriate. This answer was posted within seconds of the one you commented on. I saw it only after I posted my answer. I would have deleted my answer except with an onsite working example, it is clearly better. – JonSG Jul 02 '16 at 14:31
0

Use <hr> between those two sections. You can change its style and use it like:

<hr style="margin:8px auto">
Aboozar Rajabi
  • 1,683
  • 21
  • 26
  • Thanks for the tip! But I'd like to know why my code doesn't work properly. If I used hr and change its display to none, still the same problem occurs. If I style it like the border I wanted to have, it looks slightly odd in the edge. Why is this happening? :( – Mimicat Jul 02 '16 at 02:02
  • This is not a useful answer. Clearing floats with a trailing HR tag while technically possible is not done in practice as better methods have existed for years. – JonSG Jul 02 '16 at 14:42
  • @JonSG Thanks for your comment, if you know any better methods rather than using `clearfix`, let us know – Aboozar Rajabi Jul 02 '16 at 15:53
  • 1
    @AboozarRajabi, This article has a summary of techniques to clear floats including several "clearfix" implementations and the "overflow" method. http://stackoverflow.com/questions/211383/what-methods-of-clearfix-can-i-use This article has a future fix using contain-floats https://www.sitepoint.com/clearing-floats-overview-different-clearfix-methods/ – JonSG Jul 02 '16 at 16:08
  • @JonSG Thanks, it's useful – Aboozar Rajabi Jul 02 '16 at 22:26