On hover set wider absolute positioned element but to the opposite side - html

I want to have a list of Font Awesome icons on the outer bottom side of a Bootstrap column. Currently I have positioned them absolutely and when I set bigger width or bigger padding on hover that icon will grow bigger to the left, while I want it to go on the right.
How do I set it to go on the right, and also how to stop second element from reacting? That feature isn't planned :)
If someone has a better idea how to set it different I would be glad to hear.
http://codepen.io/filaret/pen/ORNmPZ
ul {
position: absolute;
bottom: 60px;
right: -50px;
li {
a.btn {
width: 50px;
height: 46px;
display: block;
&:hover {
width: 100px;
padding-left: 50px;
}
}
}
}
<div class="col col-md-8">
... content ...
<ul class="share-buttons-outside list-unstyled">
<li>
<a class="btn" href="#">
<i class="fa fa-facebook" aria-hidden="true"></i>
</a>
</li>
...
</ul>
</div>

Instead to position relative to right edge, do position from left:
ul {
left: 100%;
/* REMOVE right: -65px */
}

You could add a margin to correctly position it:
ul li a.btn:hover {
width: 100px;
margin-right: -50px;
padding-left: 50px;
}
This appears to correct the issue of one interacting with the other also.
Working codepen: http://codepen.io/sol_b/pen/xEVdgj

You could set a left value, instead of right:
ul {
position: absolute;
bottom: 60px;
left: 758;
...

Maybe this simple solution is enough. Instead of
right: -50px;
do
left: 760px;

You could use position: absolute; on your li elements:
Codepen
li {
border: 0;
position: absolute;
left: -50px;
top: -46px;
&:nth-child(2) {
top: 0;
}
}

Related

How to make icons/(content) placed behind navigator bar while scrolling?

I'm using google icons. But when scrolling the page, the icon position is in front of the navbar.
Icon position is using relative position because I want the icon position vertically centered, but it makes the icon located in front of the navigation bar when scrolling, I want the icon located behind the navbar. This is the screenshot of the website
#navbar {
overflow: hidden;
background-color: #151b54;
color: #fff;
position: sticky;
top: 0;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
i.material-icons {
position: relative;
top: 4.5px;
padding: 2px;
padding-right: 6px;
}
/* only to simulate scrolling */
#tri>div~div {
padding-bottom: 2000px;
}
<section id="navbar">
<a class="active">Home</a>
Site Map
FAQ
Article
</section>
<section id="main-home">
<div id="tri">
<div>
<h1>ARTICLE</h1>
<p>Interesting articles by Dustin Ivander</p>
</div>
<div style="text-align:right;">
<a href="./article/home">
<h3>Go to ARTICLE<i class="material-icons">arrow_forward_ios</i></h3>
</a>
</div>
</div>
</section>
Use a negative z-index on i.material-icons
#navbar {
overflow: hidden;
background-color: #151b54;
color: #fff;
position: sticky;
top: 0;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
i.material-icons {
position: relative;
top: 4.5px;
padding: 2px;
padding-right: 6px;
z-index: -1;
}
/* only to simulate scrolling */
#tri>div~div {
padding-bottom: 2000px;
}
<section id="navbar">
<a class="active">Home</a>
Site Map
FAQ
Article
</section>
<section id="main-home">
<div id="tri">
<div>
<h1>ARTICLE</h1>
<p>Interesting articles by Dustin Ivander</p>
</div>
<div style="text-align:right;">
<a href="./article/home">
<h3>Go to ARTICLE<i class="material-icons">arrow_forward_ios</i></h3>
</a>
</div>
</div>
</section>
What you should do is add z-index:-1 to your style sheet for anything that you want to stay on top.
i.material-icons {
position: relative;
top: 4.5px;
padding: 2px;
padding-right: 6px;
z-index: -1;
}
You can include z-index for the icon, and make its position to be relative. The higher the number of z-index, the higher the object will be placed on z-axis.
For instance, an icon with z-index:2 will be placed on top of another icon with z-index:1. Make sure to position the element in order for z-index to function. [You may refer to this image for better illustration]

How to increase the clickable area of a button?

I need to increase the clickable height of a button to 48px. The button has a background color, and I want to increase the clickable height without actually setting the height of the button (i.e. the increase in clickable area should be invisible / empty space around the button). I've tried increasing the padding and setting background-clip: content-box, however this means that the edges of the button are no longer rounded. What is the recommended way to achieve this?
I'd work with a pseudo element here:
button {
--clickable-space-around-button: -15px;
position: relative;
}
button::after {
content: "";
left: var(--clickable-space-around-button);
right: var(--clickable-space-around-button);
bottom: var(--clickable-space-around-button);
top: var(--clickable-space-around-button);
position: absolute;
}
<div style="padding: 20px;">
<button onclick="console.log('clicked')">Click me</button>
</div>
If your issue was rounded corner then use transparent border and padding-box not content-box
button {
background:red padding-box;
font-size:25px;
padding:10px 20px;
border:25px solid transparent;
border-radius:35px;
outline:none;
}
button:active {
background-color:blue;
}
<button>text</button>
Here is what I found for your request, I hope it will be useful.
I can suggest adding an invisible before (tinted with a color so that
the area is visible, you just need to remove this color):
.link {
position: relative;
display: block;
margin:50px auto;
height: 1px;
width: 1px;
background: pink;
cursor: pointer;
}
.link:before {
content: '';
position: absolute;
display: block;
top: -15px;
left: -15px;
right: -15px;
bottom: -15px;
background: rgba(255, 0, 0, 0.06);//цвет убрать
}
<a class="link" href="#"></a>
Original Answer: https://ru.stackoverflow.com/a/702645
Or you also can just try margin
Have a good day!

Animating :before element on hover

Trying to have my back and next buttons have an animated 'background' created by a :before element when hovered over. The back and next buttons are located at the sides of the page and are the text of the posts so I don't have full control over their content. I want the background block to stretch from one side to the other (right to left on next, left to right on previous) behind the text.
I want the background block (:before element) to be the full height and width of the text it is behind (text has padding)
css (I left out the transition: css until I can get it working properly.)
#nav-BN {
position: relative;
display: block;
padding: 0;
margin: 50px 0;
}
.nav-previous, .nav-next {
display: block;
position: absolute;
z-index: 1;
}
.nav-previous { left: 0; }
.nav-next { right: 0; }
.nav-previous a, .nav-next a {
display: block;
position: relative;
z-index: 2;
text-align: center;
color: #333;
padding: 10px 20px;
}
.nav-previous a:before, .nav-next a:before {
display: inline-block;
position: absolute;
content: '';
left: 0; top: 0;
height: 100%; width: 0%;
background-color: #000;
}
.nav-previous a:hover:before, .nav-next a:hover:before { width: 100%; }
.nav-previous:before { transform-origin: left center; }
.nav-next:before { transform-origin: right center; }
<div id="nav-BN">
<div class="nav-previous">
<a>link</a>
</div>
<div class="nav-next">
<a>link</a>
</div>
</div>
Issues I've encountered is using 100% width, makes it full width of screen not of the containing div. text jumping around page when hovered, etc
I have used this before and I think it is exactly what you are looking for:
http://ianlunn.github.io/Hover/
Use the example hvr-shutter-out-horizontal :
<a class="hvr-shutter-out-horizontal" href="#">Shutter Out Horizontal</a>
but change the css for .hvr-shutter-out-horizontal to background: transparent;
https://cssanimation.rocks/pseudo-elements/
Hope this helps. Not sure exactly what you are trying to do-
I think you should try
flex box

How to position one element top of another in css

I am trying to make a login form. So far I have managed to hardcode it but once I need to for ex. move one of the wrappers then I got to change every element position in that wrapper. How can I do it so that when moving icon, BG field and text, I only got to change position from one place?
HTML code:
<div id="user-wrapper">
<img id="userfield" src="images/fieldBG.png" alt="Username">
<img id="usericon" src="images/userIcon.png" alt="Username">
<p id="username">
Username
</p>
</div>
<div id="pw-wrapper">
<img id="pwfield" src="images/fieldBG.png" alt="Password">
<img id="pwicon" src="images/pwIcon.png" alt="Password">
<p id="pw">
Password
</p>
</div>
<div id="login-wrapper">
<img id="loginbtn" src="images/loginBtn.png" alt="Login">
<p><a id="login" href="#">
Login
</p>
</div>
CSS code:
#user-wrapper {
position: relative;
top: 100px;
width:1760px;
}
#usericon {
position: absolute;
top: 10px;
left: 740px;
}
#user-wrapper p {
position: absolute;
top: 14px;
left: 840px;
}
#pw-wrapper {
position: relative;
top: 120px;
width:1760px;
}
#pwicon {
position: absolute;
top: 10px;
left: 740px;
}
#pw-wrapper p {
position: absolute;
top: 14px;
left: 840px;
}
#login-wrapper {
position: relative;
top: 140px;
width: 1940px;
}
#login-wrapper p {
position: absolute;
top: 12px;
left: 950px;
}
The whole thing should look like this (but should be editable/positioned with an ease):
Thank You!
Only use
#usericon {
position: absolute;
top: 10px;
float: right;
left: 740px;
}
Okey, I managed to fix it myself.
Instead of width in the wrapper, I had to use left.
For ex.
#user-wrapper {
position:relative;
top:100px;
left:0px;
}
Now I can just only change wrapper parameters top/left and it moves all items inside the wrapper div.

How to align to the center a div with position absolute within a div with position relative?

I want to place #carousel-paginator in the center of .content-snippet.
With the following CSS cannot get the desired result
http://jsfiddle.net/y7S7Z/
Could you tell me what is wrong and how to fix it?
Note: #carousel-paginator is created dynamically and could have different size on every page request.
HTML
<div id="snippet-cnt-0" class="content-snippet">
<!-- cnt adv carousel -->
<div id="carousel-paginator"><ul>
<li id="paginator-0" class="item-paginator">0</li>
<li id="paginator-1" class="item-paginator activePaginator">1</li>
<li id="paginator-2" class="item-paginator">2</li><li id="paginator-3" class="item-paginator">3</li>
<li id="paginator-4" class="item-paginator">4</li><li id="paginator-5" class="item-paginator">5</li><li id="paginator-6" class="item-paginator">6</li></ul></div>
<div id="carousel-container">
<div id="carousel-inner">
<ul id="carousel-ul"><li id="item-6" data-dataid="6" class="item focusable focus">6</li><li id="item-0" data-dataid="0" class="item focusable">0</li><li id="item-1" data-dataid="1" class="item focusable">1</li><li id="item-2" data-dataid="2" class="item focusable">2</li><li id="item-3" data-dataid="3" class="item focusable">3</li><li id="item-4" data-dataid="4" class="item focusable">4</li><li id="item-5" data-dataid="5" class="item focusable">5</li></ul>
</div>
</div>
<div id="btn-carousel-left">PREV</div>
<div id="btn-carousel-right">NEXT</div>
</div>
CSS
.content-snippet {
height: 250px;
outline: 1px solid green;
}
ul {
list-style-type: none;
margin: 0px;
padding: 0px;
}
#carousel-paginator {
position: absolute;
top: 100px;
z-index: 1;
}
#carousel-paginator > ul li {
float: left;
background-color: lightblue;
}
#carousel-paginator > ul li, #carousel-paginator .activePaginator {
font-size: 18px;
text-align: center;
}
There is a nice CSS3 solution to positioning every item in the center of it's parent.
If you have an absolutely position element.
Try adding
left:50%;
transform:translateX(-50%);
-webkit-transform:translateX(-50%);
-ms-transform:translateX(-50%);
to your ID:
#carousel-paginator {
position: absolute;
top: 100px;
z-index: 1;
left:50%;
transform:translateX(-50%);
-webkit-transform:translateX(-50%);
-ms-transform:translateX(-50%);
}
http://jsfiddle.net/y7S7Z/6/
Always remember the prefixes!
If you know how many lines the pagination is going to take up (in this case, it's only ever 1 line) you do in-fact know the height of the element. This means you can use the line-height trick to center the element.
Here's the fiddle: http://jsfiddle.net/y7S7Z/10/
First, set the line-height on the pagination:
#carousel-paginator {
position: absolute;
top: 50%;
z-index: 1;
line-height: 1em;
}
At this point, our element is 50% from the top + 1em in line-height. Simply bring it up by half the line-height to center it vertically, like so:
#carousel-paginator {
position: absolute;
top: 50%;
z-index: 1;
line-height: 1em;
margin-top: -0.5em;
}
If you want to center it horizontally too, that's pretty simple.
Set the width of the pagination to 100%, and set text-align to center:
#carousel-paginator {
position: absolute;
top: 50%;
z-index: 1;
line-height: 1em;
margin-top: -0.5em;
width: 100%;
text-align: center;
}
And then you just need to make the ul inside inline-block (as you have the items inside floated left):
ul {
list-style-type: none;
margin: 0px;
padding: 0px;
display: inline-block;
}
A little edit at CSS because u give him that position absolute.absolute is position free and if u give position absolute ,it gone to the Top or Left.
#carousel-paginator {
position: absolute;
top: 100px;
z-index: 1;
text-align:center;
padding-left:350px;
padding-right:350px;
}
Try this css:
#carousel-paginator {
position: absolute;
top: 100px;
z-index: 1;
left:250px;
}