Ali Ali - 4 months ago 10
HTML Question

how to show each two <p> in one line inside a div

i have a loop inside a jsp page , for each element of my arrayList i print a pragraph, this my code :

<% for(object ob:myList){ %>
<p> <%=ob.getName()%></p>
<%}%>


this code show me a lot of paragraphs, but each paragraph in one row, my issue is : how to show each two paragraphs in one line

thanks in advance.

Answer

In order to have two paragraph tags in 1 line you need some css:

p { 
    display: inline-block;
    width: 50%;
}

or

p { 
    float: left;
    width: 50%;
}

The 50% width is for 2 <p>'s to be on the same row and take half of the width.

Hope that helps.

.

Update

https://jsfiddle.net/v6sjq5jj/1/

.

Second update

Or use table-row and table-cell, which is the best-solution in my opinion and it is for multiple p tags. https://jsfiddle.net/v6sjq5jj/2/