overflow:hidden hiding borders but not the element that overflows - css

I'm working on a header with a transition. But something is not working.
I made the ul 120px and li 60px.
And I gave the li:hover a translateY(-60px). So that it pops up when you hover over the li.
I want to hide the content that is overflowing until you hover over it. But it doesn't seem to work. It does hover hide the border of the li that is overflowing.
Does anybody know why?
thank you in advance!
<header>
<ul>
<li>
<a id="p1" href="#">Vibe</a>
<a id="p2" href="#">Vibe</a>
</li>
<li>
<a id="p1" href="#">Creations</a>
<a id="p2" href="#">Creations</a>
</li>
<li>
<a id="p1" href="#">Vision</a>
<a id="p2" href="#">Vision</a>
</li>
<li>
<a id="p1" href="#">Just tell us</a>
<a id="p2" href="#">Just tell us</a>
</li>
</ul>
</header>
And this is the css
header {
height: 60px;
width: 100%;
background-color: #34495e;
}
header ul {
margin-right: 20px;
float: right;
height: 60px;
overflow: hidden;
}
header ul li {
display: inline-block;
height: 120px;
padding-left: 40px;
padding-right: 40px;
overflow: hidden;
-webkit-transition: -webkit-transform 0.2s ease-in-out;
overflow: hidden;
border-left: 1px solid #2c3e50;
}
header ul li a {
text-decoration: none;
line-height: 60px;
font-size: 14px;
font-family: "lato", sans-serif;
font-weight: 700;
color: #e74c3c;
text-transform: uppercase;
-webkit-transform: rotate(10deg);
}
#p2 {
position: absolute;
text-align: center;
color: #c0392b;
line-height: 60px;
}
header ul li:hover {
-webkit-transform: translateY(-60px);
}

Add
position: relative;
To your ul class
Here is the jsfiddle http://jsfiddle.net/2jabu/

Here is one solution that may work for you:
Example Fiddle
First id's should be reserved for single uses. Your #p1 & #p2 would be better written as classes. To solve your problem you only need overflow:hidden; on the highest level container, in this case the header. Also since you've given #p2 absolute position, you also need to give the header position:relative;.
CSS:
header {
// existing styles
position: relative;
overflow: hidden;
}

Related

how can I put a :after pseudo element as the container for sibling elements?

I have this HTML code that I should NOT edit.
I need a solution from css to have something like in this image,
https://imgur.com/DbPheOW
where a black rectangle is added, which contains the texts of: "Colombia" and "South america". I know that the solution is done using pseudo-elements like :after, but I'm new to this CSS topic and I don't know how to do it.
I appreciate your help, and I will be happy to learn.
img{
width:300px;
height:300px;
}
li{
list-style:none;
}
li:after{
content:'';
position:absolute;
width:100%;
height:100%;
background:black;
}
<ul class="offers">
<li>
<img src="https://upload.wikimedia.org/wikipedia/commons/2/21/Flag_of_Colombia.svg" alt="">
<h3 class="country">colombia</h3>
<div class="continent_ubication">south <span class="text_continent" >america</span></div>
</li>
</ul>
First off, the list-style: none declaration you have on the list element <li> doesn't have any effect. It should added to the unordered list <ul> style block.
As the picture doesn't include the red color, I assume you wanted to keep that. Here is a solution using pseudo elements. Specifically, using the ::after element and positioning the black box right underneath the flag <img>. Then positioning the "colombia" and "south america" text using position: relative to move them into the alignment you wanted in the image.
Since your using a heading element <h3> for the "colombia" text it will have a larger font-size and font-weight than the <div> with text "south america". You could give them both similar font sizes and font weights to make them look "alike" unless you were going for a mismatched size appearance.
img{
width:300px;
height:300px;
}
ul {
list-style: none;
}
/* Make <h3> and child <div> have same font-size and weight (remove this if you want them to be different size) */
ul li h3,
ul li div {
font-size: 1.25rem;
font-weight: 400;
}
ul li .country {
position: relative;
color: #fff;
z-index: 99;
top: -5rem;
left: 4.5rem;
}
ul li .continent_ubication {
position: relative;
color: #2E86C1;
z-index: 99;
left: 7.5rem;
bottom: 4.5rem;
}
li:after{
content: "";
position: absolute;
top: 15rem;
width: 300px;
height: 110px;
z-index: 5;
background-color: black;
}
<ul class="offers">
<li>
<img src="https://upload.wikimedia.org/wikipedia/commons/2/21/Flag_of_Colombia.svg" alt="Flag of Colombia">
<h3 class="country">colombia</h3>
<div class="continent_ubication">south <span class="text_continent" >america</span></div>
</li>
</ul>
That was quite a challenge to accomplish this without changing the html, but I think I did it (at least in codepen it works). I wasn't able to make it work with li::after, but I added the black background to the "South America" text and that worked fine. Here is the CSS:
img{
width:300px;
height:300px;
}
h3 {
color: white;
position: absolute;
z-index: 2;
top: 180px;
left: 60px;
}
li{
list-style:none;
position: relative;
}
.continent_ubication,
.text-continent {
color: lightblue;
position: absolute;
z-index: 1;
background: black;
width: 160px;
height: 60px;
padding-left: 140px;
padding-top: 80px;
top: 170px;
}

CSS - problem with show a sub item under a <li>

I try to make a list menu with a submenu using JSX(React) and css Pure (Not jquery!). My intention is show "box-blue" under the <li> "Technologies" but I don't know how to make the div "box-blue" stay visible when I move out from the <li> "Techonologies" element. (obviously always inside the <div> "box-blue")
<ul className="display-menu">
<li className="display-menu-item"><NavLink className="link-categories" exact to="/">Technologies</NavLink>
<div className="box-blue"></div>
</li>
<li className="display-menu-item"><NavLink className="link-categories" exact to="/">Furniture</NavLink></li>
<li className="display-menu-item"><NavLink className="link-categories" to="/">Entertainment</NavLink></li>
</ul>
CSS code
.display-menu-item{
margin-left: 1rem;
position:relative;
}
.link-categories{
text-decoration: none;
color:white;
font-size: 0.85rem;
width: 40%;
text-align: center;
white-space: nowrap;
width:10rem;
}
.box-blue{
height:25rem;
width: 80rem;
background-color: blue;
position: absolute;
bottom: -25.5rem; /* the box appears under the ul */
z-index: 10;
display: none;
right: -45.5rem; /* the box appears at center */
}
.link-categories:hover ~ .box-blue{
display:block;
}

CSS :hover to affect 2 elements

So I have some CSS generating this.
The HTML code as follows.
<div class="menu">
<ul>
<li><a href='index.html'>Home</a></li>
<div class="menutab"></div>
<li><a href='about_us.html'>About Us</a></li>
<div class="menutab"></div>
<li><a href='#'>Order Online</a></li>
<div class="menutab"></div>
<li><a href='gallery.html'>Gallery</a></li>
<div class="menutab"></div>
<li><a href='#'>Contact Us</a></li>
<div class="menutab"></div>
</ul>
</div>
And the CSS
.menu {
width: 100%;
height: 220px;
float: left;
margin-left: -20px;
position: relative;
text-align: center;
}
.menu li{
display: block;
list-style: none;
width: 100%;
background: #EBE5D9;
height: 50px;
margin-left: -40px;
margin-top: 5px;
line-height: 50px;
}
.menu li:hover {
background: #AEC32A;
}
.menu li a{
text-decoration: none;
font-size: 20px;
color: #000000;
font-family: fantasy;
}
.menutab {
width: 30px;
position: relative;
margin-top: -3px;
margin-left: -71px;
border-right: 21px solid #EBE5D9;
border-bottom: 21px solid transparent;
}
Basically what I am wanting is for the hover effect to turn the whole thing green, currently .menu li:hover turns the block the colour #AEC32A but I also want it to turn the .menutab border the same colour, anyway of doing this? preferably without using Javascript.
Thanks in advance for your help :-)
Try the adjacent selector.
.menu li:hover+.menutab {
border-right-color: #AEC32A;
}
JS Bin Demo
This is no problem with the adjacent sibling combinator.
Simply add this to your css:
.menu li:hover + .menutab{
border-right-color: #AEC32A;
}
This selects the immediately preceeding element (.menutab) of the first element (.menu li:hover).
see the live demo
Browser-support is 100% if you don't care for old IEs <(=) 8;)

IE problem - Unwanted margin around images

http://www.wedevents.com.au/index.asp
No problem in FF but in IE there are some unwanted white margins appearing around the images in the top and bottom menu.
Any ideas on how to remove the unwanted margin?
HTML:
<ul class="topnav">
<li>
<a href="http://www.wedevents.com.au/index.asp">
<img src="/images/menu_home.gif" name="home" onMouseOver="over(0)" onMouseOut="out(0)" alt="Home" /></a>
</li>
<li>
<a href="http://www.wedevents.com.au/about.asp">
<img src="/images/menu_about.gif" name="about" onMouseOver="over(1)" onMouseOut="out(1)" alt="About" /></a>
</li>
CSS:
ul.topnav {
list-style: none;
padding: 0 85px;
margin: 0 auto;
width: 630px;
height: 36px;
background: #b09a27;
font-size: medium;
text-align: left;
}
ul.topnav li {
float: left;
margin: 0;
padding: 0;
position: relative;
}
ul.topnav li a{
padding: 0;
color: #fff;
display: block;
text-decoration: none;
float: left;
}
There is no margin or padding on the image. The user agent style is defaulting to putting a border around the image. Set border: 0; on the image. Also see the other answer for reset.css to prevent this sort of thing in the future.
Try using a reset.css Here's one I like http://meyerweb.com/eric/tools/css/reset/

Dropdown menu, when resizing the browser

I am doing an horizontal dropdown menu. It looks like this :
[menu1][menu2][menu3][menu4]
But when I resize (less wide) my browser, the menu appears like :
[menu1][menu2]
[menu3][menu4]
I want it to remain in line all the time!
EDIT: my CSS file
/* General */
#cssdropdown, #cssdropdown ul {
list-style: none;
position: relative;
visibility: visible;
z-index: 1;
overflow: hidden;
}
#cssdropdown, #cssdropdown * { padding: 0; margin: 0; }
/* Head links */
#cssdropdown li.headlink {
width: 11.911em;
float: left;
margin-left: -1px;
border: 1px black solid;
background-color: #e9e9e9;
text-align: center;
}
#cssdropdown li.headlink a { display: block; padding: 10px; }
/* Child lists and links */
#cssdropdown li.headlink ul { display: none; border-top: 1px black solid; text-align: center; }
#cssdropdown li.headlink:hover ul { display: block; }
#cssdropdown li.headlink ul li a { padding: 5px; height: 17px;}
#cssdropdown li.headlink ul li a:hover { background-color: #FF9; }
/* Pretty styling */
body {
font-family: verdana, arial, sans-serif;
font-size: 0.7em;
position: static;
}
#cssdropdown a { color: black; font-weight: bold; font-size:10px } #cssdropdown ul li a:hover { text-decoration: none; }
#cssdropdown li.headlink { background-color: #FFF50A; }
#cssdropdown li.headlink ul { background-position: bottom; padding-bottom: 10px; }
/*headermenu*/
#headerMenu {
position: relative;
float: left;
color: #DDD;
z-index: 1;
height: 34px;
right: 10px;
width: auto;
}
<div align="left" class="thrColElsHdr" id="headerMenu">
<ul id="cssdropdown" name="cssdropdown">
<li class="headlink"> Ecole
<ul>
<li>Histoire</li>
<li>Philosophie</li>
<li>Méthode</li>
<li>Equipe</li>
<li>Qualité</li>
<li>Services</li>
<li>Emplois</li>
</ul>
</li>
<li class="headlink"> Cours
<ul>
<li>Individuel</li>
<li>Semi-privé</li>
<li>Mini-groupe</li>
<li>Intensif</li>
<li>Entreprises</li>
<li>A distance</li>
<li>Par téléphone</li>
<li>Coaching</li>
<li>Soutien scolaire</li>
<li>Diplômes officiels</li>
</ul>
</li>
<li class="headlink"> Inscription
<ul>
<li>Auto-évaluation</li>
<li>Conditions</li>
<li>Tarifs</li>
<li>Formulaires</li>
</ul>
</li>
<li class="headlink"> Contact
<ul>
<li>Ecole</li>
<li>Lien externe</li>
</ul>
</li>
</ul>
</div><br/>
You should set min-width on the element containing the menu.
you want to use the css
white-space:nowrap;
this should be applied to the parent of your menus
if you provide some of the actual html, I can be more specific
for example
<div class='menuContainer'>
<span>menu1</span>
<span>menu2</span>
<span>menu3</span>
<span>menu4</span>
</div>
and css like
.menuContainer {
white-space:nowrap;
}
see http://www.w3schools.com/css/pr_text_white-space.asp
Edit in response to op question modifications
I assume #cssdropdown is the id your container around all the menus. please let me know the html for this if it's not correct.
Anyways, in this case, you should add to your css
#cssdropdown {
white-space:nowrap;
}
One other note, I see the width of your mens is set to 11.911em. When I see that I can only assume that you set it to be exactly the right width for whatever font you have. keep in mind your users may have slightly different fonts and suddenly your pixel perfect sizing is meaningless. design with a little more flexibility in mind.
Sounds like your width property isn't being set in either the HTML or the CSS.
Can you provide some sample code?

Resources