So i have a HTML list where each List item has an image with a header title above it and a box behind the image that transforms on hover. I'm close to getting it to appear the way I'd like, but the list items don't seem to co-operate the way they should. I'm trying to get the box to be directly behind the image and the text to be centered above the box, but currently they are slightly misaligned. Here is a JSFiddle JSFiddle showcasing the List.
an example of one of the list items looks like this:
<li>
<a href = "" class="linkChange">
<h6 class ="headings">Appointment App</h6>
<img class="imgs" id="imgs" src = "https://img.icons8.com/clouds/2x/calendar.png"/>
<span class="box rotate" id = "box"></span>
</a>
</li>
The css is detailed in the JSFiddle. I'm slightly new to Web Dev so forgive me if some of the CSS is redundant.
Instead of using a <span> after your <img> tag, instead put your image in a <div> and apply the background to that div. Also remove the position: absolute; that you have on .imgs and .box.
<div class="box rotate" id = "box">
<img class="imgs" id="imgs" src = "https://img.icons8.com/clouds/2x/calendar.png"/>
</div>
I think you have far too much CSS going on, and many of the styles are redundant, or being overwritten by other styles. But I don't want to focus too much on that, since this isn't a code review, but rather, a solution. I did trim away styles that were unnecessary.
Here is what I changed:
Moved the h6 outside of the link, since users are likely going to click on the large target area of the image, rather than the heading text.
Added display: flex to your anchor and justified its contents to the center.
I set white-space: nowrap on the h6 so that it looks cleaner above the boxes. Here's the result.
.appsList {
list-style: none;
display: flex;
margin: 0 auto;
}
.appsList li {
position: relative;
padding: 100px;
}
.appsList .headings {
color: purple;
white-space: nowrap;
margin: 0 0 .75rem;
font-size: 1.2rem;
}
.linkChange {
display: flex;
justify-content: center;
}
.imgs {
position: absolute;
z-index: 1;
display: inline-block;
}
.box {
position: absolute;
background: #5FCF80;
width: 200px;
height: 200px;
z-index: -1;
}
/* Box comes immediately after imgs, so it can be selected to transform on hover with imgs */
#imgs:hover+#box {
transform: rotate(360deg);
background: #9351A6;
border-radius: 50%;
transition: all 1s ease-in-out;
z-index: -1;
}
.box:hover {
transform: rotate(360deg);
background: #9351A6;
border-radius: 50%;
z-index: -1;
}
.rotate {
transition: all 0.5s ease-in-out;
}
.rotate:hover {
transition: all 1s ease-in-out;
}
<ul class="appsList">
<li>
<h6 class="headings">Appointment App</h6>
<a href="" class="linkChange">
<img class="imgs" id="imgs" src="https://img.icons8.com/clouds/2x/calendar.png" />
<span class="box rotate" id="box"></span>
</a>
</li>
<li>
<h6 class="headings">Second App</h6>
<a href="" class="linkChange">
<img class="imgs" id="imgs" src="https://img.icons8.com/clouds/2x/brain.png" />
<span class="box rotate" id="box"></span>
</a>
</li>
<li>
<h6 class="headings">Banking App</h6>
<a href="" class="linkChange">
<img class="imgs" id="imgs" src="https://img.icons8.com/clouds/2x/bank-building.png" />
<span class="box rotate" id="box"></span>
</a>
</li>
<li>
<h6 class="headings">Reimburement App</h6>
<a href="" class="linkChange">
<img class="imgs" id="imgs" src="https://img.icons8.com/clouds/2x/cash-in-hand.png" />
<span class="box rotate" id="box"></span>
</a>
</li>
</ul>
jsFiddle
Related
My Navbar code is like this:
<navbar>
<div className='carousel-container'>
<Slider />
</div>
<div className='navbar'>
<div className='nav-brand'>
<h4>e-LECTR0</h4>
<span style={{ fontSize: '1.5rem' }}>.</span>
</div>
<div className='nav-links'>
<a href='#'>Home</a>
<a href='#'>Products</a>
<a href='#'>Contact</a>
<a href='#'>About Us</a>
</div>
<div className='nav-icons'>
<a href='#'>
<i class='fi fi-rr-search'></i>
</a>
<a href='#'>
<i class='fi fi-rr-user'></i>
</a>
<a href='#'>
<i class='fi fi-rr-shopping-cart'></i>
</a>
</div>
</div>
</navbar>
Where as my CSS code:
.navbar {
display: flex;
justify-content: space-between;
padding: 0 2rem;
padding-top: 1rem !important;
align-items: center;
position: relative;
transition: 0.3s ease-in-out;
}
.navbar:hover {
background-color: #fff;
}
So I want to change the background color of my whole navbar section into white from transparent, which i did. But while hovering into the navbar section I want the other elements in the navbar, such as navbar links and icons, to go black from white color.
How do I do it? Thanks
You can add color to the .navbar:hover rule.
.navbar:hover {
background-color: #fff;
color: black;
}
If the inheritance isn't working correctly, you can be explicit:
.navbar:hover {
background-color: #fff;
}
.navbar:hover > * {
color: black;
}
There are ways you can be more explicit, but if the code above isn't working, then I expect there is a specificity conflict. Check the style rules for the elements inside the navbar to make sure that you aren't overwriting the style change from the hover rule.
You can do this by inspecting the element in the browser developer tools, and you will see all rules affecting that element in specificity order, and that will help you track down where your style is being overwritten.
This question already has answers here:
CSS Transition on Hover
(6 answers)
Transitions on the CSS display property
(37 answers)
Closed 2 years ago.
I found this thread to have an image appear over another on hover which works great, but the transition is in an instant snap, I'm hoping to make it a smooth crossfade instead like this (I couldn't get the code there to work properly).
Tried adding 'transition: opacity 1s ease-in-out;' which doesn't work, I'm not the best at this so hoping someone could point out what's wrong please?
.imageBox {
position: relative;
float: left;
}
.imageBox .hoverImg {
position: absolute;
left: 0;
top: 0;
display: none;
}
.imageBox:hover .hoverImg {
display: block;
}
<div class="imageBox">
<div class="imageInn">
<a href="https://amovenew.druminternet.uk/first-time-buyer/"><img class="round aligncenter" src="https://www.isbiryatak.com/wp-content/uploads/2019/04/OMURGAPOPUP_MAY19-450x281.png" />
</a>
</div>
<div class="hoverImg">
<a href="https://amovenew.druminternet.uk/first-time-buyer/"><img class="round aligncenter" src="https://i.pinimg.com/originals/2e/52/bc/2e52bc9e2b3bb786820fbfb6366dda02.jpg" />
</a>
</div>
</div>
You have to set an opacity property before you can transition it:
.imageBox {
position: relative;
float: left;
}
.imageBox .hoverImg {
position: absolute;
left: 0;
top: 0;
opacity: 0;
transition: opacity 1s ease-in-out;
}
.imageBox:hover .hoverImg {
opacity: 1;
}
<div class="imageBox">
<div class="imageInn">
<a href="https://amovenew.druminternet.uk/first-time-buyer/"><img class="round aligncenter" src="https://www.isbiryatak.com/wp-content/uploads/2019/04/OMURGAPOPUP_MAY19-450x281.png" />
</a>
</div>
<div class="hoverImg">
<a href="https://amovenew.druminternet.uk/first-time-buyer/"><img class="round aligncenter" src="https://i.pinimg.com/originals/2e/52/bc/2e52bc9e2b3bb786820fbfb6366dda02.jpg" />
</a>
</div>
</div>
did you try opacity 0 for display none and opacity 1 for display block along with transition property ?
If that does not work you can you animation keyframes for opacity transition.
.imageBox>div {
position: absolute;
left: 0;
top: 0;
transition: opacity 1s;
}
.imageBox:hover .hoverImg {
opacity: 0;
}
<div class="imageBox">
<div class="imageInn">
<a href="https://amovenew.druminternet.uk/first-time-buyer/">
<img class="round aligncenter" src="https://www.isbiryatak.com/wp-content/uploads/2019/04/OMURGAPOPUP_MAY19-450x281.png" />
</a>
</div>
<div class="hoverImg">
<a href="https://amovenew.druminternet.uk/first-time-buyer/">
<img class="round aligncenter" src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1054339559,3607230833&fm=26&gp=0.jpg" />
</a>
</div>
</div>
Here are some code fragments. I have a banner and I am changing its' size depending on whether it is the home page or other pages.
HTML:
<div id="page1">
<header class=large_banner> <a class="logo" title="Swordsmen Martial Arts" href=""><span>Swordsmen Martial Arts</span></a>
<div id="myBanner" class="hero">
<h1>We know Martial Arts</h1>
<a class="btn" title="Get training from Masters" href="http://hdkumdo.com/smen/about">Get training<span> from leading Masters</span></a>
</div> ...
CSS
header div.hero {
position: absolute;
width: 42%;
top: 99px;
left: 55%
}
header div.hero h1 {
line-height: 1em;
margin: 0 0 30px 0;
color: #fff;
}
.large_banner {
height: 300px; /* default height for Home page is 200px*/
};
The banner size component works fine and I get the correct size according to the page. My problem is that I also want to change the top property of the div hero so that it is more centrally aligned (between top and bottom) within the overall banner.
I have tried different combinations of class hero, large_banner and id myBanner with no success.
You can use display:flex. Put the .hero in a container and give container css like in example: where 100vh is window height and 34px is Logo height
#myBanner {
height: calc(100vh - 34px);
display: flex;
align-items: center;
}
.hero {
margin-top: -34px;
}
<div id="page1">
<header class=large_banner>
<a class="logo" title="Swordsmen Martial Arts" href="">
<span>Swordsmen Martial Arts</span>
</a>
<div id="myBanner">
<div class="hero">
<h1>We know Martial Arts</h1>
<a class="btn" title="Get training from Masters" href="http://hdkumdo.com/smen/about">Get training<span> from leading Masters</span></a>
</div>
</div>
</header>
</div>
At this site, there is a div.social below the Online Bookings at top right of the screen.
http://imgur.com/a/QhlIL
Note: I've not been able to upload images to SO for months - always says the image is too large (> 2MB) when it is 140 KB.
For some reason .social is not displaying, nor its sub-elements:
<div class="social">
<a title="Trip Advisor" href="#" target="_blank">
<div class="tripAdvisor"></div>
</a>
<a title="Facebook" href="#" target="_blank">
<div class="facebook"></div>
</a>
<a title="Instagram" target="_blank" href="#">
<div class="instagram"></div>
</a>
<a title="YouTube" target="_blank" href="#">
<div class="youtube"></div>
</a>
</div>
<style>
.headRight .tripAdvisor {
background: url(../images/social/tripadvisor.png) no-repeat;
width: 28px;
height: 22px;
}
</style>
.social is set to display: block; and there is enough room to fit the icons in.
Help appreciated.
Just checked the bug on your website.
You must apply the style to the child divs of .social
.social div {
display: inline-block;
margin-right: 15px;
display: inline; // remove this line
zoom: 1;
}
remove the
"display: inline"
Just keep
.social div {
display: inline-block;
margin-right: 15px;
zoom: 1;
}
from that class. Will work perfectly.
I have a page that displays a span and an image, the idea is that the span appears above the image so that the image appears behind the transparent parts of the text: http://www.luckysaddleupholstery.com.
The webpage is fairly simple:
<body>
<div id="content" >
<div id="nav">
<ul id="pages">
<li class="selected">
LUCKY SADDLE</li>
<li >
designs</li>
<li >
info</li>
<li >
contact</li>
</ul>
<ul id="subpages">
</ul>
<div id="layoutItem40" class="layoutItem textItem titleText" style="left: 0px; top: 196px; width: 556px;"><span style="font-size: 42px; line-height: 42px; color: #B84C59;">VINTAGE. MODERN. TRADITIONAL. BY HAND. STUFFING. HIERLOOM. nostalgic. shabby. recycle. textiles. worn. forgotten. spring. unique. restore. </span>
</div>
<img id="logo" src="/static/img/logo.png"/>
<div id="contact"><strong>T</strong> 07961 706 522<br /><span><strong>E</strong> ruth#luckysaddleupholstery.com</span>
</div>
</div>
<div id="bodyWrapper" style="top: 14px; position: absolute;">
<div id="body" style="position: relative;">
<div id="layoutItem49" class="layoutItem imageItem" style="left: 288px; top: 0px; width: 748px;">
<img src='/static/media/imgs/Richard-Moore-Chair-Main.jpg' />
</div>
</div>
</div>
</div>
</body>
</html>
The relevant parts of the css:
.layoutItem {
position: absolute;
margin-top: 3px;
margin-left: 1px;
}
.textItem span {
z-index: 10;
margin-top: 2px;
position: relative;
}
.imageItem img {
z-index: 1;
position: relative;
}
#nav {
width: 172px;
height: 100%;
top: 0px;
position: fixed;
padding-left: 1px;
}
There is more css that effects the elements and their parents but this is all text styling, rather than positioning.
The concept is that the large text in the nav column overlays the body div - which contains the image, allowing the image to be scrolled underneath.
The image and text are rendered from a CMS system which is why the html is slightly convoluted, although very customisable!
The renders fine in Firefox, but recently seems to have become broken in recent versions of Safari / Webkit.