Tips for including vertical lines within text boxes to distinguish elements

I've been working on a simple form using CSS and HTML, but I'm struggling to add vertical lines to separate my text from the radio buttons. Right now, I'm just using '|' to divide them, but it's not the most visually appealing solution. How can I make sure the vertical lines extend all the way from the top of the text box to the bottom?

<!DOCTYPE html>
<html>
<head>
<style>
.box1 {
width: 300px;
height: 20px;
padding: 5px;
border: 1px solid black;
margin: 0;
float: left
}

input[type=radio] {
  display: inline;
}


</style>
</head>
<body>


<div class="box1">

<form method="GET" action="." target="new">
 Up Down |
 <input type="radio" name="option" id="r1" value="1" />
 <label for="r1">Up</label>
 <input type="radio" name="option" id="r2" value="2" />
 <label for="r2">Down</label>
 |
 <input type="submit" />
</form>
</div>
</body>
</html>

Answer №1

I would opt not to rely on table elements for layout in this scenario (unless I am presenting tabular data) due to its lack of semantic value. Instead, utilizing flexbox would be a more suitable approach.

display: flex;

.box1 form {
  width: 300px;
  border: 1px solid black;
  margin: 0;
  display: flex;
}

.col {
  display: inline-block;
  border-right: 1px solid black;
  padding: 5px;
}

.col:last-child {
  border-right: none;
}

.col.input-control {
  padding-right: 20px;
}
<div class="box1">

  <form method="GET" action="." target="new">
    <label class="col">Up Down</label>
    <span class="col input-control">
      <input type="radio" name="option" id="r1" value="1" />
      <label for="r1">Up</label>
      <input type="radio" name="option" id="r2" value="2" />
      <label for="r2">Down</label> 
    </span>
    <span class="col">
      <input type="submit" />
    </span>
  </form>
</div>

Answer №2

To enhance the presentation of your content, consider designing a table and incorporating HTML inputs along with labels.
Additionally, applying CSS style to the table can greatly improve its visual appeal.

Answer №3

To enhance your radio buttons, consider enclosing them within a div element and applying borders to the left and right sides.

https://jsfiddle.net/krbp8tx7/

.box1 {
  height: 20px;
  padding: 5px;
  border: 1px solid black;
  margin: 0;
  float: left
}

input[type=radio] {
  display: inline;
}

.separateradios {
  display: inline-block;
  border-left:1px solid #000;
  border-right:1px solid #000;
  padding: 0 0.2em;
}
<body>
  <div class="box1">

    <form method="GET" action="." target="new">
      Up Down
      <div class="separateradios">
        <input type="radio" name="option" id="r1" value="1" />
        <label for="r1">Up</label>
        <input type="radio" name="option" id="r2" value="2" />
        <label for="r2">Down</label>
      </div>
      <input type="submit" />
    </form>
  </div>
</body>

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

There is a significant distance between the columns, causing the text to appear misaligned and not left-

I'm encountering an issue with the alignment of a row with two columns. The first column contains an image, and the second column contains text. However, the text is not aligning properly next to the image. <link href="https://cdn.jsdelivr.net/ ...

Guide to transforming Tailwind CSS into a class and saving it in a CSS document

Recently, I implemented Tailwind CSS to style my application. It has been a helpful tool, but I am looking to consolidate all the CSS into one file for better organization. I want to keep it separate from the HTML code. My attempt to convert the following ...

Extracting Tailwind color palette through API request

After conducting some research, I have not been able to find a definitive answer to my query. I possess a CMS API that supplies branding colors and other assets for a React application that can dynamically change its appearance using a combination of colo ...

Tips for eliminating checkboxes from a form

function addCheckbox(){ var labels = document.form1.getElementsByTagName('label'); var lastLabel = labels[labels.length-1]; var newLabel = document.createElement('label'); newLabel.appendChild(Checkbox(labels.length)); ...

Clicking on a button in HTML to open a JavaScript file

As a beginner in HTML and JavaScript, I am looking for a way to open a JavaScript file when the onclick event of a button in my HTML file is triggered. Can anyone provide me with guidance on how to achieve this? Thank you in advance. ...

There appears to be a CSS problem cropping up on the right side of my website

Kindly pay a visit to the following URL: dev.dgconcepts.com.pk https://i.stack.imgur.com/sBC4Dm.jpg I am puzzled by the fact that whenever we swipe left or right on mobile responsive, the website shifts slightly on both sides. I am unable to identify ...

Is there a way to have the menu displayed on a single line and consistently centered?

I am working on a menu that needs to stay centered at the top of the screen, with a consistent appearance and just one line, regardless of the screen width. However, I'm encountering an issue where the menu mysteriously transitions into a two-line for ...

Remove the "href" from Zend2 navigation functionality

When using Zend2 navigation from an array passed in Zend\Navigation\Navigation, everything works smoothly if child items are opened on parent item mouse hover. However, undesirable actions occur when they are opened on mouse click, as the user is ...

Python script for handling unclickable buttons using Selenium

Having trouble clicking a button with Selenium: Here is the HTML code for each side: "plus de 26 ans" https://i.sstatic.net/ntvmy.png "Moins de 26 ans" https://i.sstatic.net/6jD0m.png Tried using Selenium to create a button clicke ...

Avoiding text from overflowing a DIV when the parent DIV's width is specified as a percentage

After extensively searching through over 20 similar posts, I have not been able to find a solution that works for my specific issue. The layout of some content I'm working with resembles the example provided here: Check out the Fiddle Example In th ...

What is the best way to set the width of an iframe within a <td> element to be 33% of the screen?

I am facing an issue with scaling an iframe dynamically inside a <td> element. My goal is to make the iframe occupy 33% of the screen width while automatically adjusting its height. Here is what I have tried: <iframe src="google drive presentati ...

Tomcat: jamming out to some tunes

My web application includes a feature to play audio files uploaded to the server. I'm using the following code for this: <object id="MediaPlayer" type="application/x-oleobject" height="42" standby="Installing Windows Media Player..." width="138" a ...

What is the best method for enlarging the central image in Owl Carousel?

Could someone help me with implementing Owl Carousel to achieve this design? I have attempted it, but unfortunately, it is not working as expected. Your assistance in fixing the issue would be greatly appreciated. Please find the necessary code below: ...

Can you add descriptive text below a linked image?

I am currently working with a customized CMS created specifically for our company. My goal is to insert text below the image displayed. Ideally, I would like the text to be centered within the border of the image if possible. I have limitations in that I ...

I am facing an issue where the weather information is not being displayed even after sending a request to

I'm working on building an app that will provide users with weather data once they input a city. Utilizing the openweathermap.org API for this purpose, I've noticed in my console under networks that an API call is made when the city is entered, b ...

My HTML Won't Recognize the CSS File

Despite trying various paths and browsers, I am unable to link my CSS file to my HTML file. When inspecting the page elements and checking under resources, the CSS file does not appear. Here is a snippet of my HTML: <html> <head> <meta ...

What is the best way to replicate touch functionality on mobile browsers for both Android and iPhone devices?

Recently, while developing a web application, I ran into an issue on mobile browsers where the :active pseudo class wasn't functioning properly. I am currently utilizing CSS sprites and looking for guidance on how to simulate clicks for mobile browser ...

PHP programming language for opening, editing, and saving HTML files

Trying to use PHP to open an HTML file, remove the content of a specific div (class Areas), and then save it. $dom = new DOMDocument; $dom->loadHTMLFile( "temp/page".$y.".xhtml" ); $xpath = new DOMXPath( $dom ); $pDivs = $xpath->query(".//div[@class ...

Adjust the background color of the container when transitioning to a new slide in a Slick carousel

I am using a Slick slider where each slide has its own background color. The container color is set to white, but I want the container color to change instantly to match the color of the currently active slide when swiping or changing slides. This is my J ...

Arranging inline-flex elements within a div container

I have been struggling to position two elements side by side within a single div, where the second element should be on the right side. <div className={classes.container}> <div className={classes.first}> First </div> <d ...