I am soooo close and yet 3 different methods I've tried to get text over an image on a hover is defying me.
What I am trying to do is to have a list on the left, hover over any one of the 6 elements on the left and have the image on the right change with text on it. The first image should be the default shown image.
You will see that I've tried 3 different ways to get text to show up on the first 3 elements. No matter how I do it, the text always shows up on all 3 elements as opposed to JUST the hovered element.
Here is the live test site: http://oppcess.test-lca-website.com/
This is a WordPress site using Headway Themese(GUI theme creator).
Here is the jsfiddle of the section where the issue is: http://jsfiddle.net/DragonDon/6aw6jc99/ (It's going to looked messed as it's not the full site but more just a custom code in a container.
<div class="switch prehover texthover">
<ul>
<li>
One Stop
<img src="" alt="" />
<h2><span>All required services in one location</span></h2>
</li>
<li>
Private
<img src="http://oppcess.test-lca-website.com/wp-content/uploads/2015/02/private.png" style="width:67%;" alt=""/>
<h2><span>Personal information and requirements are kept completely confidential.</span></h2>
</li>
<li>
Personal
<img src="http://oppcess.test-lca-website.com/wp-content/uploads/2015/02/Personal.png" style="width:67%;" alt=""><p class="personal"></p></img>
</li>
<li>
Cross border
<img src="http://oppcess.test-lca-website.com/wp-content/uploads/2015/02/Crossborder.png" style="width:67%;" alt=""/>
</li>
<li>
Execution
<img src="http://oppcess.test-lca-website.com/wp-content/uploads/2015/02/execution.png" style="width:67%;" alt=""/>
</li>
<li>
Services
<img src="http://oppcess.test-lca-website.com/wp-content/uploads/2015/02/Service.png" style="width:67%;" alt=""/>
</li>
</ul>
.switch ul {
display: inline-block;
height: 100%;
position: relative;
list-style-type: none;
width: 100%;
padding: 0;
}
.switch li {
font: bold 16px/100px sans-serif;
list-style-type: none;
height: 100%;
}
.switch a {
border-right: 1px solid #444;
border-top: 1px solid #444;
color: red;
display: block;
text-align: center;
text-decoration: none;
width: 33%;
}
.switch li:first-child a {
border-top: none;
background: #1f3552;
color: white;
}
.switch li:nth-child(2) a {
color: white;
background: #1f3552;
}
.switch li:nth-child(3) a {
color: white;
background: #1f3552;
}
.switch li:nth-child(4) a {
color: white;
background: #1f3552;
}
.switch li:nth-child(5) a {
color: white;
background: #1f3552;
}
.switch li:nth-child(6) a {
color: white;
background: #1f3552;
}
.switch a: {
color: #fff;
}
.switch li:nth-child(2) a:hover {
color: #fff;
}
.switch li:nth-child(3) a:hover {
color: #fff;
}
.switch li:nth-child(4) a:hover {
color: #fff;
}
.switch li:nth-child(5) a:hover {
color: #fff;
}
.switch li:nth-child(6) a:hover {
color: #fff;
}
.switch img {
background: red;
display: none;
height: 100%;
position: absolute;
right: 0;
top: 0;
}
.switch li:nth-child(2) img {
background: blue;
}
.switch li:nth-child(3) img {
background: green;
}
.switch li:nth-child(4) img {
background: yellow;
}
.switch li:nth-child(5) img {
background: gray;
}
.switch li:nth-child(6) img {
background: black;
}
.switch a:hover + img,
.switch img:hover {
display: block;
}
.prehover {
background-image: url("http://oppcess.test-lca-website.com/wp-content/uploads/2015/02/onestop.png");
background-repeat: no-repeat;
background-position:right top;
background-size: 67% ;
}
.li-hover img {
height: 100%;
width: 100%
}
.texthover h2 span {
color: white;
font: bold 55px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
position: absolute;
right: 5%;
bottom: 10%;
}
.personal:before {
content: "Providing one on one, bespoke consultation by taking all client needs into consideration.";
color: red;
font: bold 55px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
position: absolute;
right: 5%;
bottom: 10%;
}
You are doing the toggle(show/hide) only for image sibling and not the text.
.switch a:hover + img, .switch img:hover {
display: block;
}
You can wrap all text in a container with say class .details and use the general sibling combinator ~ for selecting the elements after the anchor in this case. Keep the .details hidden at first and toggle on hover
.details {
display: none;
}
.switch a:hover ~ div.details {
display: block;
}
Demo fiddle
Add z-index: 1; on below codes to show the image at the top
.switch a:hover + img, .switch img:hover {
display: block;
z-index: 1;
}
Related
I am setting up my new menu for mobile devices. Everything is set fine but after I click on any menu item it does not close the menu and menu overlay.
Any ideas how to fix this?
I am providing my CSS and HTML code bellow.
CSS
margin-bottom:-7em;
}
#keyframes bugfix {
from {
padding: 0;
}
to {
padding: 0;
}
}
#-webkit-keyframes bugfix {
from {
padding: 0;
}
to {
padding: 0;
}
}
#overlay-button {
position: absolute;
right: 2em;
top: 3em;
padding: 26px 11px;
z-index: 5;
cursor: pointer;
user-select: none;
}
#overlay-button span {
height: 4px;
width: 35px;
border-radius: 2px;
background-color: white;
position: relative;
display: block;
transition: all 0.2s ease-in-out;
}
#overlay-button span:before {
top: -10px;
visibility: visible;
}
#overlay-button span:after {
top: 10px;
}
#overlay-button span:before, #overlay-button span:after {
height: 4px;
width: 35px;
border-radius: 2px;
background-color: white;
position: absolute;
content: "";
transition: all 0.2s ease-in-out;
}
#overlay-button:hover span, #overlay-button:hover span:before, #overlay-button:hover span:after {
background: #fff;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]:checked ~ #overlay {
visibility: visible;
}
input[type="checkbox"]:checked ~ #overlay-button:hover span,
input[type="checkbox"]:checked ~ #overlay-button span {
background: transparent;
}
input[type="checkbox"]:checked ~ #overlay-button span:before {
transform: rotate(45deg) translate(7px, 7px);
opacity: 1;
}
input[type="checkbox"]:checked ~ #overlay-button span:after {
transform: rotate(-45deg) translate(7px, -7px);
}
#overlay {
height: 190vh;
width: 100%;
background: #ec6451;
z-index: 2;
visibility: hidden;
position: fixed;
left:0;
top:0px;
}
#overlay.active {
visibility: visible;
}
#overlay ul {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
text-align: center;
height: 100vh;
padding-left: 0;
list-style: none!important;
}
#overlay ul li {
padding: 1em;
list-style: none;
margin-left:-4%;
}
#overlay ul li a {
color: white;
text-decoration: none;
font-size: 1.5em;
}
#overlay ul li a:hover {
color: #333332;
}
#overlay ul li a:click {
display:none;
background-color:transparent;
}
HTML
<body>
<input type="checkbox" id="overlay-input" />
<label for="overlay-input" id="overlay-button"><span></span></label>
<div id="overlay" >
<center> <img src="/wp-content/uploads/2019/06/logo-copy.png" class="logo-up" alt="Trulli" width="250" height=auto></center>
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</body>
Please tak a look at my problem. Thank you for every answer.
This code has been tested on tablets, not mobile devices yet.
First of all I need the solution for my problem.
u must put onclick action for closing the hover
Is there a way, using CSS, to make it so that when clicking a tab (as shown in the diagram below), the tab "points" to an inactive tab?
I'm trying to make it so that the green Tab 1 (in the diagram below) points to Tabs 2 and 3, and then if you click Tab 2, it points to Tab 3. However, when you click Tab 3, it would remain rectangular (with no arrow).
I have been trying various Stack Overflow snippets which successfully place the arrow above or below the tab, but none seem to work in overlapping the inactive tab next to the active tab.
This is the basic structure of my HTML:
<ul>
<li class="active">
Tab 1
</li>
<li>
Tab 2
</li>
<li>
Tab 3
</li>
</ul>
As for the CSS, I've been using snippets like this one: https://codepen.io/mimoYmima/pen/MwzQym
The issue I've been running into seems to be that, because the tabs are floated left, I can't make the active tab's arrow overlap the other tabs.
Just add triangle using pseudoelement to active tab and other to simulate triangle border. Demo:
ul {
list-style-type: none;
display: flex;
margin: 0;
padding: 0;
}
ul > li {
padding: 10px 40px;
font-weight: bold;
font-size: 24px;
height: 40px;
border: 1px solid #000;
border-right: none;
background: linear-gradient(to bottom, #fdfdfd, #828282);
}
ul > li.active {
background: #66d835;
position: relative;
}
ul > li.active:before,
ul > li.active:after {
content: "";
position: absolute;
left: 100%;
top: 0;
}
/* triangle border for active tab */
ul > li.active:before {
transform: translateX(1px);
border: 30px solid transparent;
border-left-color: #000;
z-index: 1;
}
/* triangle for active tab */
ul > li.active:after {
/* border-width equal half of the height */
border: 30px solid transparent;
border-left-color: #66d835;
z-index: 2;
}
/* border-radius for first tab */
ul > li:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
/* border-radius for last tab but not active */
/* and right border */
ul > li:not(.active):last-child {
border-right: 1px solid #000;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
ul > li > a {
height: 100%;
/* styles for text centering */
display: flex;
align-items: center;
justify-content: center;
}
ul > li > a,
ul > li > a:hover,
ul > li > a:active,
ul > li > a:visited {
color: inherit;
text-decoration: none;
}
<ul>
<li class="active">
Tab 1
</li>
<li>
Tab 2
</li>
<li>
Tab 3
</li>
</ul>
You can leverage a pseudo element with absolute positioning as the arrow for the active tab. It will be hidden unless the list item is given the 'active' tab. Original HTML markup remains untouched.
html,
body {
height: 100%;
margin: 0;
}
html {
font-family: sans-serif;
}
body {
display: flex;
}
ul {
margin: auto;
padding: 0;
display: inline-block;
list-style-type: none;
overflow: hidden;
background-color: #eee;
background-image: linear-gradient( #fff, #ddd);
border-radius: 1rem;
border: 1px #888 solid;
font-weight: bold;
}
li {
float: left;
padding: 1.5rem 4rem;
border-right: 1px #aaa solid;
position: relative;
}
li:last-child {
border: none;
}
a {
text-decoration: none;
color: #000;
}
.active {
background-color: #0b0;
background-image: linear-gradient( #0b0, #090 );
}
li.active::after {
content:'';
width: 3rem;
height: 3rem;
background-color: #eee;
position: absolute;
border: none;
transform: scaleX( 0.75 ) rotate( 45deg ) translate( -50% );
top: 50%;
right: -2.45rem;
margin-top: -0.45rem;
border-top: 1px #888 solid;
border-right: 1px #888 solid;
background-color: #0b0;
background-image: linear-gradient( 130deg, #0b0, #090 );
border-top-right-radius: 0.5rem;
}
<ul>
<li class="active">
Tab 1
</li>
<li>
Tab 2
</li>
<li>
Tab 3
</li>
</ul>
You don't need to float the arrow divs.
I have forked the codepen you linked to and edited the CSS to create the effect in the graphic you've shared. Here's my edited version:
https://codepen.io/sigil/pen/YxWZGa
<!-- language: lang-css -->
/* Button-arrow CSS: */
.arrow {
cursor: pointer;
display: inline-block;
height: 40px;
position: relative;
line-height: 2.5em;
padding-left: 2em;
padding-right: 2em;
background: white;
color: black;
border: 1px solid #eee;
}
.arrow:after {
border-left: 20px solid white;
}
.arrow.active {
background-color: yellow;
}
.arrow.active,
.arrow.active:after {
z-index: 50;
border-left: 20px solid yellow;
}
.arrow.active:after {
content: "";
position: absolute;
border-bottom: 20px solid transparent;
border-top: 20px solid transparent;
height: 0px;
width: 0px;
margin-right: -20px;
right: 0;
}
.arrow:hover,
.arrow:active {
background: yellow;
color: black;
}
.arrow:hover:after,
.arrow:active:after {
border-left: 20px solid yellow;
}
/* General styles to set a baseline 'look' - not related to the button-arrow CSS above */
body, html {
font-family: helvetica;
background: #333;
color: #CCC;
}
.content {
text-align: center;
margin: 0 auto;
}
a:visited, a:link {
color: #F93;
}
<!-- language: lang-html -->
<html>
<body>
<div class="content">
<p>Button with an arrow on the right. Just uses an anchor tag and css, so you can use it with your existing buttons easily by just adding the class of "arrow"! Also includes a hover state.</p>
<a class="arrow active">Arrow</a><a class="arrow">Arrow</a><a class="arrow">Arrow</a>
</div>
</body>
</html>
<!-- end snippet -->
Here's the code I have problem with my underline hover effect its exppanding extra how to fix it please help me out ************************
HTML
<div class="nav-wrap">
<ul class="group" id="example-one">
<li>Home</li>
<li><a class="dropbtn">Models</a>
<ul class="dropdown-content">
<li></li>
<li>Audi</li>
<li>Bmw</li>
<li>Mercedes</li>
</ul>
</li>
<li>Offers</li>
<li>Group Sales</li>
<li>Reviews</li>
</ul>
</div>
And also i want my dropdown in the middle of his parent And here its*********
CSS
.nav-wrap {
background: white;
width: 100%;
}
#example-one {
text-align: right;
}
#example-one li {
text-align: left;
position: relative;
display: inline-block;
font-family: 'Montserrat', sans-serif;
top:-20px;
}
#example-one a {
color: #000;
font-weight: bold;
font-size: 14px;
padding: 15px 15px;
text-decoration: none;
position: relative;
color: #000;
}
#example-one a:after {
color: #333;
content: '';
position: absolute;
width: 0;
height: 3px;
display: block;
margin-top: 2px;
right: 0;
background: #000;
transition: width all 1s ease;
-webkit-transition: width 1s ease;
}
#example-one a:hover:after {
width: 100%;
left: 0;
background: #000;
}
.dropdown-content {
display: none;
position: absolute;
top: 30px;
left: 0;
background-color:white;
z-index: 1;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
}
#example-one li li {
display: block;
}
#example-one li:hover>ul {
display: block;
}
If I understand your problem correctly, the issue is with the dropdown items not being centered and the dropdown underline being too long. I believe this issue is caused by the padding on the dropdown div.
To resolve this, add some normalised padding to your .dropdown-content class:
.dropdown-content {
padding: 0 20px;
}
let the underline be attached to the text it self not to all the list item so it takes the width of just the text, now it takes the width of the whole cell in the list
This question already has answers here:
How to make this arrow in CSS only?
(5 answers)
Closed 6 years ago.
How can i achieve the effect in the below image using css
parent div with divs with triangle egde like in the picture below. if i can achieve this with JS am also open to any good idea
* {
margin: 0;
}
a {
color: #333;
text-decoration: none;
}
nav {
background: #eee;
overflow: hidden;
}
nav li {
display: inline-block;
vertical-align: top;
position: relative;
}
nav li:after {
content: " ";
position: absolute;
right: 0;
top: 0;
bottom: 0;
width: 40px;
transform: rotate(45deg);
background: #999;
}
nav a {
display: block;
padding: 14px 20px;
position: relative;
z-index: 1;
}
nav li a:before {
content: " ";
position: absolute;
right: 3px;
top: 0;
bottom: 0;
width: 40px;
transform: rotate(45deg);
background: #eee;
z-index: -1;
}
<nav>
<ul>
<li>Jewelry and watches
</li>
<li>watches
</li>
<li>Jewelry
</li>
<li>Wrist watches
</li>
</ul>
</nav>
Or you can even simplify it by using one psudo element and using the border property
* {
margin: 0;
}
a {
color: #333;
text-decoration: none;
}
nav {
background: #eee;
overflow: hidden;
box-shadow: 0px 0px 3px 2px rgba(0,0,0,0.25);
margin: 15px;
}
nav li {
display: inline-block;
vertical-align: top;
position: relative;
}
nav li:after {
content: " ";
position: absolute;
right: 0px;
top: -1px;
bottom: 0;
width: 30px;
transform: rotate(45deg);
background: transparent;
height: 30px;
border-right: 1px solid #999;
border-top: 1px solid #999;
}
nav a {
display: block;
padding: 5px 20px;
position: relative;
z-index: 1;
}
<nav>
<ul>
<li>Jewelry and watches
</li>
<li>watches
</li>
<li>Jewelry
</li>
<li>Wrist watches
</li>
</ul>
</nav>
Try this one
HTML
<ul class="breadcrumb">
<li>Home</li>
<li>Vehicles</li>
<li>Vans</li>
<li>Camper Vans</li>
<li>1989 VW Westfalia Vanagon</li>
</ul>
CSS
.breadcrumb {
list-style: none;
overflow: hidden;
font: 18px Helvetica, Arial, Sans-Serif;
}
.breadcrumb li {
float: left;
}
.breadcrumb li a {
color: white;
text-decoration: none;
padding: 10px 0 10px 65px;
background: brown; /* fallback color */
background: hsla(34,85%,35%,1);
position: relative;
display: block;
float: left;
}
.breadcrumb li a:after {
content: " ";
display: block;
width: 0;
height: 0;
border-top: 50px solid transparent; /* Go big on the size, and let overflow hide */
border-bottom: 50px solid transparent;
border-left: 30px solid hsla(34,85%,35%,1);
position: absolute;
top: 50%;
margin-top: -50px;
left: 100%;
z-index: 2;
}
.breadcrumb li a:before {
content: " ";
display: block;
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
border-left: 30px solid white;
position: absolute;
top: 50%;
margin-top: -50px;
margin-left: 1px;
left: 100%;
z-index: 1;
}
.breadcrumb li:first-child a {
padding-left: 10px;
}
.breadcrumb li:nth-child(2) a { background: hsla(34,85%,45%,1); }
.breadcrumb li:nth-child(2) a:after { border-left-color: hsla(34,85%,45%,1); }
.breadcrumb li:nth-child(3) a { background: hsla(34,85%,55%,1); }
.breadcrumb li:nth-child(3) a:after { border-left-color: hsla(34,85%,55%,1); }
.breadcrumb li:nth-child(4) a { background: hsla(34,85%,65%,1); }
.breadcrumb li:nth-child(4) a:after { border-left-color: hsla(34,85%,65%,1); }
.breadcrumb li:nth-child(5) a { background: hsla(34,85%,75%,1); }
.breadcrumb li:nth-child(5) a:after { border-left-color: hsla(34,85%,75%,1); }
.breadcrumb li:last-child a {
background: transparent !important;
color: black;
pointer-events: none;
cursor: default;
}
.breadcrumb li a:hover { background: hsla(34,85%,25%,1); }
.breadcrumb li a:hover:after { border-left-color: hsla(34,85%,25%,1) !important; }
I would like to design a navigation menu that responds to the width of the page by changing the horizontal menu into a single button that drops down a menu when clicked on.
All the examples I've seen seem to use Javascript or JQuery. Is there a CSS only way of doing this?
My thought was to create two different <ul></ul> elements. One for the horizontal and one for a vertical drop down menu. And use media query to hide one depending on screen size. Can this be done using a single <ul></ul> element instead?
Here's one way to achieve a Bootstrapish functionality using CSS. It is also possible to add some smooth animation using CSS and I'll leave it up to you to work that one out and to optimize the code wherever necessary. (Resize the preview window to see the effect).
Fiddle: http://jsfiddle.net/875v00ge/.
HTML:
<nav>
<span tabindex = "1"></span>
<span></span>
<div class = "menuWrapper">
<ul>
<li>About</li>
<li>Company</li>
<li>FAQ</li>
<li>Contact</li>
<li>Help</li>
</ul>
</div>
</nav>
CSS:
* {
margin: 0;
padding: 0;
}
ul {
list-style-type: none;
}
a {
color: rgb(50, 50, 50);
text-decoration: none;
}
nav {
background-color: rgb(240, 240, 240);
border: 1px solid rgb(200, 200, 200);
border-radius: 5px;
display: table;
height: calc(14px * 3);
width: 95%;
margin: 25px auto;
position: relative;
}
nav span {
width: calc(14px * 1.5);
height: 14px;
display: none;
position: absolute;
right: 14px;
top: 50%;
transform: translateY(-50%);
outline: 0;
cursor: pointer;
}
nav span:first-of-type {
border: solid rgb(100, 100, 100);
border-width: 2px 0;
padding: 4px 0;
height: 2px;
background-color: rgb(100, 100, 100);
background-clip: content-box;
z-index: 2;
}
nav span:nth-of-type(2) {
z-index: 1;
background-color: transparent;
}
nav li {
float: left;
font: normal 14px/3 Sans-Serif;
}
nav li:first-of-type {
margin-left: 10px;
}
nav li a {
display: inline-block;
padding: 0 10px;
}
nav li a:hover {
background-color: rgb(220, 220, 220);
}
#media screen and (max-width: 360px) {
nav .menuWrapper {
position: absolute;
top: 100%;
width: 100%;
left: -1px;
overflow: hidden;
border: 0px solid rgb(200, 200, 200);
}
nav ul {
transform: translateY(-100%);
background-color: rgb(235, 235, 235);
}
nav {
border-radius: 0;
}
nav li {
float: none;
}
nav li:first-of-type {
margin-left: 0;
}
nav li a {
display: block;
}
nav span {
display: block;
}
nav span:first-of-type:focus {
border-color: green;
background-color: green;
z-index: 0;
}
nav span:first-of-type:focus ~ .menuWrapper {
border-width: 1px;
}
nav span:first-of-type:focus ~ .menuWrapper > ul,
nav span:first-of-type:not(:focus) ~ .menuWrapper > ul:hover {
transform: translateY(0%);
}
}