What is the best way to create a centered vertical line with text in the middle?

I attempted to replicate a form that contains a vertical line

<span  class="vertical-line">or</span>
with text centered in it! How can I create a similar appearance like

this form? I considered using hr but it generates a horizontal line instead of a vertical one. Maybe if we apply some CSS to rotate it, but I'm unsure of the best approach. Here's what I have experimented with so far:

* {
  box-sizing: border-box;
}

header {
  background-color: rgb(147, 88, 134);
  width: 100%;
  height: 65px;
}

.tit2 {
  float: right;
  color: white;
  margin-right: 70px;
  font-size: 20px;
  padding: 7px;
  margin-top: 10px;
}

.tit1 {
  float: left;
  color: white;
  font-weight: bold;
  font-size: 25px;
  margin-left: 100px;
  margin-top: 10px;
}

.goo {
  background-color: red;
  color: white;
  width: 200px;
  height: 50px;
}

.face {
  background-color: rgb(27, 122, 255);
  color: white;
  width: 200px;
  height: 50px;
}

.git {
  background-color: black;
  color: white;
  width: 200px;
  height: 50px;
}

.git,
.face,
.goo {
  margin: 10px;
  text-align: center;
  font-weight: bold;
  border-radius: 8px;
}

h1 {
  color: rgb(186, 183, 183);
  text-align: center;
  padding-top: 10px;
}

#login {
  background-color: rgb(147, 88, 134);
  color: white;
  text-align: center;
  border-radius: 4px;
  width: 140px;
  height: 50px;
  font-weight: bold;
  margin: 7px;
}

.botona2 {
  border: 1px solid black;
  border-radius: 2px;
  width: 250px;
  height: 50px;
  padding: 20px;
  margin: 10px;
}

.tout {
  border: 2px solid rgb(235, 235, 235);
  border-radius: 15px;
  width: 80%;
  height: 400px;
  margin: auto;
  margin-top: 80px;
  box-shadow: 5px 10px 18px 10px #dbdbdb;
}

.vertical-line {
  border-left: 2px solid #000;
  display: inline-block;
  height: 130px;
  margin-right: 20px;
}
<header>
  <p class="tit1">Simo App</p>
  <p class="tit2">Login</p>
</header>
<div class="tout">
  <h1>Choose a Login Method</h1><br><br>
  <div class="row">
    <div class="col-sm-6">
      <button class="goo"> Google</button><br>
      <button class="face">Facebook</button><br>
      <button class="git">Github</button><br>
    </div>
    <span class="vertical-line">or</span>
    <div class="col-sm-5">
      <form>
        <label><input type="text" placeholder="Username" class="botona2"></label><br>
        <label><input type="password" placeholder="Password" class="botona2"></label><br>
        <label><input type="submit" value="Login" id="login"></label>
      </form>
    </div>
  </div>
</div>

Answer №1

To place text over a line, you can use the CSS property position: absolute;

.wrapper {
  position: relative;
  width: 250px;
  height: 300px;
}

.line {
  position: absolute;
    top: 0;
  bottom: 0;
    left: 50%;
    transform: translateX(-50%);
  width: 1px;
    background-color: grey;
}

.word {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
  text-transform: uppercase;
  padding: .5em;
  background-color: #fff;
    border: 1px solid grey;
    border-radius: 50px;
}
<div class="wrapper">
  <div class="line"></div>
  <div class="word">or</div>                                      
</div>

Answer №2

To optimize the mobile version, you should incorporate a full-size column (12) in between two col-sm-6 elements. Align everything to the center and create a circle design as usual. For screens larger than SM, apply absolute positioning to the new block to avoid affecting the bootstrap grid layout. Center-align it using flexbox and adjust margins as needed to maintain spacing integrity with adjacent content blocks. The slight screen overlap is due to existing content size and compliance with the bootstrap grid system.

Note: This method specifically caters to layouts with two columns only. If more columns or items are added, the absolute positioning strategy may require modifications. However, this adjustment is unlikely to impact the current setup significantly as it's not tied to incremental listing rules.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to make an HTML link target the same as JavaScript window.opener?

Within my project, the main page is where users log in and access the primary tables. Additionally, there are numerous supplementary pages that open in separate windows. Once the login session times out, it is essential to restrict user access to any cont ...

Grow your website horizontally rather than vertically for a unique user experience

When I align divs to the right, they start stacking up and crowding on top of each other. When there are more than 4 divs, the fifth one jumps below the rest as the page expands downward. I want to prevent this from happening. Instead, I would like the h ...

Delete all pictures beginning with this specific ID from the posts

Currently, I have approximately 300 Wordpress posts, and each one contains a "tracking pixel" from a previously used service (which is implemented using IMG tags). This is an example of how it appears: <img id="serviceTrack_3274570" style="margin: 0px ...

CSS: Adjusting the vertical alignment of numbers in an ordered list

Hey there, I have a question about the vertical alignment of numbering in an ordered list. It seems that the numbers are being pushed to the baseline when <li> elements contain floated divs only. Is there any way to prevent this and have the numbers ...

What is the method for obtaining the WordPress user ID?

I am looking to incorporate a Twitter follow button for all site authors on every post. Below is the structure of the Twitter button: <a href="https://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="false" data-lang="en">Foll ...

What is the best way to ensure the options/choices div reaches its ideal width?

Check out my StackBlitz project that I've set up In the styles.css file, you'll notice that I defined a fixed width of 650px for the option dropdown div, which is currently working fine @import '~bootstrap/dist/css/bootstrap.min.css'; ...

CSS: Obtain a button and align it to the "a" element

Feeling a bit puzzled: https://i.stack.imgur.com/S7xKh.png In the image, there's a span button labeled "Navigation einblenden", and a span a tagged as "Suche". Despite styling them identically: In the CSS snippet, dispOpts is the parent span's ...

How can you enable fullscreen for a featherlight iFrame?

I have implemented Featherlight to display an iframe within a popup modal on my website. If you click the iframe button, you can see a demo of how it works. One issue I am facing is that the generated iframe tag by Featherlight does not include allowfulls ...

Interactive game created using JavaScript input

I've scoured the internet for guidance on creating a text-based game that utilizes user input, but all I come across are tutorials focusing on button interactions. What I envision is triggering different responses based on specific user inputs. For i ...

Mastering the Cache-Manifest file configuration for optimal performance

I am experiencing a problem where even though I have my cache manifest, my website is not functioning correctly. Currently, I am working with Visio 2012, using asp.net MVC. Here are the steps I have taken so far: I created a file called Manifest.manifes ...

Tool to identify your network location: Local domain and network status checker

Is there a way to determine if a user is accessing our site from within our local network or from the broader internet? For example, imagine someone scans a QR code at our restaurant that leads to a page designed to check whether they are connected locall ...

AngularJS - Show Banner after two rows, then show two more rows

I'm attempting to showcase a Banner <div> after 2 rows of 4 x "col-md-3", succeeded by another 2 Rows - thus, resulting in the following markup: <div class="col-md-3">1</div> <div class="col-md-3">2</div> <div clas ...

Retrieve data from json files

After retrieving this object from my controller, I have a name, a list of beans, and a list of operations: { "name": "Charge", "beans": [ ], "operations": [ { "name": "getSize", "returnType": "java.lang.Integer", "descriptio ...

Develop a stylish contact form using a mixture of HTML5, Bootstrap, and Php

On my website, I have created a contact us form using HTML, Bootstrap, and PHP. The form functions correctly, and messages are successfully received. However, the issue is that upon clicking the submit button, a new page opens up displaying a "Thank you me ...

Is there a way to ensure that text is always displayed at the bottom of an image, perfectly aligned with the left edge of the image, regardless of the parent alignment?

I'm working on creating a layout in HTML/CSS/Bootstrap with an image and text below it. The challenge is to ensure that the text always starts at the left border of the image, regardless of its length. Here's what I need the layout to look like: ...

Tips for incorporating Javascript in an innerHTML inline css situation

I'm just starting to learn about html5 and php. I'm curious about how to incorporate javascript into my existing code. Currently, I have data from a database displayed in an HTML table. My goal is to align the output of the last cell more toward ...

Achieving Right Alignment of SVG Next to an <h4> in Bootstrap 5

I'm encountering an issue where I am attempting to align an SVG icon to the right of an H4 element and center it vertically using Bootstrap 5, but it's not working as intended. <div class="container-fluid"> <div class="r ...

Having trouble displaying DIV Content with CSS through printing

<script type="text/javascript"> function PrintElem(elem) { Popup($(elem).html()); } function Popup(data) { var mywindow = window.open('', 'mydiv', 'height=550,width=750'); mywindow.doc ...

Show a button using CSS when the cursor is hovering

Expressing my gratitude to everyone! I need assistance with implementing a function in reactJS where the <button /> remains hidden during page loading and reveals itself when hovered over. Despite trying various methods, I have been unable to resolve ...

I prefer to avoid generating the document structure while parsing with JSOUP

Utilizing the Jsoup API to parse a section of HTML using the Jsoup.parse() method. However, during parsing, it includes the document structure in the HTML content. For Instance: <p><a href="some link">some link data</a> Some paragraph c ...