0

If we look at my site, we see that the icon with the like and dislike button is not on its correct place. I want it to be to the right of the text evaluate tekkkz.com and above XX total views. So that's my html:

<div id="bar">
 <span>evaluate<br><a href="../../">tekkkz.com</a></span>
 <a class="icon-small" id="like"></a>
 <a class="icon-small" style="margin: 0 0" id="dislike"></a>
 <br>
 <span id="views"></span>
</div>

And here some CSS:

.icon-small {
 display: block;
 position: absolute;
 height: 32px;
 width: 32px;
 text-indent: -9999em;
 margin: 0 0.5em;
}
#bar span {
 float: none;
 padding: 0 0.2em;
 vertical-align: middle;
}
#bar {
 right: 70px;
 top: 1em;
 position: absolute;
 font-size: 0.7em;
}

So what is wrong?

j08691
208k33 gold badges269 silver badges281 bronze badges
asked Sep 26, 2015 at 17:26

3 Answers 3

1

I rewrote the HTML. Not all the changes are necessary to solve your issue, but I think it's better practice to makes your elements divs as opposed to spans with <br />. A hard-coded break like this makes it more complicated to control line breaks using CSS. I also found it easier to group your like/dislike buttons in one div.

<div id="bar">
 <div class="evaluate">evaluate<br><a href="../../">tekkkz.com</a></div>
 <div class="likeButtons">
 <a class="icon-small" id="like"></a>
 <a class="icon-small" style="margin: 0 0" id="dislike"></a>
 </div>
 <div id="views"></div>
</div>

Then for the CSS I used inline-block to put the necessary elements side by side.

.evaluate, .likeButtons { /* this is new */
 display: inline-block;
}
.icon-small {
 display: inline-block; /* was block before */
 /*position: absolute; <-- remove this */
 height: 32px;
 width: 32px;
 text-indent: -9999em;
 margin: 0 0.5em;
}
/*#bar span {
 float: none;
 padding: 0 0.2em;
 vertical-align: middle;
}
^ I don't think you need this any more,
maybe the padding but I'm sure you can work that out yourself */
#bar { /* didn't touch this */
 right: 70px;
 top: 1em;
 position: absolute;
 font-size: 0.7em;
}
answered Sep 26, 2015 at 17:53
Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic work. So much time for my problem, writing so much fixes! Very good!
0

You're positioning the icons absolutely, but not defining where they go (top, bottom, left, right) in the parent, which is also positioned absolutely.

You're probably going to need to define a top value for them both, then individually define a left or right value.

I would strongly recommend restructuring the html and use floats instead to accomplish what you want. Using absolute positioning can be a pain and very buggy.

answered Sep 26, 2015 at 17:36

2 Comments

absolute is necessary cause it should be a little bar between background and text in the padding of the box
Then you're going to need to use the positioning params to get what you want.
0

Remove position: absolute; seems to work

answered Sep 26, 2015 at 18:00

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.