I'm trying to achieve the following :
I have image and I need border 1px black and 1px white on the img to achieve some effects . And on hover 3px border that on click become active class and change the hover to fixed border of 3px.
What is the best way to that ?
I tried to do that with padding 3px on the a link
And gave the following :
a {
float:left;
background-color:white;
padding:3px;
}
and
img {
max-width:100%;
float:left;
}
The problem is that the border is not equal and little bit move the img.
Also When I hover all the UI I need opacity 0.5 and it's make problem with the a
So I looking for the best solution for 3 borders with hover and active/non active without affecting the img
my code is :
<ul>
<li>
<div>
<a class="active">
<img>
</a>
</div>
</li>
<li>
<div>
<a>
<img>
</a>
</div>
</li>
</ul>
Not sure if this is what you had in mind, but I hope that the output below can help you get started.
The main trick here is to put your <img> inside 3 divs:
the innermost div is your white border
the middle div is your black border
the outermost div is a transparent 1px border
The last one is required so that the image doesn't move--since the border is already there and will not have to be generated when you hover.
So when you hover: the outer div becomes white, the middle div (previously black) becomes white, and the last div is, well, still white. Voila! You have your "3px solid white" border on hover.
in order to toggle an active class that will stick, then you will need javascript. In this case, I just went ahead and used JQuery.
last note: since I eliminated your <a> tag, I just put a cursor:pointer rule on your outermost div so that it will still look like you are hovering on a link. You can just place whatever is your link action in your javascript onclick rule.
Hope this helps!
$('.outer').on('click',function(){
$('.active').removeClass('active');
$(this).addClass('active');
});
body {
background:gray;
}
li {
margin-top:15px;
}
li * {
transition:all ease 0.3s;
}
li:hover {
cursor:pointer;
}
.outer {
border:1px solid transparent;
}
.outer:hover,.outer:hover > .black-border {
border:1px solid white;
}
.outer:hover img {
opacity:0.5;
}
.active {
border:1px solid white;
}
.active > .black-border {
border:1px solid white;
}
img {
max-width:100%;
padding:0;
margin:0;
vertical-align:top;
background-size:cover;
}
.black-border {
border:1px solid black;
}
.white-border {
border:1px solid white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>
<div>
<div class="outer">
<div class="black-border">
<div class="white-border">
<img src="https://cdn.pixabay.com/photo/2014/03/29/09/17/cat-300572_960_720.jpg">
</div>
</div>
</div>
</div>
</li>
<li>
<div>
<div class="outer">
<div class="black-border">
<div class="white-border">
<img src="https://www.petfinder.com/wp-content/uploads/2012/11/155293403-cat-adoption-checklist-632x475-e1354290788940.jpg">
</div>
</div>
</div>
</div>
</li>
</ul>
Related
I'm sort of new to HTML and currently, I am creating a custom home page for myself containing links to site I often visit.
When I hover over a picture it expands to show more specific links (i.e. subreddits).
However, the problem is that the "sub-link-icons" are not properly aligned with the expanding DIV It will show in front of the bigger picture when hovering over it.
What I am trying to do is have the sub-link-icons to be in sync with the expanding div.*
HTML:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<title>Homepage</title>
</head>
<body>
<div class="submenu" id="steam"><img src="steam.png"></div>
<div class="submenu" id="reddit">
<img src="reddit.png"/>
<ul>
<li><img src="reddit.png"/></li>
<li><img src="reddit.png"/></li>
<li><img src="reddit.png"/></li>
</ul>
</div>
<div class="submenu" id="youtube"><img src="youtube.png"/></div>
</body>
</html>
CSS:
body {
background-color: #330000;
color: white;
}
div img {
width:256px;
height:256px;
border-radius:5px;
}
li img {
width:75px;
height:75px;
border-radius:15px;
}
#youtube:hover {
border: #E6E6E6 solid 4px;
background-color: #E6E6E6;
}
#steam:hover {
border: #12151A solid 4px;
background-color: #12151A;
}
#g2a:hover {
border: #0F1F2E solid 4px;
background-color: #0F1F2E;
}
#reddit:hover {
border: #999999 solid 4px;
background-color: #999999;
}
ul{
position:absolute;
list-style-type: none;
display:none;
margin-left: 125px;
}
.submenu {
border-radius: 5px;
position:relative;
display: inline-block;
margin-left: 0px;
width:256px;
height:256px;
border:4px solid #330000;
text-align:center;
margin-left:5px;
margin-top:5px;
transition: width 1s;
z-index:0;
}
.submenu img {
float:left;
}
.submenu:hover {
width:350px;
transition: width 1s;
}
.submenu:hover img {
float:left;
z-index:2;
}
.submenu ul {
position: absolute;
}
.submenu:hover ul {
display:inline-block;
float:right;
margin-top:-10px;
margin-left:-45px;
position:absolute;
z-index: 1;
}
.submenu:hover ul li img {
float:left;
margin-left: -30px;
margin-top: 12.5px;
}
I've tried searching the web for help but couldn't quite manage it.
JSFIDDLE
Lets go through this step by step.
First issue: On hover, "sub-icon-links" are layered over your big pictures, instead of under it.
This IS fixable with z-index, but first you have to understand how z-index works.
Note: z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).
With z-index you can layer elements that are in the same HTML layer. Because it didn't work I assume you've tried to apply z-index on the sub-menu-links. This wouldn't work because the big picture is not on the same layer as them. If we take a look at your HTML structure you'll see:
<div class="submenu" id="reddit">
<img src="http://www.workatplay.com/files/styles/fpo_medium/public/article/logo/Reddit%20Small.jpg?itok=dclAuuiP"/>
<ul>
<li><img src="http://www.workatplay.com/files/styles/fpo_medium/public/article/logo/Reddit%20Small.jpg?itok=dclAuuiP"/></li>
<li><img src="http://www.workatplay.com/files/styles/fpo_medium/public/article/logo/Reddit%20Small.jpg?itok=dclAuuiP"/></li>
<li><img src="http://www.workatplay.com/files/styles/fpo_medium/public/article/logo/Reddit%20Small.jpg?itok=dclAuuiP"/></li>
</ul>
</div>
To use z-index in this case, you have to see at which points the images or their containers are on the same layer.
Your big image is contained within an anchor tag (a)
Your small images are contained within list items
These list items are contained within an unordered list
This unordered list and the anchor tag are on the same layer. Applying z-index to one of these will fix this issue.
Note: This works different when using things like "position: absolute" and "position: fixed" or any other attribute that changes the position of the element in the HTML stack.
JSFiddle: https://jsfiddle.net/eehdo8wa/5/
What I did:
Added "z-index: -1;" to ".submenu ul"
Removed "z-index: 1;" from ".submenu:hover ul"
Second issue: On hover, the "sub-icon-links" should expand at the same rate as the div expands
So, doing this should be very simple now the pictures are layered under the big picture correctly. Basically, when you think about it, all you should have to do is make the pictures stick to the right side of its parent, so when it expands, the pictures stick to the right side and slide along, taking them into the view.
JSFiddle: https://jsfiddle.net/eehdo8wa/6/
What I did:
I redid some of the CSS to make it so everything is already in the right position before sliding into the view. This is essentially what you want in these cases. In your original fiddle you had a LOT of styling on the hover portions, changing all kinds of styling and spacings, but was it really needed? In the end, no. Now it's all in position behind the big image, ready to slide right into the view.
I have this DIV:
<div class="menu">
<label id="label1">label</label>
<div id="content">
content
</div>
<a href="" id="link>link</a>
</div>
When I hover the DIV, I only want to change the DIV's font color, not the label's and not the link's.
Thanks in advance.
Check this fiddle.
CSS:
.menu:hover #content {
color: red;
}
I believe you want to add something like this to your css?
div.menu:hover div#content {
color: red;
}
Also if you will have more divs (with other #id) inside the menu and you want that text to respond to the hover you could use:
.menu:hover .menu div {
color: red;
}
I have a list of businesses separated by categories. Next to each category name, starting at about 20px apart, I'd like to have a 3px tall border stretching to the end of the div. I would like for that border to be filled with a pattern, or image. Initially, I tried just using an image, but as each category name is a different length, that proved to be impractical.
I'm sure there is a relatively easy way to go about this, I'm just not certain on how to make it happen. Ideas?
Thanks.
updated image
here I'm using a <div> to show the border behind the <h1> category where both the <body> and <h1> have matching background patterns (that are also lined up)
example jsfiddle
CSS
body {
background:url('http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/gray_jean.png');
font-family:helvetica,arial,sans-serif;
}
#container {
margin:0 20px;
position:relative;
}
h1 {
position:relative;
float:left;
padding-top:6px;
padding-right:20px;
font-size:2em;
background:url('http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/gray_jean.png')
}
.border {
background:url('http://s3.amazonaws.com/creattica/uploaded-images/0016/6142/patterns_009_blue-hexagon-pattern_crop-iphone_web_for-creattica.jpg') repeat-x -10px 0;
position:absolute;
top:20px;
width:100%;
height:3px;
}
.listings {
clear:both;
}
HTML
<div id="container">
<div class="border"></div>
<h1>Catering</h1>
<div class="listings">
<ul>
<li>
Catering Company 1
</li>
<li>
...
</li>
</ul>
</div>
</div>
If additional markup is allowed (and your parent element has a solid background), you could go about it this way:
h1 {
background: red; /* replace with background-image */
}
h1 span {
background: white; /* replace with color of parent element's bg */
}
<h1><span>Test Headline</span></h1>
http://jsfiddle.net/358Gg/
I decided on an effect I would like for a vertical drop down list. Basically, each list element is separated by a 1px grey bar. This effect is easy, apply bottom-border: solid 1px black;
On hover, I want the top and bottom borders of the selected item to become white. Unfortunately, setting the top and bottom borders on the list item element, does not change the bottom border of the list item above it and I end up with the top border staying black and the bottom border becoming white.
Is there a css only way to achieve this effect?
The desired effect is shown here:
This would be a perfect use of the nonexistent previous-sibling selector. Unfortunately, it being nonexistent at all, I'd take a different approach. If you can change the border to be on top, the next-sibling selector will work perfectly:
ul > li:hover, ul > li:hover + li {
border-top: 1px solid white;
}
Demo: http://jsfiddle.net/mattball/ZNR94/
there is apparently looking at a CSS selector to the elements prior siblings, only for the following, look at this example:
<html>
<head>
<title></title>
</head>
<style type="text/css">
ul {
list-style: none;
width: 50%;
margin: 50px auto;
}
li {
background: #ccc;
border-bottom: 1px solid #000;
height; 20px;
}
li:hover + li, li:hover {
border-bottom: 1px solid #FFF;
}
</style>
<body>
<ul>
<li> </li>
<li> </li>
<li> </li>
<li> </li>
<li> </li>
</ul>
<p></p>
</body>
</html>
so it is difficult only with css
I have two DIVs one contain new release and must, another one contain whole data.
both div have a red border. I remove bottom border of first div.
I want to remove the border where I marked with red rectangle:
Have your active tab have position:relative and z-index higher then the content box. Then add border-bottom: 1px solid white and give it margin-bottom: -1px.
From a current project: http://jsfiddle.net/aVZLH/1/
Maybe you have some additional work for IE. But rudimentary it should show you a way to solve your problem... Without additioanl markup in your document.
<ul>
<li class="current">Tab #1</li>
<li>Tab #2</li>
</ul>
<div class="content">
<p>MY AWESOME CONTENT</p>
</div>
/*CSS*/
ul {
overflow: hidden;
position: relative;
top: 1px;
z-index: 2;
}
li {
color:#fff;
background:red;
float:left;
border:1px solid red;
padding:5px 10px;
position:relative;
top:1px;
}
.current {
background: #FFFFFF;
border-bottom: 0;
color: red;
}
.content {
padding:20px;
border:1px solid red;
position:relative;
z-index:1;
}
You can create another div to occupy the space to the right of the "Must" tab. Set this div's bottom border to "1px solid red". Then, remove the border-top from the news box, and the border-bottom from the tabs themselves.