0

I just want the 2nd div to display a bottom border. I either get both divs displaying a bottom border or none at all.

.container {
  width: 75%; overflow: hidden;
  border: 0;
}
.container div:nth-child(1) {
  width: auto; float: left; height: 25px;
  padding: 5px 20px;
  background-color: white; 
}
.container div:nth-child(2) {
  margin-left: auto; height: 25px;
  padding: 5px 20px;
  background-color: ghostwhite;    
  border-bottom: 1pt solid black;
}
<div class="container">
  <div>Div Left</div><div>Div Right</div>
</div>
Patrick
  • 315
  • 1
  • 8
  • 27

1 Answers1

1

Use display:inline-block, instead of float as float allows the second div to occupy space behind the first.

.container {
  width: 75%;
  overflow: hidden;
  border: 0;
}
.container div:nth-child(1) {
  width: auto;
  height: 25px;
  padding: 5px 20px;
  background-color: white;
  display: inline-block;
}
.container div:nth-child(2) {
  margin-left: auto;
  height: 25px;
  padding: 5px 20px;
  background-color: ghostwhite;
  border-bottom: 1pt solid black;
  display: inline-block;
}
<div class="container">
  <div>Div Left</div>
  <div>Div Right</div>
</div>
j08691
  • 204,283
  • 31
  • 260
  • 272