mr chon
mr chon

Reputation: 125

how to create a responsive line in css?

I want to draw a line and make sure the line resizes to fit the screen size, and the point of line should always stick to the paragraph. Something like this:

enter image description here

Is there any way to add the line so it will point to the div all the time? I did small research and found that using border-right: 1px solid #000000; is used for list, how can I do the same for div?

This is my code:

.jumbotron {
  /*  background-color: #353535;*/
  /* background-image: url("https://unsplash.it/1440/736/?random");*/
  background-size: cover;
  color: #fff;
  /*   padding: 155px 25px;*/
  padding-bottom: 200px;
  font-family: Montserrat, sans-serif;
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<div class="container">
  <div class="jumbotron text-center">
    <h1>company name </h1>
    <div calss="line" style="    border-bottom: 5px solid #000000;">
      <div class="col-sm-6">
        <h2 class="usertype">For Businesses</h2>
        <p> Authentication .</p>
        <a href="#" class="btn btn-default">Try It Now</a>
      </div>
      <div class="col-sm-6">
        <h2 class="usertype">For Individuals</h2>
        <p>For Google, Facebook, Coinbase .</p>
        <a href="#" class="btn btn-default">Download App</a>
      </div>
    </div>
  </div>
</div>

Upvotes: 1

Views: 10292

Answers (3)

Ram kumar
Ram kumar

Reputation: 3162

Here is in example. Please have a look

* {
  box-sizing: border-box;
}

body {
  background: #fff;
}

.intro {
  position: relative;
}

.main-heading:before {
  width: 5px;
  position: absolute;
  left: 50%;
  bottom: 0;
  height: 20px;
  background: #000;
  content: '';
  transform: translate(-50%, 0);
}

.main-heading {
  text-align: center;
  font-size: 30px;
  line-height: 30px;
  position: relative;
  padding-bottom: 25px;
  border-bottom: 5px solid #000;
}

.two-col:after {
  display: block;
  clear: both;
  content: '';
}

.two-col .col {
  float: left;
  width: 50%;
  position: relative;
  padding: 0 20px;
}

.sub-heading {
  position: relative;
  display: inline-block;
  padding: 20px 0;
}

.sub-heading:before {
  width: 10px;
  position: absolute;
  left: 50%;
  top: 0;
  height: 20px;
  background: #000;
  content: '';
  transform: translate(-50%, 0);
}

.sub-heading:after {
  position: absolute;
  background: #fff;
  top: -5px;
  left: -9999px;
  content: '';
  right: 50%;
  height: 25px;
}

.two-col .col:last-child {
  text-align: right;
}

.two-col .col:last-child .sub-heading:after {
  right: -9999px;
  left: 50%;
}
<div class="intro">
  <div class="main-heading">Company Name</div>
  <div class="two-col">
    <div class="col">
      <div class="sub-heading">For Business</div>
    </div>
    <div class="col">
      <div class="sub-heading">For Individuals</div>
    </div>
  </div>
</div>

here is fiddle link also https://jsfiddle.net/gafnk4rg/

Upvotes: 3

Alvaro Montoro
Alvaro Montoro

Reputation: 29645

One possible solution:

  • Move the line one level down.
  • Make it occupy only 50% of the width and center it (that way it will go from center to center of both columns).
  • Add :before and :after to make the vertical lines.
  • Hide the line when in xs because of the way your menu is styled it starts in sm.

Here is a demo (click on "Full page" button to see the effect):

.jumbotron {
  background-size: cover;
  color: #fff;
  padding-bottom: 200px;
  font-family: Montserrat, sans-serif;
}
.line {
  border-bottom:4px solid #000000;
  width:50%;
  margin:auto auto;
  position:relative;
}
.line:before {
  content:"";
  position:absolute;
  top:-15px;
  left:50%;
  height:15px;
  border-left:4px solid #000000;
}
.line:after {
  content:"";
  position:absolute;
  top:0;
  left:0;
  border-left:4px solid #000000;
  border-right:4px solid #000000;
  width:100%;
  height:20px;
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<div class="container">
  <div class="jumbotron text-center">
    <h1>company name </h1>
    <div>
      <div class="line hidden-xs"></div>
      <div class="col-sm-6">
        <h2 class="usertype">For Businesses</h2>
        <p> Authentication .</p>
        <a href="#" class="btn btn-default">Try It Now</a>
      </div>
      <div class="col-sm-6">
        <h2 class="usertype">For Individuals</h2>
        <p>For Google, Facebook, Coinbase .</p>
        <a href="#" class="btn btn-default">Download App</a>
      </div>
    </div>
  </div>
</div>

Upvotes: -1

khushboo29
khushboo29

Reputation: 916

You can use horizontal rule: "hr". It is responsive.

Please refer

How to draw lines through Bootstrap vertical dividers?

Upvotes: 0

Related Questions