I'm currently working on my first site, and I have encountered a problem when trying to create two animations. The element when hovered, moves the text above the image (in this example "Krow Logo"),zooms at the image, and changes its opacity. Great so far.
The problem is, I want a small text to transition in during this animation as well, element h3. This, does not work in all the ways I've tried. I imaged it was a problem with inheritance so I tried to change the parent's properties specifically to its second child. No luck.
I want to preserve overflow:hidden on h2 (Krow Logo) but NOT on h3, since I want h3 to move OUTSIDE of the parent box.
Any hints are greatly appreciated!
I've fiddled around with :nth-child to try and change property overflow:hidden to visible
I've tried creating a grandparent element with position set to relative.
I've tried combinations of + ~ > combinators
None of them works.
CSS
#import url(https://fonts.googleapis.com/css?family=Raleway:400,800);
figure.snip1104:first-child {
font-family: 'Raleway', Arial, sans-serif;
position: absolute;
left:20%;
overflow: hidden;
margin: 10px;
min-width: 220px;
max-width: 310px;
max-height: 220px;
width: 100%;
background: #000000;
color: #ffffff;
text-align: center;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
figure.snip1104 h2 {
position: absolute;
left: 40px;
right: 40px;
display: inline-block;
background: #000000;
-webkit-transform: skew(-10deg) rotate(-10deg) translate(0, -50%);
transform: skew(-10deg) rotate(-10deg) translate(0, -50%);
padding: 12px 5px;
margin: 0;
top: 50%;
text-transform: uppercase;
font-weight: 400;
}
figure.snip1104:hover h2,
figure.snip1104.hover h2 {
-webkit-transform: skew(-10deg) rotate(-10deg) translate(-150%, -50%);
transform: skew(-10deg) rotate(-10deg) translate(-150%, -50%);
}
figure.snip1104 h3 {
opacity:0;
z-index: 5;
position: absolute;
left: 40px;
right: 40px;
display: inline-block;
padding: 12px 5px;
margin: 0;
top: 110px;
overflow: visible;
}
figure.snip1104:hover h3,
figure.snip1104.hover h3{
opacity:1;
background-color:green;
transform: translateY(200%);
}
HTML
<figure class="snip1104 blue">
<img class="temp" src="/home/it21366/Desktop/liberty/tshirtblue.jpg" alt="sample33"/>
<figcaption>
<h2>Krow <span> Logo</span></h2>
<h3>tesssst</h3>
</figcaption>
</figure>
The effect I wish to occur is for tessst to overflow the parent snip and stay visible despite moving outside of its borders. Instead, h3 disappears (moves to location, but is hidden)
Alright I created an example to show how you might solve just the issue you were having (from my understanding of your question). Basically you create a container for your headings and your image and you control the headings/image based on the hover state of the container.
I have done away with everything not necessary to solving the problem of moving your elements around so you'll have to apply this to your own solution in a way that makes sense (e.g. play with sizing, display: none, whatever you want).
There are also ways to trigger this with JavaScript but I wanted to show a CSS only solution.
If you run the code snippet you should look at it full screen or else it looks bad because I am using view-port units for the page height. Or checkout the codepen and put the editor on the left or right to get more height for the display.
https://codepen.io/zenRyoku/pen/oRdYzB?editors=1100
#import url(https://fonts.googleapis.com/css?family=Raleway:400,800);
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Raleway', Arial, sans-serif;
}
.page {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: slategray;
}
.main-heading,
.sub-heading {
padding: 2rem;
color: white;
background: rgba(0,0,0,.6);
transition: all 300ms;
text-align: center;
}
.main-heading {
transform: translateY(200%);
}
.sub-heading {
opacity: 0;
}
.container:hover .main-heading {
transform: translateY(0px);
}
.container:hover .sub-heading {
opacity: 1;
transform: translateY(-200%);
}
<div class="page">
<div class="container">
<h2 class="main-heading">Logo</h2>
<img src="https://source.unsplash.com/400x300/?japan,sign"/>
<h3 class="sub-heading">some other text</h3>
</div>
</div>
Not sure that I got what you're trying to achieve, but if overflow is hidden in the parent box, then any content you want to overflow outside of it will be hidden as that is the meaning of overflow: hidden.
If I may ask, what are you trying to target with this?
figure.snip1104:hover h2,
figure.snip1104.hover h2
Related
I'm working on an alternate display for a presentation program that replaces an HTML div with the text of the slide.
I want to have the bottom of the text aligned to a certain point, so that it has the same bottom point regardless of the number of lines.
I have now put that div inside another (id="wrapper") in order to get it to align at the bottom. The screen will always be 1920x1080. I've used the following CSS:
#wrapper {
height: 1040px;
}
#currentslide {
display: inline-block;
background-color: rgba(0,0,0,0.8);
color: white;
text-align: center;
line-height: 1;
font-size: 32px;
padding: 10px;
vertical-align: bottom;
position: absolute;
left: 50%;
transform: translate(-50%);
}
<div id="currentslide"></div>
The inline-block is to give a background that changes with the text width, but I think it's interfering with my placement.
Thanks for any help!
Figured it out. I used:
#wrapper {
height: 1080px;
}
#currentslide {
display: inline-block;
background-color: rgba(0,0,0,0.8);
color: white;
text-align: center;
line-height: 1;
font-size: 32px;
padding: 10px;
position:absolute;
bottom: 40px;
left: 50%;
transform: translate(-50%);
}
I am using a flexbox as my navigation bar at the top of my page. I have only included the code for this part because the project is an entire site. All anchor tags on my site are styled the same, with the same transform: scale(1.2) characteristic on hover. This works everywhere except in my nav. Nothing seems to scale at all inside of my nav.
Additionally on this codepen, the flexbox doesn't seem to respect the justify-content: space-around, making the anchors appear more squished together than they do on my actual site.
Codepen: https://codepen.io/colesam/pen/YxLPVW
a {
color: #646c84;
font-weight: 500;
line-height: 1.7vw;
transition: all 0.2s;
}
a:hover {
color: #ffaf54;
cursor: pointer;
transform: scale(1.2);
text-decoration: none;
}
a:focus {
color: #646c84;
text-decoration: none;
}
a:focus:hover {
color: #ffaf54;
cursor: pointer;
}
.active-indicator {
background: #ffaf54;
border-radius: 25px;
height: 2px;
margin-top: -2px;
margin-bottom: 5px;
margin-left: auto;
margin-right: auto;
opacity: 0;
transition: all 0.2s;
width: 25px;
}
.active-indicator.active {
opacity: 1;
}
#menu {
background: whitesmoke;
border: 1px solid rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: row;
justify-content: space-around;
padding: 0 25vw;
position: fixed;
left: -1;
right: -1;
top: 0;
transition: all 0.2s;
z-index: 1;
}
#menu a {
font-size: 0.9vw;
}
#menu.inactive {
opacity: 0;
}
<div id="menu">
<div id="landing-nav">
<a>Home</a>
<div class="active-indicator active"></div>
</div>
<div id="about-nav">
<a>About</a>
<div class="active-indicator"></div>
</div>
<div id="portfolio-nav">
<a>Portfolio</a>
<div class="active-indicator"></div>
</div>
<div id="resume-nav">
<a>Resume</a>
<div class="active-indicator"></div>
</div>
<div id="contact-nav">
<a>Contact</a>
<div class="active-indicator"></div>
</div>
</div>
Your nav menu has no extra width, so the flex items are packed together.
Yes, you create the illusion of width with:
#menu { padding: 0 25vw; }
But that just adds padding to the left and right of the container. The items are still packed together, and justify-content has no space to work.
revised codepen (padding removed)
Instead of padding, try using something like width: 50vw.
revised codepen (padding removed; width added)
The problem with the transform: scale() is that you have it applied to an inline-level element (a), which is not a transformable element.
Either add display: block to the anchor elements, or apply the transform to the parent div.
revised codepen (padding removed; width added; added display: block to a elements)
References:
https://drafts.csswg.org/css-transforms/#transform-property
https://drafts.csswg.org/css-transforms/#transformable-element
You have used invalid property values for your fixed nav.
Replace
left: -1;
right: -1;
with
left: 0;
right: 0;
I'm not sure why exactly transform: scale is not working, but it can be fixed by changing the display value of the div wrapping the anchor tags to flex
Codepen
I have 5 boxes that contain text that changes on hover.
However if the 'content' of a box has more than one line, it pushes the other boxes down slightly.
Also, how do I center the content vertically? Line-height does the job-ish but some of the text is more than one line. Also vertical-align seems to apply to the whole div rather than just the text in content
.image {
width: 204px;
height: 204px;
background-image: url('imglink');
display: inline-block;
background-repeat: no-repeat;
margin-left: 22px;
margin-right: 22px;
font-family: "Verdana", Geneva, sans-serif;
color: white;
font-size: 11pt;
}
.image:hover{
cursor: pointer;
}
.image:after {
width: 204px;
height: 204px;
display: inline-block;
background-repeat: no-repeat;
/* Content is inserted */
content: 'This text is already there';
}
.image:hover:after{
background-image: url('/imglink');
cursor: pointer;
content: 'This text will appear on hover';
}
<div class="image">
</div>
Here's the CSS, identical for all 5 boxes except different content.
Having massive difficulties sorting this as searching for "content" on Google doesn't really come up with the CSS "content"
Here's a fiddle: https://jsfiddle.net/su8bytdc/7/
Simply add display: flex and align-items: center to your :after selector and position: relative to your div .image.
To align the content horizontally just add text-align: center to .image and justify-content: center to the :after element
So your updated code would look something like this
.image {
position: relative;
width: 204px;
height: 204px;
display: inline-block;
background-color: red;
margin-left: 22px;
display: inline-block;
margin-right: 22px;
font-size: 11pt;
cursor: pointer;
text-align: center;
}
.image:after {
position: absolute;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
/* Content is inserted */
content: 'This text is already there Even multiple lines';
}
.image:hover:after {
text-align: center;
content: 'This text will appear on hover';
}
<div class="image">
</div>
<div class="image">
</div>
<div class="image">
</div>
<div class="image">
</div>
<div class="image">
</div>
Ok, so try adding vertical-align: top to your image class
.image{
vertical-align: top;
}
To fix the line-wrap issue, just put overflow: hidden on the container element. Beware, however that this will prevent all text from overflowing meaning if you later want to have a lot of text inside a box it will be hidden.
To center text inside of the box remove width and height from the pseudo elements and use the transform hack. Use this on the elements you want to center (remember to make its container relative):
position: absolute; (relative could also work here)
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
Finally, all of these issues are no longer issues when using flexbox, so I would suggest learning that since it's awesome.
Try this:-
.image img {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
====================================
Base styling, to make the demo more fancy
==================================== */
body {
font-family: Roboto, sans-serif;
background: #2C3D51;
padding: 1em;
-webkit-font-smoothing: antialiased;
}
h2 p {
text-align:center;
margin: 0;
font-size: 16px;
position: absolute;
top: 5px;
right: 5px;
font-weight: bold;
color: #ECF0F1;
}
section {
display: block;
max-width: 500px;
background: #E74C3C;
margin: 0 auto 15px;
height: 150px;
border-radius: .2em;
position: relative;
color: white;
text-align:center;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
}
<section class="text"> <h2>Text</h2> <p>I'm vertically aligned! Hi ho Silver, away!</p></section><section class="image"> <h2>Images</h2> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=120%C3%9770&w=120&h=70">
https://jsfiddle.net/4tmx5f46/
font-family: "Verdana", Geneva, sans-serif;
vertical-align:middle;
The font declaration was causing the dropdown of the boxes. You'll need 'vertical-align:middle;' on the boxes themselves to prevent this.
Aligning the content in the middle with vertical-align is likely a bad idea here. Vertical Align can be a real scumbag.
source: http://christopheraue.net/2014/03/05/vertical-align/
That said, You should check out this guide.
https://css-tricks.com/centering-css-complete-guide/
if you insist on centering it this way, then I would suggest you modify the content being placed by using a conjunction of ::before and ::after -> Using ::before to knock everything down by 50%, and then starting the ::after with the real content.
(or just absolutely position, transform, and be done with it)
If you want an example of what I'm describing, comment, and I'll crank out something for you.
Apologies for the mixup earlier. Grabbed a wrong tab's URL
#border {
position: static;
z-index: 1;
width: 120px;
height: 120px;
margin-left: 92% ;
padding: 15px;
border-radius: 11px;
background: white;
opacity: 0.2;
}
#text {
margin-left: 93%;
z-index: 2;
color: white;
font-weight: bold;
}
<div id="border"></div>
<div id="text">Users online</div>
I can't post the image here, cuz I have less than 10 reputation, so try to imagine it please. I want to place it's "Users online" inside the border, how should I do this? Thanks.
I'm assuming you are trying to have an element with a semitransparent background.
Since you are using the opacity property on the element with an id of border.
The problem here is that z-index will not have any effect, if the position is set to static, which is the default value for div elements.
The other thing is, that you should be using a relative positioned parent to make your life easier and have more control over the elements since positioned elements will leave the normal document flow and result in new stacking order.
Here you can find good information on the the z-index property, stacking and the document flow.
This is one solution to your problem.
body {
background:black;
}
.holder {
position:relative;
}
#border {
position: absolute;
z-index:1;
right:0;
width: 120px;
height: 120px;
padding: 15px;
border-radius: 11px;
background: white;
opacity: 0.2;
}
#text {
position: absolute;
z-index:2;
right:0;
width: 120px;
height: 120px;
padding: 15px;
text-align: center;
color: white;
font-weight: bold;
}
<div class="holder">
<div id="border"></div>
<div id="text">Users online</div>
</div>
But i would actually try to solve this with a different approach, because i find the above solution a bit to complex and it involves to much positioning, so if all you need is a semitransparent background just make use of the background property with an rgba value. Here is an example.
.user-panel {
float:right;
height: 120px;
width: 120px;
padding: 15px;
border-radius: 11px;
/* fallback for browser that do not support rgba */
background: #ccc;
/* semitransparent background */
background: rgba(0, 0, 0, .2);
text-align: center;
color: white;
}
/* clear the float using the pseudo after element */
user-panel:after {
clear: both;
display: block;
visibility: hidden;
height: 0px;
}
<header>
<div class="user-panel">Users online</div>
</header>
Hope that helps.
Change
position: static;
to
position: absolute;
for #border. That way, border will be "removed from the flow" (i.e. other elements will ignore it). You may need to adjust the margin-left property for #text so it properly aligns.
Fiddle: https://jsfiddle.net/xzdmLt33/1/
How do you animate the text position smoothly. On hover, I want to re-position the text from text-align: center to text-align: left.
From this state:
To this state:
When I change the text-align on a :hover selector, the transition isn't smooth. It just jumps to the left alignment.
div.subject > div.subjectHeader {
height: 200px;
width: 100%;
color: white;
font-family: 'Lato', 'Helvetica', sans-serif;
font-weight: 700;
font-size: 1.8em;
box-sizing: border-box;
text-align: center;
vertical-align: middle;
line-height: 200px;
transition: all 0.7s cubic-bezier(0.4,0,0.2,1);
-moz-transition: all 0.7s cubic-bezier(0.4,0,0.2,1);
}
div.subject:hover > div.subjectHeader {
height: 30px !important;
line-height: 30px !important;
font-size: 1.5em !important;
text-align: left !important;
padding-left: 10px !important;
}
Here is the jsfiddle: Link to jsfiddle
The text-align property is not animatable, so CSS transitions will not be applied to it.
One possible workaround involves positioning your text inside a div absolutely and animating the left property instead. For example, modify your header HTML like this:
<div class="subjectHeader"><span class="subjectHeaderInner>Chemistry</span></div>
Then animate the CSS of .subjectHeaderInner using the left and margin properties. Don't change text-align as there's no way to animate that property. For example:
div.subject .subjectHeaderInner {
width: 200px;
position: absolute;
left: 50%;
margin-left: -100px;
-moz-transition: all 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
div.subject:hover .subjectHeaderInner {
left: 0;
margin-left: 0;
}
I updated your fiddle with this code: http://jsfiddle.net/kAPtL/5/
Other workarounds are possible depending on what kind of effect you want. There are some examples at Is it possible to transition text-alignment using CSS3 only?
Edit: Slightly better, since the closing animation can't be done with precision (without knowing the text length), I made it simpler but at least it doesn't look that bad.
This is an alternative that works pretty well, almost perfect I would say. The most notable trick is using white-space: nowrap to play with the box dimensions effectively.
HTML layout:
<div>
<h1>
<span>Some Title</span>
</h1>
<p>some cool explanation</p>
<p>more explanation</p>
</div>
CSS that delivers the magic:
div { border: 5px solid black; height: 18em; padding-top: 2em; position: relative; width: 20em; }
div:hover h1 { height: 1.2em; }
div:hover span { right: 10em; padding-top: 0; }
h1 { bottom: 0; height: 20rem; margin: 0; top: 0; width: 20rem; }
p { padding: 10px; }
span { font-size: 1em; left: 0; padding-top: 4em; position: absolute; right: 0; text-align: center; white-space: nowrap; }
h1, span { background: green; position: absolute; transition: all .3s ease; }
JSFiddle example