This question already has answers here:
Why is this inline-block element pushed downward?
(8 answers)
Closed 1 year ago.
My problem and the reason of it:
I have this html:
<div class="container">
List of anchors:
First child
Second child
</div>
and these styles:
.child {
text-decoration: none;
color: red;
overflow: hidden;
display: inline-block;
}
But, for some reason, the anchors it strangely moves up, you can see it here.
And, I found out that this problem happens because of the overflow property, i tried to remove it and this is what I get, which also what I expected. But of course, I really need the overflow property, so I can't move on without it.
The reason I need to use the overflow property:
I want to use it because I want to make the effect, when I hover each anchor, there will be a line under it moves from left to right.
So I will use the ::after pesudo element, translate it 100% (transform: translateX(-100%)) to the left and when hover it, it would move back to 0% (transform: translateX(0%)). So the overflow property would hide the ::after pesudo element when it translate 100% to the left.
What I tried:
I tried to use the ul element instead, an wrap each anchors into each li element:
<ul class="list">
List of anchors:
<li class="child-list">First child</li>
<li class="child-list">Second child</li>
</ul>
.child-anchor {
text-decoration: none;
color: red;
display: inline-block;
overflow: hidden;
}
.child-list {
display: inline-block;
list-style-type: none;
}
But, that it still moves up.
What I want to know:
I want to know why this weird problem happens, and also the way to fix it, or some other ways to make the effect that I mentioned in the The reason I need to use the overflow property section. So hopefully, you guys can help me with this and thank you so much for spending time reading this question!
Have you tried :
vertical-align: middle;
Related
I am using tooltips in bootstrap3.
If you hover over the gap between the lines in the 'Position' column in the table example, the tool tip will disappear. Notice that the mouse pointer changes from arrow to 'text'.
How do I get it so that the tooltip is always displayed when hovering over the cell.
Note that I tried to move the tooltip to the parent td, but this is no good because when hovering it brings in a div which breaks the table formatting.
I believe it should be possible to solve this using CSS.
JSFiddle
Thanks for the answers which got me to the solution.
Either using div (not span) solves the issue, or declaring the following css:
[data-toggle="tooltip"]{
display: block;
}
this happen because the td have a padding of 8 px- to fix it try that:
[data-toggle="tooltip"]{
display: block;
cursor: pointer;
padding:8px;
}
.table>tbody>tr>td{
padding:0;
}
This question already has answers here:
List with nested `overflow-x: hidden` hides list counter/point - why/is this a bug?
(2 answers)
Closed 6 years ago.
I'm inclined to think this is a bug in Chrome (why would a style on a child element affect the parent?), but there might be something else going on that I'm not understanding.
The ordered list below has 1 item, which in Firefox and IE10 is numbered (although in IE, it's positioned wrong). In Chrome though, the number is hidden entirely.
ol {
list-style-position: outside;
}
div {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
width: 150px;
}
<ol>
<li>
<div>Some text that trails off</div>
</li>
</ol>
What's going on/is this a bug/can this be worked around?
Well, this is a kind of a hack, but it works. Adding a pseudo :before-element brings back the list style, as the li will have some content now. Bring back the div to the top and it looks like nothing has changed.
CSS
ol > li:before {
content: '';
display: block;
height: 1px;
}
div {
margin-top: -1px;
}
Demo
Try before buy
This isn't a bug so to speak, more of a difference in how different browser engines render the CSS. (Blink vs Trident vs Gecko vs WebKit etc)
Technically speaking, the Chrome display is correct due to hiding everything outside of the div as specified with overflow: hidden;.
If you use the Chrome Inspector, you can see where the edges of the elements are and the number is outside of that area.
Your best work-around would be to set an additional piece of CSS to override the main div element.
ol {
list-style-position: outside;
}
div {
overflow: hidden;
}
ol div {
overflow: visible;
}
<!doctype html>
<html>
<body>
<ol>
<li>
<div>Some text</div>
</li>
</ol>
</body>
</html>
If you need to use the div inside li, display the div as inline, otherwise list-style: inside will work.
ol {
list-style-position: outside;
}
div {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
width: 150px; display: inline;
}
<ol>
<li><div>Some text</div></li>
</ol>
Define selectors for these elements.
Your going to began to run into problems if your just using global tags: <li> <div> especially since your nesting here.
eg:<li class="dothis"> <div class="thisdivdoes"> ...
After you do this it would be easier to differentiate overflow:hidden; where and not where.
Since your tag is within your <li> define what you want them to do individually since that's what you want to do, or else you may see them inherit each other as your experiencing.
Also, check your doctype in HTML5 I think it's not valid while in strict it may be.
The issue is quite simple really. Here is my CSS:
.fixed-body {
position: absolute;
}
And my HTML:
<div class="fixed-body">
<ul class="breadcrumb">
<li class="active">Name with spaces<span class="divider">/</span></li>
<li>Home<span class="divider">/</span></li>
<li>Library</li>
</ul>
</div>
Everything looks all right in all browsers apart from Internet Explorer 8. This is how it renders the Breadcrumb:
You can see it for yourself in this jsfiddle. This is just the resulting frame because jsfiddle doesn't render on IE8 properly. The whole fiddle is at this address (it's the same address without the "show" part in the URL).
There are two reasons why it doesn't render properly:
The CSS directive position: absolute in .fixed-body
Spaces in the first section of the breadcrum Name with spaces
If the first section doesn't contain spaces or the position of the parent node isn't set to absolute then Internet Explorer 8 renders the breadcrumb properly.
I tried to wrap the breadcrumb in another div and reset its position to static but it doesn't help. Is there any specific limitation of Internet Explorer 8 that shows in that way? And most interestingly, is there any way of fixing or working around this problem?
EDIT (copied from my response):
Just found by accident the proper fix. Overriding inline-block with inline for li in the breadcrumb gives the desired effect without any side issues (AFAIK):
.breadcrumb > li {
display: inline;
}
See also the new version of my fiddle, or open just the show frame in IE8.
This is because of "breadcrumb" width...
Check this in IE8: http://fiddle.jshell.net/azm53/12/show
I have changed breadcrumb width to 400px and it's ok.
<div class="fixed-body">
<ul class="breadcrumb">
<li class="active">Name with spaces<span class="divider">/</span>
</li>
<li>Home<span class="divider">/</span>
</li>
<li>Library
</li>
</ul>
</div>
And CSS
.fixed-body {
position: absolute;
}
.breadcrumb {
width: 400px;
}
Actually, setting the display to inline-block gives a similar result as the answer gave by ITChristian:
.breadcrumb {
display: inline-block;
}
However, both solutions have some problems. In case of setting width to a fixed value the site ceases to be responsive (the breadcrumb will not size with the window). When setting display to inline-block the gray background shrinks to only cover the links, leaving a white strip to the right. If after setting display to inline-block the width is set to 100% then it overflows the right border (since the width is to take 100% of the parent's element). Maybe the simplest solution would be to just get rid of the spaces?
EDIT:
Just found by accident the proper fix. Overriding inline-block with inline for li in the breadcrumb gives the desired effect without any side issues (AFAIK):
.breadcrumb > li {
display: inline;
}
See also the new version of my fiddle, or open just the show frame in IE8.
I'm working on a website for a small law office. In the side-menu, I'm trying to highlight the "current page". I have tried changing the background of the LI, but this doesn't quite do the trick; the list item doesn't spread to the full width of the menu, so it looks bad.
Here's a jsfiddle. I would like the yellow section to highlight like the pink section is highlighted: filling up the full vertical and horizontal space, not just highlighting the text.
Any suggestions on how to do this? I've included the style tag in the html just for example, obviously, and my real solution will be a little different when it's done. But I can't move forward until I figure out how to somehow highlight the entire line.
One little issue: you're mixing em and px units for layout. This makes it a lot harder when trying to make things line up.
I've implemented it using a .selected class that would be applied to the selected elements, and a special case for the elements which are sub-menu items:
.selected
{
display: block;
background-color: #FCFFEE;
width: 15.4em;
margin-left: -0.6em;
padding-left: 0.6em;
}
.subMenuItem.selected
{
display: block;
background-color: #FCFFEE;
width: 13.4em;
margin-left: -2.6em;
padding-left: 2.6em;
}
And a jsFiddle fork of your original with the changes: http://jsfiddle.net/CkKc7/2/.
Good luck.
Remove the padding-left from the ul. Also remove the width.
Add display: block to the <a> tags.
Add the removed padding-left back, but on the <a> tags instead.
http://jsfiddle.net/7fEYx/4/
<li class="menuItem">Contact</li>
Is that what you are trying to achieve?
You should apply your style to the LI parent of the A tag, or make the A tag element block-level. Also, consider using a class instead.
Hi,
I have the following HTML :
<div class="controlTitleContainer ">
<label for="test">Titel</label>
<div class="q"> </div>
</div>
The CSS looks like this
.controlTitleContainer .label
{
font-size: 0.94em;
color: #778899;
display:inline;
}
.controlTitleContainer .q
{
background-image: url("Images/Common/Icons/questionMark_15x14.png");
height: 14px;
width: 15px;
float:left;
}
The problem is that the div will be placed to the left of the label instead of to the right? Why?
I have tried to switch the div to a span with no success. Also If I change the div to a img intead then it will work but there is some unvanted margins that I canĀ“t remove with the div element.
Pleas advice
Edit1: The confusions in the question should now be fixed, sorry for that.
MySolution : I created two div elements (one for text and one for icon) and then set float to left on both.
You're quite confused. You talk about IMG in question title, then you present SPAN in your code and afterwards talk about DIV in your text.
But I guess all three refer to SPAN in your code since you do set a background image to your SPAN element.
Solution
Anyway. Your span is floated left according to your CSS. If you remove the following line in your style sheet, your span will appear to the right of your label:
float: left; /* <- remove this */
Edit: I suppose your question got downvoted due to this confusion. If you want the community to help with detailed answers the least you could do is to take the time to formulate your question with the same amount of care as you expect back.
Do you not want the image to the right of the label? You have specified float: left;. You may also want to change .label to label in line one of the css code.
You could use the "CSS :after Selector"
Link : http://www.w3schools.com/cssref/sel_after.asp
Floats can be tricky... I would just make sure that the label is inline or inline-block, and that your image or image container also is inline or inline-block. They would then be aligned as text on a row. Yeay!