Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two inline-block elements always on same line

Tags:

css

I have two elements that i always want to show in a single line. First element has 100% available width up to maximum of 350px and second has fixed with of 150px.

When width of parent (or browser) is reduced I want first element's width to get reduced to adjust both elements in same line, but second element moves to next line

Here is a sample code:

span {
    height: 30px;
    display: inline-block;
 }
.span1 {
    background: red;
    max-width: 350px;
    width: 100%;
}
.span2 {
    background: blue;
    width: 150px;
}
<span class="span1"></span>
<span class="span2"></span>
like image 251
dusk7 Avatar asked Jun 21 '26 00:06

dusk7


1 Answers

Hm ok, here is an example:

span {
  height: 30px;
  display: inline-block;
  margin-right: -.25em;
}
.span1 {
  background: red;
  width: 350px;
  max-width: calc(100% - 150px);
}
.span2 {
  background: blue;
  width: 150px;
}

I'm not sure if I understand you right. Here is a fiddle: http://jsfiddle.net/cmy45soz/

Ciao Ralf

like image 57
RWAM Avatar answered Jun 23 '26 18:06

RWAM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!