user2879704
user2879704

Reputation:

Icon next to text/span appears in the next line on mouse hover

I need to show an edit icon next to the text (inline), when user hovers mouse over it. When i hover over the text, the edit icon is falling in the next line.

My span is taking up the 100% of div width, even though i have set it to 80% width and the rest 20% width is reserved for the right side icon.

Span style is,

span{
display: inline-block;max-width:80%;width:80%;
}

It looks like,

enter image description here

How can i display the icon inline, at the right end in the same line as the text? Plunker code is here.

Upvotes: 0

Views: 1229

Answers (2)

Maihan Nijat
Maihan Nijat

Reputation: 9355

span is inline element by default and you cannot add width to it unless you display it as block.

<div>
  <span style="display:inline-block; width:80%;">Hello Hello Hello</span>
  <i style="display:inline-block; padding-left:5px;float: right;   border-left: solid black 1px; width: 15%;">ICON</i>
</div>

Upvotes: 0

mmativ
mmativ

Reputation: 1414

You can do like this.

$('document').ready(function(){
     console.log('document ready callback fn is invoked')
     $('.menu-body').hide()
   })
   $('body').on('click', '.drp-down-btn', function(){
     $('.menu-body').toggle()
   })
.cntr{
   width: 20%;
   overflow: hidden;
   white-space: nowrap;
   display: block;
 }
 .cntr  i {
   visibility: hidden;
   opacity: 0;
   transition: all 0.4s;
   -webkit-transition: all 0.4s;
   cursor: pointer;
 }

<!-- .cntr:hover{
   border: solid black 1px;
 } -->
 .cntr:hover > i{
      display: inline-block;
 }
 .cntr>span>p{
   width: 15%;
   overflow:hidden;
   vertical-align:middle;
   text-overflow: ellipsis;
   white-space: nowrap;
 }
.cntr span,.cntr p,.cntr i{
    display: inline-block;
}
 .cntr:hover  i{
   visibility: visible;
   opacity: 1;
 }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<body>
  <div class="cntr">
    <span>
      <p>Hello worldaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
      <i class="fa fa-edit fa-lg" style="padding-left:5px;border-left: solid black 1px;">
      </i>
      </span>
  </div>
  <script src="script.js"></script>
</body>

Upvotes: 2

Related Questions