Ways to showcase floating items in a single row without using tables

I need help to align float elements in a single line without resorting to tables. As the user resizes the browser window, the elements currently break onto separate lines which is not the desired outcome.

Here is the HTML code snippet I am using:

<ul class='regul'>
<li>First name:</li>
<li>Last name:</li>
<li>Email:</li>
<li>Confirm email:</li>
<li>Password:</li>
<li>Confirm password:</li>
<li>Sex:</li>
<li>Date of birth:</li>
<li><input class='button' type='submit' name='action' value='Register' /></li>
</ul>
<ul class='regul'>
<li><input type='text' name='fname' id='fname' /></li>
<li><input type='text' name='lname' id='lname' /></li>
<li><input type='text' name='email' /></li>
<li><input type='text' name='cemail' /></li>
<li><input type='password' name='pass' /></li>
<li><input type='password' name='cpass' /></li>
<li><select name='sex'><option value='male'>Male</option><option value='female'>Female</option></select></li>
<li>
<input type='text' name='day' size='2' maxlength='2' />
<input type='text' name='month' size='2' maxlength='2' />
<input type='text' name='year' size='4' maxlength='4' />
</li>
</ul>

You can visit my website at .

Any advice on which CSS code I should implement would be greatly appreciated.

Thank you for your assistance!

Answer №1

Here is a snippet of code that you can use:

<style>
.regul{
float:left;
list-style:none;
}
.regul li{
height:25px;
width:150px;
}
</style>
<div style="width:500px;clear:both;">
<ul class='regul'>
<li>First name:</li>
<li>Last name:</li>
<li>Email:</li>
<li>Confirm email:</li>
<li>Password:</li>
<li>Confirm password:</li>
<li>Sex:</li>
<li>Date of birth:</li>
<li><input class='button' type='submit' name='action' value='Register' /></li>
</ul>
<ul class='regul'>
<li><input type='text' name='fname' id='fname' /></li>
<li><input type='text' name='lname' id='lname' /></li>
<li><input type='text' name='email' /></li>
<li><input type='text' name='cemail' /></li>
<li><input type='password' name='pass' /></li>
<li><input type='password' name='cpass' /></li>
<li><select name='sex'><option value='male'>Male</option><option value='female'>Female</option></select></li>
<li>
<input type='text' name='day' size='2' maxlength='2' />
<input type='text' name='month' size='2' maxlength='2' />
<input type='text' name='year' size='4' maxlength='4' />
</li>
</ul>
</div>

Answer №2

To align elements side by side, apply float:left. And don't forget to include style='clear:both' on another element afterward.

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

Issue with Colspan in Nested Tables in Bootstrap 4.1.3

I'm dealing with an issue related to colspan within a nested table. I've tried various solutions, including wrapping the table in a div, but nothing seems to be working as expected. My goal is to have the nested table span across the entire width ...

Can you inherit from a class in a different file using SASS?

All the information needed is in this question. For example, if I decide to utilize Twitter Bootstrap, would it be possible for me to create classes in my own SASS stylesheet that inherit from Bootstrap's CSS classes? Or is SASS inheritance restricte ...

Dynamic motion of balloons using jquery technology

I am trying to make an image move smoothly inside a div using jQuery and CSS. I have tried rotation and animation, but nothing has worked the way I need it to. <div class="baloon" style="position:fixed;left:0px;top:160px;"> <img id="rot" class="r ...

The rating and comment section is failing to adapt to smaller screens, creating a terrible user experience

I am a beginner with Sass and CSS. I wanted to create a rating and comment section which looks fine on a laptop screen, but appears off on smaller screens. It seems like the layout might be incorrect or maybe I didn't follow grid layout guidelines pro ...

Adjusting the width of a Material UI select/dropdown component

In my material-ui grid setup, each <Grid> contains a <Paper> element to define the grid's boundaries precisely. Inside every <Paper>, there is a custom <DropDown> component (a modified version of Material-UI's Select). I ...

How to position collapsible buttons in Twitter's Bootstrap framework

I have successfully created two buttons on the same line. The second button is collapsible and when clicked, it adds a row of two more buttons to the view. However, the newly collapsed row of buttons appears aligned with the second button. I would like th ...

Aligning HTML Headings Vertically with CSS Baseline

I am looking to align two columns of headings to the baseline, with each having a different font size. Additionally, I want one column on the left side and the other on the right side. To achieve this, using display: inline-block will ensure that they are ...

Is it possible to implement Photoshop-inspired color curves filters on an HTML tag?

I am attempting to recreate the color curves filter from Photoshop using an HTML video tag. https://i.stack.imgur.com/erB1C.png The solution closest to what I need so far is how to simulate Photoshop's RGB levels with CSS and SVG Filters, but it doe ...

Using JQuery's $.post function can be unreliable at times

Looking for help with a function that's giving me trouble: function Login() { var username = document.getElementById('username').value; var password = document.getElementById('password').value; $.post("Login.php", { ...

Fixing the hydration error in Next 13 can be challenging, especially when it occurs outside of a Suspense boundary

Encountering an issue while working with Next.js 13: Error: Hydration failed because the initial UI does not match what was rendered on the server. Warning: Expected server HTML to contain a matching <div> in <html>. Every time I attempt to r ...

Steps to replace the content of an HTML file (such as modifying images) by clicking on an element in a separate HTML file

Currently, I am in the midst of a project and wondering if it is possible to dynamically modify the content of an HTML file, such as images and text, using JavaScript. My goal is to achieve this without relying on any frameworks, simply by clicking on el ...

Could jQuery and CSS be utilized for image enlargement?

Is it possible for jQuery (or CSS!) to detect an area around the mouse when hovering over an image, capture the image underneath, and then zoom in on that area? This concept differs from typical jQuery zoom effects where there are two separate images - sm ...

Transform the query results into clickable links

Is there a way to automatically turn specific results fetched from a MySQL $row into hyperlinks? For example, if I fetch the website Google.com in a search query, is there a method for making it an active hyperlink that goes directly to Google.com when cli ...

Is there a way to adjust the transparency of individual words in text as you scroll down a page, similar to the effect on https://joincly

Is there a way to achieve a text filling effect on page scroll similar to the one found here: . The specific section reads: "Deepen customer relationships. Own the brand experience. Add high margin revenue. Manage it all in one place. Get back your pr ...

The function in jQuery that can be used to hide a <div> when clicked

I am facing a problem with my jQuery code that is supposed to remove/hide a specific div. Despite checking various examples, I can't seem to make it work properly. This issue arises in the context of jQuery on Drupal 7. The live site where this proble ...

What are the best techniques for using jQuery to manipulate an HTML form that contains nested elements?

I have a scenario where I need to dynamically generate mini-forms within an empty form based on certain conditions. For instance, imagine a form that gathers information about restaurants such as their names and locations. Depending on the number of restau ...

Retrieve CSS height using Jquery, based on the declared value rather than the computed value

In a previous version of jQuery, the default behavior was different. When I use .css("height") and .height(), it gives me the computed height instead of what I actually want. I only need the height value if it is explicitly declared in the CSS for that ele ...

Is there a way to duplicate a specific quantity of icons with Polymer?

I am facing a bit of a challenge with a seemingly simple task. My goal is to showcase the number of credits completed by each student in my list using star icons. For instance, John ★, Sarah ★★, Ken ★, and Jared ★★★★. The JSON data contai ...

Is it possible to click on the second item in a list based on its Span class using Selenium?

self.driver.find_element_by_xpath("//span[@class='bog']").click() This is the current code I am using. It allows me to click on the first email in my Gmail inbox. However, I now want to be able to click on the second or third email. I am struggl ...

Is it possible to have Mobile WebKit store the click position?

I am in the process of developing a unique framework specifically designed for WebKit devices. One of the features I have implemented is a series of list views that activate a 'hover' class when users touch them. Below is the jQuery/JavaScript co ...