0
votes

I wrote a code for my header, when you hover the header, it resizes its width to 300px and now I would like to add text inside only when width = 300px or slowly add the text while resizing the header after hovering it with mouse.

This is the code I wrote. CSS:

#header {width: 5px; height: calc(100vh - 30px); text-align: center; transition: width 0.5s ease-out; -o-transition: width 0.5s ease-out; -ms-transition: width 0.5s ease-out; -moz-transition: width 0.5s ease-out; -webkit-transition: width 0.5s ease-out;}
#header:hover {width: 300px; background: #171C21;}

HTML:

<div id="header">
    <p>test</p>
    <p>test</p>
    <p>test</p>
</div>

I'm looking for a CSS method if there is any method to make this in CSS.

Live preview: http://awesomeness.adam.zur.io/

4
overflow: hidden;? - Roope
Use media queries ? @media screen and (max-width: 300px) { // code go here } ?? - elreeda
@John He's not asking about screen width, is he? - Roope

4 Answers

3
votes

I think this should be useful.

#header { 
  width              : 10px                ; 
  height             : calc(100vh - 30px)  ;  
  text-align         : center              ; 
  transition         : width 0.5s ease-out ; 
  -o-transition      : width 0.5s ease-out ; 
  -ms-transition     : width 0.5s ease-out ; 
  -moz-transition    : width 0.5s ease-out ; 
  -webkit-transition : width 0.5s ease-out ;
  background         : #171C21             ; 
  overflow           : hidden              ;
  color              : white               ;
}

#header:hover {
  width : 300px ;
}

#textContent{
  visibility : hidden;  
}

#header:hover  #textContent{
  visibility : visible;
}
<div id="header">
  <div id="textContent">
    <p>test</p>
    <p>test</p>
    <p>test</p>
  <div/>
</div>
0
votes

You could make the text invisible by making it fully transparent with a color value of color: rbga(0, 0, 0, 0.0); and make the color solid on hover with color: rbga(0, 0, 0, 1.0);

Here's a codepen demonstrating that http://codepen.io/anon/pen/yeggKO (edited, also has the 300px width now on hover)

0
votes

You can do one thing :

Add one div with hidden element, when you hover on #header make display : block of that div tag.

Here is small example of it :

#header {width: 5px; height: calc(100vh - 30px); text-align: center; transition: width 0.5s ease-out; -o-transition: width 0.5s ease-out; -ms-transition: width 0.5s ease-out; -moz-transition: width 0.5s ease-out; -webkit-transition: width 0.5s ease-out;}
#header .hiddencontent{display:none;}
#header:hover {width: 300px; background: #171C21;}
#header:hover .hiddencontent{display:block;}
<div id="header">
    <p>test</p>
    <p>test</p>
    <p>test</p>
    <div class="hiddencontent">
    <p>test</p>
    <p>test</p>
    <p>test</p>
      <p>test</p>
    <p>test</p>
    <p>test</p>
    </div>
</div>
0
votes

Well, everything seems to be solved, but something went wrong with the hover effect of the header. When I take off my mouse of the header it doesnt animate back to its original width, it gets back without animation.

html, body {background: #1A2026; font-family: "Open Sans", "sans-serif";}
* {margin: 0; padding: 0;}
a {display: block;}

/* DESKTOP */
#header {width: 5px; height: calc(100vh - 30px); padding-top: 10px; color: rgba(255,255,255,0.0); text-align: center; transition: width 0.5s ease-out; -o-transition: width 0.5s ease-out; -ms-transition: width 0.5s ease-out; -moz-transition: width 0.5s ease-out; -webkit-transition: width 0.5s ease-out;}
#header:hover {width: 300px; background: #171C21; color: rgba(255,255,255,1.0);}
#header .hidden {display:none;}
#header .hidden > p {font-size: 16px; text-transform: uppercase; margin-bottom: 10px; font-weight: 600;}
#header .hidden > a {margin-top: 5px; text-decoration: none; color: #fff; font-weight: 600;}
#header .hidden > a:hover {color: #27ae60;}
#header:hover .hidden {display:block;}

#footer {width: 100%; height: auto; bottom: 0px; position: absolute;}
#footer .copyright {height: 30px; background: #171C21; line-height: 30px;}
#footer .copyright > p {color: #fff; text-align: center; font-size: 13px;}