Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align a span and a div on the same line

Tags:

html

css

I have the following HTML:

<div class="mega_parent">
<div class="parent">
<div class="holder">
    <span class="holder_under">Left heading</span>
    <div class="holder_options">
        <span class="holder_options_1">Option 1</span> 
        <span class="holder_options_2">Option 2</span> 
        <span class="holder_options_3">Option 3</span>
    </div>
</div>
</div>
</div>

and the following CSS:

.holder {
    background-color: blue;
    padding: 10px;
}
.holder_under {
    padding-left: 10px;
    font-size: 16px;
    color: #999;
}
.parent {
    float: left;
    margin-right: 20px;
    width: 600px;
}
 .mega_parent {
background-color: blue;
    margin: 130px auto;
    min-height: 320px;
    height: 100% auto;
    overflow: auto;
    width: 940px;
    padding: 0px 10px;
}

Question:

How do I make the div with the class holder_options align in the same line as the span with the class .holder_under?

Here's what it looks like currently in jsFiddle.

like image 909
starbucks Avatar asked May 20 '13 15:05

starbucks


People also ask

How do I display a div and SPAN in one line?

In the wrapping div you should have: display: flex; align-items: center; and remove the display property from both elements.

How do you align two items on the same line?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.

Can a div be inside a span?

As all phrasing content is flow content, it means phrasing element can be used in all of flow content. The phrasing elements can only contain other phrasing elements, for example, you can't put div inside span.

Can you use text align with SPAN?

Use a p or div rather than a span. Text is an inline element and so is a span. For text-align to work, it must be used on a block level element (p, div, etc.) to center the inline content.


1 Answers

Div's are by default block level elements. Please read up more about block level elements here.

"Block level elements - Their most significant characteristic is that they typically are formatted with a line break before and after the element (thereby creating a stand-alone block of content)."

Set it to display:inline-block;

.holder_options {
  display:inline-block;
}

Working jsFiddle here.

like image 62
dsgriffin Avatar answered Nov 09 '22 22:11

dsgriffin