What's the HTML to have a horizontal space between two objects?

I have been searching for an answer and trying different things without success. Could someone kindly let me know how to put spaces between two objects by using PHP code? (Please note: I use WordPress, in case that makes a difference.)

I know how to do so vertically with </br>, but what is the horizontal equivalent to that?

Please note that I don't know a whole lot about code, so any detailed information you are able to provide is very much appreciated in advance - thank-you very much!

5

9 Answers

I guess what you want is:

&nbsp;

But this is usually not a nice way to align some content. You better put your different content in

<div>

tags and then use css for proper alignment.


You can also check out this post with useful extra info:

1

You should put a padding in each object. For example, you want a space between images, you can use the following:

img{ padding: 5px;
}

That means 5px paddin for ALL sides. Read more at . By the way, studying a lot before attempting to program will make things easier for you (and for us).

CSS

div.horizontalgap { float: left; overflow: hidden; height: 1px; width: 0px;
}

Usage in HTML (for a 10px horizontal gap)

<div></div>
1

PHP does not do styling. You need to use html or css. Take a look at

In HTML 4.01, the


tag represents a horizontal rule.
In HTML 4.01, the <hr> tag represents a horizontal rule.
11

<div> looks nice, but a bit complicated in setting all these display: block, float: left... Maybe because the general idea behind <div> is a block of a paragraph size or more.

I have found the following nice way for spacing:

<button>Button 1></button>
<button>Button 2</button>

I think what you mean is putting 2 paragraphs (for example) in 2 columns instead of one below the other? In that case, I think float is your solution.

<div> <!-- would cause this to hang on the left -->
<div> <!-- would cause this to hang on the right-->

Here's an example:

Well, this is probably frowned upon but you can make a 1px transparent image, then size it as needed in between text.

Some text <img src="spacer.png" height="1px" width="10px"> Some more text

I've run into this issue when one or two spaces just wasn't enough for my design sensibilities.

You could use the old ways. And use a table. In the table you define 3 columns. You set the width of your whole table and define the width of every colum. that way you can horizantaly space 2 objects. You put object one inside cell1 (colum1, row1) and object2 in cell3 (colum 3, row 1) and you leave cell 2 empty. Given it has a width, you will see empty spaces. example

<table width="500"> <tr> <td width="40%"> Object 1 </td> <td width="20%"> </td> <td width="40%"> Object 2 </td> </tr>
</table>

Or you could go the better way with div's. Just put your objects inside divs. Add a middle div and put these 3 divs inside another div. At the css style to the upper div: overflow: auto and define a width. Add css style to the 3 divs to define their width and add float: left example

<div> <div> Object 1 </div> <div> </div> <div> Object 2 </div>
</div>
1

Another way you can add horizontal space between elements is to set up labels to preserve spaces in css:

label { white-space: pre;
}

..and then add a label with as many spaces as you want:

<label> </label>

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like