css overlay right side is cut off - css

I am inserting an overlay div with width 100%, but the overlay div is not rendered completely. For some reason, it looks as if it has moved rightward.
Here is fiddle. You can check that the padding on the right side does not show fully.
html
<div class='overlay'>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</div>
css
.overlay {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1000000;
background-color: rgba(255, 255, 255, 0.85);
-webkit-transition: opacity .2s linear;
transition: opacity .2s linear;
padding: 20px;
}

Paddings are not calculated in the width in HTML.
That's why when you set the width to 100% (relative to the window), the padding will go outside the window.
If you wish to fit the size, with the padding, you should not set any width property.
But, in your case, your string is a bunch of "A"s, which will affect the property listed above. In this case, you would need to set the width to 40px shorter than the window width. (Because the padding on the left and right are 20px respectively, 20 + 20 = 40)
document.getElementsByTagName("div")[0].style.width = window.innerWidth - 40 + "px";
Apart from that, if you want the "A"s to move to the next line, use this css property:
word-wrap: break-word;
Otherwise, use one of the following two css properties:
overflow: hidden;
white-space: nowrap;

Replace your CSS padding with below code,
.overlay {
padding : 20px 0px;
}

As you are using padding: 20px you need to reduce width and height by 40px, you can do that using calc(100% - 40px).
Also you need to add word-wrap: break-word to break long word in div.
.overlay {
position: fixed;
left: 0;
top: 0;
width: calc(100%-40px);
height: calc(100%-40px);
z-index: 1000000;
background-color: rgba(255, 255, 255, 0.85);
-webkit-transition: opacity .2s linear;
transition: opacity .2s linear;
padding: 20px;
word-wrap: break-word;
}

Related

How to wrap parent DIV around scaled child DIV

I have a parent div wrapped around a scaled child div. The child div starts off with transform:scale(0,0); & expands to transform:scale(1,1); when a button is clicked.
.content-wrapper {
display: inline-block;
background-color: #ddf;
padding: 10px;
clear: both;
}
.content {
padding: 10px;
background-color: #fff;
display: flex-block;
overflow: hidden;
transform:scale(0,0);
transform-origin:top;
transition:transform 1s ease-out;
}
.content.open {
transform:scale(1,1);
}
However the parent div content-wrapper stays at the same size of the child div content - even when the child is "closed".
The desired behaviour is when the child div is closed the parent div shrinks to only wrap around the button.
JSFiddle of Example
Is it possible to wrap the parent div around the child div when it's "closed" in this example?
This will be a little challenging because the background color is attached to the content container. I would remove the background color from the main container, then make it a separate div positioned absolute
<div class="content">
...
<div class="content-bg"> //contains your background color
then manipulate that based on your click handler.
I've updated the JSFiddle http://jsfiddle.net/ztxa5kwu/90/
CSS for the new div:
.content-bg{
position: absolute;
background-color: #ddf;
left: 0;
right: 0;
bottom: 0;
top: 0;
z-index: -1;
transition: all .5s ease;
transform-origin: bottom right;
}
Notice the transform-origin: bottom right; to scale the background towards your button. In the JSFiddle, I made the button take on a border the same color as the background, but you could easily edit the size of the new <div class="content-bg"></div> to fit around your button.
Hope that helps, and gets you in the right direction.
Try this:
.content {
background-color: #fff;
overflow: hidden;
transform:scale(0,0);
transform-origin:top;
transition:transform 1s ease-out;
display: block;
padding: 0;
height: 0; width: 0;
}
.content.open {
padding: 10px;
height: auto; width: auto;
transform: scale(1,1);
}
Edit: Play with this:
.content {
padding: 0;
background-color: #fff;
display: block;
overflow: hidden;
transform-origin:top;
transition: transform 1s ease-out, max-width 0.5s ease-out 0.4s, max-height 1s ease-out;
transform: scale(0,0); max-width: 0; max-height: 0;
}
.content.open {
padding: 10px;
transition: transform 1s ease-out, max-width 1s ease-out, max-height 8s ease-out;
transform: scale(1, 1); max-width: 1920px; max-height: 1080px;
}
I found this comment on an older question:
This method only partially achieves the desired effect but doesn't
actually remove the space. The transformed box acts like a
relatively positioned element - the space is taken up no matter how it
is scaled. Check out this jsFiddle which takes your first one and
just adds some bogus text at the bottom. Note how the text below it
doesn't move up when the box height is scaled to zero. – animuson♦ Jul
29 '13 at 20:37
So with that in mind I used the max-height/ max-width hack to get something close to what I was after: http://jsfiddle.net/BaronGrivet/ztxa5kwu/176/
.content {
padding: 10px;
background-color: #fff;
display: flex-block;
overflow: hidden;
transform:scale(0,0);
transform-origin:top;
transition:all 1s ease-out;
max-width: 0;
max-height: 0;
}
.content.open {
transform:scale(1,1);
max-width: 500px;
max-height: 500px;
}

Div clickable through the whole width of the page even though the margin is set to less of the distance

Ok, so i have a little bit of a weird problem.
I have been working on a little website for a school project and i needed a panel of buttons on the side.
So i made some divs and made them link to my other pages and so on.
But then a weird problem came up. The area where i could click my divs was not confined to the area of the margin, but it went out to the full length of the page's horizontal axis, but not the vertical.
I have tried searching around for some kind of solution to this problem, but can't seem to find any. I have also tried to change the margin of my divs, but nothing seems to work.
This is the HTML code for my div and the link
<a href="main.html">
<div class="MenuTop">
<p id="MenuTextOn">Forside</p>
</div>
</a>
And this is the CSS code associated with that div element.
.MenuTop {
position: relative;
border-width: 3px;
border-style: solid;
border-color: black;
width: 70px;
height: 60px;
border-radius: 15px 30px;
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
background: -webkit-linear-gradient(bottom right, gray, #F0F0F0);
margin: 15px;
It should be noted that i'm new to this, but understand the basic principles.
Thanks for helping in advance! :D
You don't need to put a div inside an a element, just style the a starting with a display:block (to have it as a div by default):
Let's also organise better the CSS
.MenuTop {
/* positioning */
position: relative;
/* box-model */
display: block;
width: 70px;
height: 60px;
margin: 15px;
border-width: 3px;
border-style: solid;
border-color: black;
/* style */
background: -webkit-linear-gradient(bottom right, gray, #F0F0F0);
border-radius: 15px 30px;
opacity: 1;
/* effects */
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
Have a look here: https://jsfiddle.net/7063nkfg/
Read about inline and block elements in HTML - http://www.impressivewebs.com/difference-block-inline-css/
P.S.You don't need to put DIV and P tags into A, this will make your code difficult to read and undestand.
Make it all simplier, with styles:
html:
<div>
Text1
Text2
Text3
</div>
css:
a.menu {
display: block;
box-sizing: border-box;
padding: 15px;
width: 70px;
height: 60px;
/* other styles */
}

Changing bottom and top values in a CSS transition on click

I have a div with a fixed position that is supposed to slide up/down on click. I'm trying to get this to work with a smooth CSS transition but it only jumps up/down when clicked. I'm probably missing something obvious here but can't figure out what.
Any ideas?
I've created a demo here.
My CSS:
.wrapper {
position: fixed;
bottom: 30px;
top: initial;
background: green;
width: 100%;
height: 20px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.wrapper.slide-up {
top: 0px;
bottom: initial;
}
.wrapper.slide-down {
top: auto;
bottom: 36px;
}
My JS:
var wrapper = $('.wrapper');
$(wrapper).click(
function () {
if (wrapper.hasClass('slide-up')) {
wrapper.addClass('slide-down').removeClass('slide-up');
} else {
wrapper.removeClass('slide-down').addClass('slide-up');
}
});
You can't use top and bottom interchangeably. You need to have one style you need to change.
For example:
.wrapper.slide-up {
top: 0px;
}
.wrapper.slide-down {
top: calc(100% - 36px);
}
JSFiddle
You can use the calc css function to work out exactly what you need.
top: calc(100% - 36px);
But you need to make sure that when you're doing transitions, you keep it to one element that you need to change. So top will give it the animation when you have two different top values, but when you introduce bottom when it's not set, it will just 'jump'.
Be careful when using calc() as it isn't fully supported in older browsers:
Can I use - Calc()
I think the reason is in moving from 0 to auto value. You must specify the numbers in both cases, see fiddle.
I changed CSS only: you can calculate the position in both classes based on top only
.wrapper.slide-up {
top: 0px;
}
.wrapper.slide-down {
top: calc(100% - 20px);
}
Maybe it won't work for your business case but for this example it does.
By the way 20px in calc(100% - 20px) is the height of the block.
Check this fiddle if it suit your needs: https://jsfiddle.net/8d19f59q/12/
top: calc(100vh - 20px - 36px);
this made the trick...

Center content of pseudo element

I have a :before pseudo element displayed on :hover of a particular element.
I'm using font awesome and want to vertically center the content of the :before, but vertical align, margins etc haven't been of much help.
Any ideas?
.tile:before {
font-family: FontAwesome;
font-size: 150px;
color: white;
text-align: center;
border-radius: 15px;
opacity: 0;
z-index: 9999;
width: 100%;
height: 100%;
content: "\f16b";
position: absolute;
background-color: rgba(219,127,8, 0.7);
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.tile:hover:before {
opacity: 1;
}
Here are a few potential suggestions for .tile:before :
1 - use pixel value instead of 100% for height:
height: 100px;
2 - Make sure this is being displayed as an element that can ACCEPT margin, padding, etc.
display: block;
-or-
display: inline-block;
3 - I know you said you tried margins, but did you try padding-top?
padding-top: 20px;
4 - Try setting the overflow to hidden or visible. This often forces elements to behave "better."
overflow:hidden;
I would try all of these TOGETHER and see what happens.
Last, I might try setting a "top:" value since you have "position:absolute;" already. Maybe try this in conjunction with "position:relative;" too.
top: 10px;
Really need all the code (HTML) to tell what would work.
Using :before as the cover background to display on top of the tile element, and an :after with:
.tile:after {
top: 50%;
left: 50%;
/* Both half of font-size */
margin-left: -75px;
margin-top: -75px;
height: 150px;
line-height: 1;
}
Seemed to do the trick. Thanks all.

CSS opacity and background color

I'm using the following CSS code on my linked images:
a img:hover {
filter: alpha(opacity=80);
-khtml-opacity: 0.8;
-moz-opacity: 0.8;
opacity: 0.8;
background: #f00;
}
The idea is that when a user hovers over an image, this will be slightly tinted with red. The browser though seems to ignore the "background: #f00;" property.
What am I doing wrong?
Thanks in advance
It won't work as you are having image, so you need to have an overlay element, probably a div
Demo
HTML
<div class="wrap">
<img src="http://images.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif" />
<div class="overlay"></div>
</div>
CSS
.wrap {
position: relative;
display: inline-block;
}
.overlay {
position: absolute;
width: 100%;
height: 100%;
background: transparent;
top: 0;
}
.wrap:hover .overlay {
background: rgba(250, 0, 0, .1);
}
Note: You should have a positioned relative container, else your absolute positioned div will run out in the wild, moreover, you can remove display: inline-block; and provide respective height and width to the container element, see to it that it sticks to your image, alternatively you can also use transitions for smooth effect
For transition you need to modify the class like this
.overlay {
position: absolute;
width: 100%;
height: 100%;
background: transparent;
top: 0;
transition: background 1s;
-moz-transition: background 1s;
-webkit-transition: background 1s;
-o-transition: background 1s;
}
Demo Transition

Resources