2

enter image description here

we are using below code to display text in one line and image in below line.

what i tried is position : relative: top: xxpx; bottom: xxpx; but i think its bad way of coding.

enter image description here

html

<div class="cc51">
   <?php echo $this->__('Add/Change Background color'); ?>
   <div class="cc55"><img src="<?php echo $this->getSkinUrl('images/circle.PNG') ?>" alt="image upload button" /></div>
   <br/>
</div>

css

.cc51 {
     margin-top: 40px;
     font-size: 24px;
}
.cc55 {

}
fresher
  • 917
  • 2
  • 20
  • 55

9 Answers9

3

Just add inline-flex

cc51{
   display:inline-flex;
 }

use above code in your css or you can use below css

or you can also use below css.

     .cc51{
       float:left;
     }
     .cc55{
       float:right;
     }
     .cc54{
        clear:both;
     }
Sagar Kodte
  • 3,723
  • 4
  • 23
  • 52
  • please check here also : http://stackoverflow.com/questions/39719035/display-dropdown-menu-items-in-next-column – fresher Sep 27 '16 at 09:53
1

You can either use (on the text element like , add class to "Add/Change Background colour")

display: inline-block;

Or you can float the elements to the left/right

float: left;

Just don't forget to clear the floats after

clear: left;

Ave
  • 4,338
  • 4
  • 40
  • 67
1

use

.cc51
{
 margin-top: 40px;
 font-size: 24px;
 display:flex;
 align-text:center;
}

this way the image will be aligned centered to the text

see here : jsfiddle

Mihai T
  • 17,254
  • 2
  • 23
  • 32
1

Please try to add following css

.cc51 {
  margin-top: 20px;
  font-size: 24px;
  float: left;
}
.cc55 {
  float: right;
}
vignesh
  • 951
  • 5
  • 13
1

You can use display: inline-block for both text and image to show in one line.

.cc51 .text,
.cc51 .cc55 {
  display: inline-block;
  vertical-align: top;
}
<div class="cc51">                  
  <div class="text">Add/Change Background color</div>
  <div class="cc55">
    <img src="<?php echo $this->getSkinUrl('images/circle.PNG') ?>" alt="image upload button"/>
  </div>
</div>
Mohammad Usman
  • 37,952
  • 20
  • 92
  • 95
1

I went on the site you've linked in the post and the following code works:

.cc55 {
   display: inline-block;
   vertical-align: middle;
}
Ivan
  • 34,531
  • 8
  • 55
  • 100
1

Set position (float) as per you requirement

cc51 img{
     display:inline; float:right; vertical-align: middle;
 }
1

The best way if you need to support older browsers is simply like this, where the white-space: nowrap; keep them in 1 line even on smaller screen sizes

.cc51 {
  font-size: 24px;
  white-space: nowrap;
}
.cc55 {
  display: inline-block;
  vertical-align: middle;
}
<div class="cc51">                  
  Add/Change Background color
  <div class="cc55"><img src="http://placehold.it/35/f00" alt="image upload button"/>
  </div>
</div>

And you could drop the inner div

.cc51 {
  font-size: 24px;
  white-space: nowrap;
}
.cc51 img {
  vertical-align: middle;
}
<div class="cc51">                  
  Add/Change Background color
  <img src="http://placehold.it/35/f00" alt="image upload button"/>  
</div>

Even the img could be dropped

.cc51 {
  font-size: 24px;
  white-space: nowrap;
}
.cc51:after {
  content: url(http://placehold.it/35/f00);
  vertical-align: middle;
  display: inline-block;
}
<div class="cc51">                  
  Add/Change Background color
</div>
Asons
  • 84,923
  • 12
  • 110
  • 165
1

You can use display:inline-flex

.cc51
 {
     display:inline-flex;
 }
<div class="cc51">                  
             Add/Change Background color          
            <div class="cc55"><img src="<?php echo $this->getSkinUrl('images/circle.PNG') ?>" alt="image upload button"/></div>
            <br/>
</div>
Lemon Kazi
  • 3,308
  • 2
  • 37
  • 67