Arranging 2 divs side by side

As a beginner, I'm struggling to find the answer because I have no idea what search terms to use.

Now, I have a form

        <form action="#" method="POST">
            <div id="labels">
    <label>CMS System</label><p>
    <label>Responsive Design</label><p>
    <label>Google Package+</label><p>
    <label>Google Ranking</label><p>
    <label>Slider/Slideshow</label><p>
    <label>Social Media</label><p>

<div id="input">
<input type="text" name="page" value="1"><p>
Yes<input type="radio" name="cms" id="cmsyes" value="yes"/> No<input type="radio" name="cms" value="no" id="cmsno" checked/><p />
Yes<input type="radio" name="Responsive" value="yes"/> No<input type="radio" name="Responsive" value="no" checked/><p />
Yes<input type="radio" name="Googlepkg" value="yes"/> No<input type="radio" name="Googlepkg" value="no" checked/><p />
Yes<input type="radio" name="Googlerank" value="yes"/> No<input type="radio" name="Googlerank" value="no" checked/><p />
Yes<input type="radio" name="slideshow" value="yes"  /> No<input type="radio" name="slideshow" value="no" checked/><p />
Yes<input type="radio" name="socials" value="yes" id="socialyes" /> No<input type="radio" name="socials" value="no" id="socialno" checked/><p />
            </div>
    </form>

I would like

#input {
      move next to #labels instead of being below it

}

I tried using margin: -xxxpx; but I understand that is not the correct way to achieve this.

JSFiddle http://jsfiddle.net/tAVGC/

Answer №1

http://example.com/CAT65/

#categories { float: right; margin-left: 12px; }

Don't forget to close your tags properly.

On the topic of styling with ids, I suggest using classes instead. Check out this blog post by Sarah Smith for some great insights and additional resources.

Answer №2

Here are a couple of things to note:

Make sure your <div id="labels" > has a closing tag like </div>.

Remember that <p> tags require both an opening and closing tag, such as <p></p>

Consistency is key - ensure every element receives a <p> tag if you want them aligned properly. Consider using the following markup for side-by-side display in HTML:

<label>CMS System</label><input type="radio" name="cms" />

If you prefer separate <div> containers, you can try this approach:

http://jsfiddle.net/sk6gz/1/

There may be a discrepancy between the elements. To achieve the desired result, consider adding an extra <p> tag in either the first or second <div> container.

Answer №3

Are you attempting to create your own CMS system?

If you want to master CSS styling for positioning elements, I recommend researching the css box model. This will provide valuable information on how to arrange elements horizontally.

As for your current issue, it seems like you are aiming for a layout similar to this example: JSFiddle

To solve your problem, make sure to group each label with its corresponding control (radio button) in the markup:

<label>CMS System</label>
Yes<input type="radio" name="cms" id="cmsja" value="yes"/> 
No<input type="radio" name="cms" value="no" id="cmsno" checked="checked" />
<br/>

I included a <br/> element for quick spacing, but utilizing the box model will offer more precise positioning options.

Additionally, exploring topics like html forms may be beneficial for your project.

Consider starting with smaller projects as a beginner before tackling a full-fledged CMS.

Answer №4

When it comes to styling form elements, this approach can be quite effective:

HTML:

<label>Content Management System</label><input type="radio" name="cms" />
<label>Your thoughts</label><input type="text" name="thoughts" />

CSS:

label, input[type=text] { display:inline-block; text-align: right; }
label { width: 30%; margin-right: 2%; }
input, input[type=text] { width: 60%; }

The radio buttons don't require a set width, but I included the text input to demonstrate how you could further enhance the styling of forms.

For a visual example, check out this link: http://jsfiddle.net/harveyramer/E7kSt/

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

When jQuery adds new elements, their CSS may not be applied accurately

One issue I encountered is using jQuery to dynamically add new elements, only to find that the CSS isn't being applied correctly to the newly added element. To illustrate this problem, I created a jsFiddle. In the example, there are differences in sp ...

Adjust the text size to fit perfectly within the boundaries of a textarea input field

Is there a way to ensure that users type within a specific area with formatting and returns in a textarea element? I'm looking for a solution that limits overflow and ensures users stay within the designated area. How can this be achieved? I am worki ...

Redirecting visitors to a specific section of the website as soon as they enter the site

Currently, I am utilizing a jquery plugin known as Ascensor which can be found at this link: This plugin is designed for creating one-page websites with smooth scrolling capabilities both vertically and horizontally. It operates using a coordinate system ...

How can I convert the left links in my navigation bar to a CSS drop-down menu to make it more responsive on small screens?

Here is the structure of my HTML (at the top): <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></s ...

AngularJS: Click on image to update modelUpdate the model by clicking

I am a newcomer to AngularJS and I am attempting to update my model after the user clicks on an image. Below is the code for this: <div class="col-xs-4 text-center"><a ng-model="user.platform" value="ios"><img src="ios.png" class="img-circl ...

Transitioning from Webpack version 4 to version 5 resulted in a failure to detect certain styles

After migrating my React project to Webpack v5, I am facing an issue where none of my .scss files are being picked up when I run the project. I meticulously followed the guide on migrating webpack https://webpack.js.org/migrate/5/, updated all plugins and ...

Passing a parameter from AJAX to PHP

const studentNumber = $('#studno').val(); $(document).ready(function () { $('.go').click(function () { $('.inup').load('prochat.php', { studno: studentNumber }); }); }); I've ...

The boundary of embedded components

I am looking for CSS code that will allow me to arrange all elements with specific indents, such as placing the first element on the left side of the page, followed by an image with some indentation, and so on. <div class="container-fluid"> &l ...

Pretending to determine the exact height of the body

I am facing a challenge with my JavaScript application that is loaded within an iframe through a Liferay portlet. The HTML container is currently empty and the JS is loaded only when the document is fully loaded. Upon loading the page in the iframe, Lifer ...

The hover effect for a :before class is not functioning as intended

I have created a dropdown menu with a triangle at the top in this style: When the cursor hovers over only the triangle, it appears like this: However, when the cursor is over the div, the hover effect for both elements is activated as shown here: I am t ...

Transfer information from the client to the server using AJAX and PHP by

When attempting to post a JavaScript variable called posY to a PHP file, an error occurred with the message: Notice: Undefined index: data in C:\xampp\htdocs\Heads_in_the_clouds\submitposY.php The posY variable is defined in the JavaSc ...

An error with rendering in Internet Explorer 8

When I hide a td in a table by setting its display to none, the table does not resize correctly when using IE8. If I have a table and want to remove an entire column, I might try something like this: $("th:first, th:last, tr td:first-child, tr td:last-ch ...

Slideshow elements removed

I attempted to remove my links individually from the div id="wrapper", but unfortunately have encountered an issue while doing so: window.onload = function () { setInterval(function () { var wrapper = document.getElementById("wrapper"); var my_l ...

What is the best way to retrieve information from a data set?

After borrowing some basic HTML, CSS, and JavaScript code from CodePen, I ran into an issue while attempting to convert it to React. The error message says that it cannot read properties of null (specifically 'dataset'). Here is the JavaScript c ...

creating unique styles for your Ionic app with Angular using JSON

Having trouble changing the item color. Does anyone know why my CSS isn't working, or if I'm missing something? <ion-view title="Add order to a table"> <ion-content class="has-header has-subheader"> <ion-list> ...

Using jquery to toggle active nav links in Bootstrap

I'm currently working on integrating a jQuery function to automatically update the active status of the navigation links in my Bootstrap Navbar. The structure involves a base HTML file that extends into an app-specific base file, which is further exte ...

`Animate your divs with slide in and slide out effects using

Currently, I am in the process of replicating a website and facing some challenges. This site is my inspiration for the project. I have managed to create a sliding effect using CSS, making the div slide in and out from the same direction. However, I want ...

Navigation that remains fixed while scrolling

Can someone help me fix the side navigation of this template to stay fixed when a user scrolls past it for easier navigation? I'm struggling with the code and could use some fresh eyes to look at it. I just can't seem to figure it out on my own, ...

Is there a way to align the Title in the Titlebar to the center?

Hi there! I could use some assistance :) I have an Electron app and I'm working on the title bar. I would like to center the title, but I'm not sure how to do it. Can anyone provide guidance on this? Also, since I am a beginner, I'm unsure i ...

Switching Symbols with JQuery

Hello, I am brand new to utilizing javascript and I'm currently experimenting with the toggle function. My goal is to create show/hide functionality while also toggling arrow icons. Specifically, I want a right arrow next to the link "More -->" and ...