Having a <li> with some text and an image to the right of the text inside of the <li> with following css:
.selectable li {
margin: 1px;
padding: 0.4em;
height: 0.52em;
line-height: 0.54em;
position: relative;
cursor: default;
}
.selectable li img {
position: absolute;
top: 1px;
right: 1px;
}
Would like to have a margin to the left of the image so that the end of the text witch sometimes have a few characters more than others doesn't come to close or gets hiden under the image.
Have tried margin-left on the image but for some reason it does not work.
Update:
http://jsfiddle.net/upnrL/
Related
I'm creating a tooltip. My problem is that when the tooltip appears, the siblings move, unlike position: absolute. I can't use an absolute position because that positions the tooltip relative to the browser window, and not it's original position.
HTML
<p class="tooltip-anchor">Hover me</p>
<span class="tooltip">Hello!</span>
CSS
.tooltip-anchor:hover + .tooltip {
display: inline-block;
}
.tooltip {
display: none;
position: relative;
color: #fff;
background: #333;
padding: 0.25em;
}
I made a demo on Code Pen.
Whit some modes to your code you can obtaine what do you want.
If you insert your span into the p tag you can set a position:absolute to the span (and position relative to it's container) and then modify it's position as you want.
Position absolute: The element is removed from the normal document
flow, and no space is created for the element in the page layout. It
is positioned relative to its closest positioned ancestor, if any;
otherwise, it is placed relative to the initial containing block. Its
final position is determined by the values of top, right, bottom, and
left.
body {
font-family: sans-serif;
font-size: 18px;
text-align: center;
}
.tooltip-anchor {
position: relative;
display: inline-block;
}
/* modified */
.tooltip-anchor:hover .tooltip {
display: inline-block;
}
.tooltip {
display: none;
position: absolute;
bottom: 20px;
/* modified */
left: -40px;
/* modify for center */
color: #fff;
background: #333;
padding: 0.25em;
min-width: 150px;
text-align: center;
}
<p style="font-size: 17px;">A simple tooltip. CSS is wonderful, may I say.</p>
<p class="tooltip-anchor">Hover me <span class="tooltip">Hello!</span></p>
<p>Hello</p>
Please look at my jsfiddle here - http://jsfiddle.net/ftuZ5/ . I know why the links won't work as the relative positioning I have used to create the link / menu backgrounds I want is covering the a element but I can't work out how to resolve the issue (having tried relative and z-index on the li and a elements, plus adding and extra div to span the a element using that to create the 'button' style background) but all to no avail.
li {
list-style: none;
}
.side-nav li {
padding-bottom: 3.125em;
width: 100%;
line-height: 1.25em;
text-align: center;
}
.side-nav a {
position: relative;
top: 1.75em;
z-index: -1;
display: block;
color: white;
text-decoration: none;
background: #c7cbaf;
-webkit-border-radius: 48px;
-moz-border-radius: 48px;
-ms-border-radius: 48px;
-o-border-radius: 48px;
border-radius: 48px;
padding-top: 1.375em;
padding-bottom: 0.75em;
text-transform: uppercase;
}
.responsive-side-nav {
background: transparent url(http://thewebbakery.co.uk/assets/graphics/responsive-icon-sml.png) no-repeat top center;
}
.interactive-side-nav {
background: transparent url(http://thewebbakery.co.uk/assets/graphics/interactive-icon-sml.png) no-repeat top center;
}
.ux-side-nav {
background: transparent url(http://thewebbakery.co.uk/assets/graphics/ux-icon-sml.png) no-repeat top center;
}
Can anyone help?
Here's a possible solution for you:
JSFiddle
<nav class="side-nav" role=navigation>
<ul>
<li><div id="responsive-side-nav" class="side-nav-image"></div>Responsive Web Design</li>
<li><div id="interactive-side-nav" class="side-nav-image"></div>Interactive Web Design</li>
<li><div id="ux-side-nav" class="side-nav-image"></div>User Experience</li>
</ul>
By wrapping the anchor tags around a new div for the images, the whole thing becomes clickable.
Then you can position the images as you wish (I've created a common class for each image):
.side-nav-image
{
width: 100%;
height: 50px;
margin-top: -50px;
}
The only downside to this is that the hit area for the button increases to fit the size of the image. But if you want the image to overlap, while having the whole thing clickable, I'm not sure that's possible.
You have to set the height and the width on the tags, if you display them as "blocks"
I have an <li> which is constrained in width and the height is set to an aspect ratio of 1:1.
I then have an element inside which is positioned absolutely with a 100% width and height. I then add an icon font to the :before pseudo element. How can I vertically center that pseudo element?
My code is:
li
+span-columns(1, 6)
a
+border-radius(50%)
display: block
position: relative
width: 100%
border: 5px solid $bright-blue
border: remCalc(5px) solid $bright-blue
&:before
padding-top: 100%
content: ''
display: block
span
display: block
position: absolute
top: 0
left: 0
width: 100%
height: 100%
&:before
// Content is added via the style for data-icon
display: inline-block
min-height: 100%
vertical-align: middle
width: 100%
color: $white
font-size: 32px
text-align: center
outline: 1px solid red
A pic of the problem. The red outline is on the span:before
COMPILED OUTPUT:
li {
width: 150px;
}
li a {
border-radius: 50%;
display: block;
position: relative;
width: 100%;
border: 5px solid blue;
}
li a:before {
padding-top: 100%;
content: '';
display: block;
}
li a span {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
li a span:before {
content: attr(data-icon);
font-family: 'IconFont';
display: inline-block;
min-height: 100%;
vertical-align: middle;
width: 100%;
color: white;
font-size: 32px;
text-align: center;
outline: 1px solid red;
}
I'v created a fiddle with a solution for you.
Here: http://jsfiddle.net/avrahamcool/h3e2G/
your span is called Content in my fiddle, and I've add a new span called Centerer.
also, I centered some text in the layout, but you can change it back to your logo without noticing any differnce.
the main ideads are:
fix the height of the li (you already fixed the width, and if it should be a circle, I dont see a problem with also fixing the height).
lossing the relative and ablsolute way
instead of centering the text inside the span (while the span was height:100%), we center the span inside his holder.
Had to solve this with top padding like so:
$half-width: space(1, 6) / 2
$half-font: remCalc(33px) / 2
$border-widths: remCalc(5px)
+rem(padding-top, $half-width - $half-font - $border-widths)
That gives me custom top padding in rems depending on the width of the circle at the time and it scales perfectly when the body font size is increased or decreased.
EDIT Changed the text to reflect better the problem.
For live demo you see the website here: http://wow-klickers.de/ (The CSS here I have modified, to maybe solve the problem.)
So I have the following scenario. My website contains a navigation bar, which in the picture above contains a "Forum" button and there is above a logo. If I go over the button the hover effect hides the part of the logo which extends into the button. I want to hover over the button but not hide the part of the logo.
Here are my code snippets:
<h1 id="logo"> // the blue box of the 2. picture
// the blue box of the 1. picture
</h1>
CSS things:
#logo a {
width: 275px;
height: 126px;
display: block;
position: relative;
bottom: 18px; // added here
}
h1#logo {
margin: 0;
position: relative;
left: 85px;
top: 6px;
background: url("images/logo.png") no-repeat;
width: 275px;
display: block;
z-index: 2; // changed here
height: 126px; // added here
}
#primary-menu-bar li a, #primary-menu-bar ul.menu li a {
display: block;
white-space: nowrap;
height: 37px;
line-height: 29px;
position: relative;
z-index: 1;
}
EDIT I tried with padding or margin, but with margin my logo is cut off but the logo should overlay over the button. And padding does not work..
Add z-index:10 to h1#logo, and not just on the a tag inside.
I know it is possible to create a custom "tooltip" with the :hover:after selectors and to align this tooltip relative to the original element by marking the original element as position:relative and the tooltip as absolute.
HTML:
test
<span custom-tooltip="testing a custom tooltip" class="tooltip">
test
</span>
test
CSS:
.tooltip {
position: relative;
}
.tooltip:hover:after {
content: attr(custom-tooltip);
position: absolute;
background: black;
color: white;
}
However, I must use absolute values to position or size this :after element
top: 30px;
left: -30px;
width: 300px;
What if I want to make the element as wide as it needs to be (Percentages are relative to the parent element creating a large vertical box so I can't tell it to go width: 100%)
And centered under the parent (left: -50% results in it being moved 50% of the parent to the left, not centered)
Is this possible without javascript? (If not, are there some magic selectors or functions to get the width of this or that and calc() the correct values?
You can force the tooltip onto a single line by using white-space:nowrap. I don't know of any way to center the tooltip without forcing a specific width on both the tooltip and the item the tooltip applies to. Here's a general-purpose example (without centering):
<p>Lorem <span tooltip="Lorem ipsum">ipsum</span> dolor sit amet.</p>
And the CSS:
*[tooltip] {
position: relative;
border-bottom: dotted 1px #000;
}
*[tooltip]:hover:before {
content: attr(tooltip);
background-color: #000;
color: #fff;
top: 1em;
position: absolute;
white-space: nowrap;
}
Note that I'm using :before instead of :after. If you want to center the tooltip and are able to define a fixed width, you can use this CSS instead:
*[tooltip] {
position: relative;
display: inline-block;
text-align: center;
width: 200px;
margin: 0 -75px;
}
*[tooltip]:hover:before {
content: attr(tooltip);
background-color: #000;
color: #fff;
top: 1em;
position: absolute;
white-space: nowrap;
width: 200px;
}
Here, the item is given a fixed width equal to the width of the tooltip then negative left/right margins to collapse it back down to the desired size. Note the addition of display:inline-block and text-align:center.
This technique isn't practical for inline tooltips, but works well for buttons and "call to action" links.
.tooltip
{
display: inline;
position: relative;
}
.tooltip:hover:after
{
background: #333;
background: rgba(0,0,0,.8);
border-radius: 5px;
bottom: 26px;
color: #fff;
content: attr(title);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 220px;
}
code from TalkersCode complete code here Create CSS3 Tooltip