Pushkal Singh
Pushkal Singh

Reputation: 57

How to make a short horizontal line over an image?

I am trying to draw a short horizontal line over an image. Like a quote followed by horizontal line followed by author name. An example of what I'm trying to do is below.

Quote with line separating author name

How can I achieve this in html css?

Upvotes: 0

Views: 2736

Answers (3)

Gacci
Gacci

Reputation: 1398

You can do it in several way. How you go about it will depend on what you are trying to accomplish. Here are two ways; one using br element and the other using a div (it could be a label too). If you want to use a different color and add more style to it, you want to go with the div

.motto, .author{
      display: block;
      text-align: center;
    }
    .motto{
      font-size: 1.85em;
    }
    .br{
      width: 50%;
      height: 2px;
      margin: 25px auto;
      border-radius: 2px;
      background-color: #0088ee;
    }
<i class="motto">It is better to be feared than loved if you cannot be both</i>

<div class="br"></div>
<!-- <hr/> -->

<strong class="author">Niccolo Machiavelli</strong>

Comment out <div class="br"></div> and uncomment <hr/> to see the two results.

Upvotes: 0

Andrei Voicu
Andrei Voicu

Reputation: 750

You can use either an hr or a div with a border. I made a simple example, hope it helps.

html, body{
 height: 100%
}

body{
 background: lightslategray;
 display: flex;
 justify-content: center;
 align-items: center;
 margin: 0;
}

.quote {
  background: url('http://lorempixel.com/g/600/200/abstract/?random=true');
  color: white;
  background-size: cover;
  padding: 2rem;
  text-align: center;
}

hr {
  width: 40%;
}
<div class="quote">
  <h1>A dream doesn't become reality through magic<br/> it takes sweat, determination and hard work.</h1>
  <hr />
  <h2>Colin Powell</h2>
</div>

Upvotes: 1

Brix Angeles
Brix Angeles

Reputation: 61

you can use the horizontal line in html <hr>

Upvotes: 0

Related Questions