Pure CSS :hover display: - html

I'm a general newbie running into a problem on my hand-coded site.
I intended for a div to change to an arrow when hovered over with the div being an anchor link. It seems simple enough but somewhere along in my build only the paragraph of the div started reacting to a mouse hover. The image does not react to the hover which is what I intended. I have no idea what's causing it. (Or the jumpiness that occurs when the larger images are hovered over.)
The page is here: http://www.tarynblake.com/projects/webapps.html
Here's the related HTML:
<a href='/projects.html'>
<div class="two-sides">
<img id="coding" class="top" src="/img/projects/code-blue-gray.png">
<img class="bottom arrow" src="/img/projects/arrow-red.png">
<p class="title">Web Apps<br> </p>
</div>
</a>
Here's the CSS:
.top {
max-height: 300px;
max-width: 90vw;
opacity: .65;
filter: alpha(opacity=30);
box-shadow: 10px 10px 10px 0 #3f3f3f;
}
.two-sides:hover .bottom {
display: block;
}
.two-sides:hover .top {
display: none;
}
.two-sides:hover img[src*="arrow"] + .title {
visibility: hidden;
}
.bottom {
display: none;
max-height: 300px;
max-width: 90vw;
margin: 0;
padding: 0;
opacity: .65;
}
.arrow {
height: 40px;
max-width: 100px;
margin: 2.5vh 0 2.6vh 1vw;;
padding: 10px 13px;
border: 3px hidden #973c13;
opacity: .8;
}

If you're just looking to swap out the image on hover, then you have possibly over-coded your solution.
What you want to do is take your .top class and add the image using CSS like so:
.top {
background-image: url ('/img/projects/code-blue-gray.png');
background-repeat: no-repeat;
max-height: 300px;
max-width: 90vw;
opacity: .65;
filter: alpha(opacity=30);
box-shadow: 10px 10px 10px 0 #3f3f3f;
}
Then for the hover state, add the next image in the sequence.
.top:hover {
background-image: url ('/img/projects/arrow-red.png');
background-repeat: no-repeat;
max-height: 300px;
max-width: 90vw;
opacity: .65;
filter: alpha(opacity=30);
box-shadow: 10px 10px 10px 0 #3f3f3f;
}
You could add CSS animation transitions or other effects to swap out the image, but this is a very basic overview. Hopefully this helps.

I found the simplest way of doing an image swap on hover is through the CSS.
<div class="image-swap"></div>
.image-swap {
width: 200px;
height: 200px;
background-image: url(images/stradegy-image-hover.jpg);
background-position: 0 0;
}
.image-swap:hover {
background-position: 0 100%;
}
Here's a way to do with CSS3 but remember that IE doesn't play well with CSS3. http://jsfiddle.net/gd8ba/
The "jumping" in your site could be from different size images and or from removing the words "web apps". Also, I noticed you have a js error. TypeError: Cannot set property 'innerHTML' of null http://www.tarynblake.com/js/myScripts.js:17

Related

Is there a CSS solution for this design?

Here's my issue:
I have a mockup from a design company that wants a text block with a 'broken' square border behind some big text that looks like this (description: there is a small white frame behind large text that is broken up by the text, and then a smaller text link below):
Image of an element on client's website,
In the design, the text is displayed accross the white square frame. The way I have implemented it right now is to make the big text's background color gray. Because the current image's background is gray the desired effect is achieved.
What is needed is to achieve that effect (of breaking the white frame) REGARDLESS of the appearance of the image. Because right now, this happens:
the gray background of the text appears like a box in front of the image -- it ought to be transparent
To further illustrate, if I set the background-color of the big text to transparent, the whole frame is shown (the desired effect is a broken frame):
background: transparent #1
More info if it helps:
The white frame element is just a div with a white border.
I am not sure exactly what to search for in this case, if there is an appropriate CSS solution (preferrable) or if I need to use SVG or maybe a PNG? Thank you for any help.
As #Temani Afif pointed out in the comments, it's not one box, but two separate shapes in CSS.
I made an example to illustrate this using flexbox.
.page {
background-color: black;
width: 400px;
height: 400px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.box-top {
width: 100px;
height: 10px;
border-color: white;
border-width: 2px;
border-style: solid;
border-bottom: none;
}
.box-bottom {
width: 100px;
height: 30px;
border-color: white;
border-width: 2px;
border-style: solid;
border-top: none;
}
.separator {
color: white;
width: 100%;
margin: 5px 0;
padding: 0;
font-size: 40px;
text-align: center;
}
<div class="page">
<div class="box-top"></div>
<p class="separator">
Headline
</p>
<div class="box-bottom"></div>
</div>
You can make a square element with a border and use a mask on it:
body {
margin: 0;
min-height: 100vh;
background: black;
box-sizing: border-box;
padding-top: 1px;
}
h2.fancy {
position: relative;
text-align: center;
color: white;
padding-top: 12px;
}
h2.fancy:before {
content: '';
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%);
width: 100px;
height: 100px;
border: 5px solid white;
clip-path: polygon(0 0, 100% 0, 100% 10px, 0 10px, 0 40px, 100% 40px, 100% 100%, 0 100%);
}
<h2 class=fancy>I'm a fancy title...</h2>
The advantage of this solution is that you can make it scale easily with what might change on various screen sizes. For example, with the title's font-size:
document.querySelector('input.font-size').addEventListener('input', function(e) {
document.querySelector('h2').style.fontSize = e.target.value + 'px';
})
body {
margin: 0;
min-height: 100vh;
background: url(https://picsum.photos/800) center /cover;
box-sizing: border-box;
padding-top: 1px;
}
.overlay {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,.5);
}
h2.fancy {
z-index: 1;
position: relative;
text-align: center;
color: white;
padding-top: 12px;
}
h2.fancy:before {
content: '';
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%);
width: 100px;
height: 100px;
display: block;
border: 5px solid white;
clip-path: polygon(0 0, 100% 0, 100% 10px, 0 10px, 0 calc(10px + 1.3em), 100% calc(10px + 1.3em), 100% 100%, 0 100%);
}
input[type=range] {
position: absolute;
bottom: 1rem;
left: 1rem;
z-index: 1;
}
<h2 class=fancy>I'm a fancy title...</h2>
<div class=overlay></div>
<input type=range min=12 max=36 class=font-size>
The disadvantage is that it doesn't work in IE or Edge lower than 18 or in Opera mini. This particular example works in IE 18, though, as it only uses polygon().

CSS - How to insert an animatable offset border behind an image? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I can't replicate the layout below using CSS where the black border is offset and behind the picture:
I tried using the border property, but that obviously didn't work as I don't know if it's possible to offset it.
Ideally, I should also be able to move/animate that border so that the offset is reduced when hovering the image.
🔨 Simpler solution: Using box-shadow
If the background under your image has a single plain color, you can use box-shadow with 2 shadows:
html,
body {
height: 100vh;
margin: 0;
}
body {
background: yellow;
display: flex;
justify-content: center;
align-items: center;
}
.frame {
height: 75vh;
box-shadow:
10px -10px 0 -5px yellow,
10px -10px 0 0 black;
transition: box-shadow ease-in 150ms;
}
.frame:hover {
box-shadow:
5px -5px 0 -5px yellow,
5px -5px 0 0 black;
}
<img class="frame" src="https://cdn.motor1.com/images/mgl/7WjgW/s3/1974-lancia-stratos-hf-stradale-for-sale.jpg" />
🔥 Limitations when using box-shadow
If the background is not plain, you would not be able to properly mask the unwanted portion of your undermost shadow, so you will get something like this:
html,
body {
height: 100vh;
margin: 0;
}
body {
background: linear-gradient(cyan, yellow);
display: flex;
justify-content: center;
align-items: center;
}
.frame {
height: 75vh;
box-shadow:
10px -10px 0 -5px cyan,
10px -10px 0 0 black;
transition: box-shadow ease-in 150ms;
}
.frame:hover {
box-shadow:
5px -5px 0 -5px cyan,
5px -5px 0 0 black;
}
<img class="frame" src="https://cdn.motor1.com/images/mgl/7WjgW/s3/1974-lancia-stratos-hf-stradale-for-sale.jpg" />
🤯 Better but more complex solution: Using a wrapping element around the image with a pseudoelement with a border
The solution to the problem above would be to use a wrapping element around that image. That element would then have a pseudoelement (::beforeor ::after) with a border instead of a box-shadow.
To animate/move it, you would then use transform instead of changing the border itself:
html,
body {
height: 100vh;
margin: 0;
}
body {
background: linear-gradient(cyan, yellow);
display: flex;
justify-content: center;
align-items: center;
}
img {
height: 75vh;
display: block;
}
.frame {
position: relative;
}
.frame::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
box-sizing: border-box;
border: 5px solid black;
transform: translate(10px, -10px);
transition: transform 150ms;
}
.frame:hover::before {
transform: translate(5px, -5px);
}
<div class="frame">
<img src="https://cdn.motor1.com/images/mgl/7WjgW/s3/1974-lancia-stratos-hf-stradale-for-sale.jpg" />
</div>
Note that I have also added box-sizing: border-box. Otherwise, the ::before pseudoelement size would be the size of the parent + the width of the borders around it, so the border would look bigger than the image. When using box-sizing: border-box the size of the borders and paddings are subtracted from the total size instead.
🚀 Performance note
Have you noticed that the last example moves more smoothly and maybe faster than the other two? That's because your browser is now using hardware acceleration to move it, which was not the case before.
Therefore, if you need to move/animate that, I would advise you to use this method. Otherwise, if you have a plain background and the border is not animated, then you could use the box-shadow method, which involves just a few lines of CSS.
There might be a more elegant way but I would solve it like this:
.frame-wrapper {
display: inline-block;
position: relative;
}
.frame-wrapper::before {
content: '';
display: block;
z-index: -1;
position: absolute;
bottom: 5%;
left: 5%;
border: 4px solid black;
height: 100%;
width: 100%;
}
<div class="frame-wrapper">
<img src="https://via.placeholder.com/200x300" alt="">
</div>
Without seeing your code, it would be hard to tell where the issue is. But try putting your image in its own and applying a border to the div itself.

Logo will not overlap on top of background image

I'm trying to put the logo to overlap the background image (see screenshot below) div with
position: absolute;
for the .header div and
position: relative;
for the .logo-svrs div
It seems that the external div will not overlap the .bg-banner. The overflow: visible didn't work either. No success.
I had to show the header of the logo by putting the
display: visible;
to be able to see the location of the logo. On the screenshot below, the right screenshot is what I need.
HTML
<div class="header">
<img src="imgs/logo-svrs.png" class="logo-svrs" alt="Sorenson VRS">
</div>
<div class="bg-banner">
<div class="notice-wrapper">
<div class="notice-overlay">
<div class="notices effect">
<div class="box-left-bad">
<img src="imgs/exclamatory.png" alt="Warning! - Sorenson VRS">
<p class="good">WARNING!</p>
</div>
<div class="box-right-bad">
<p>We are currently experiencing a technical difficulty that may be impacting our service. You may want to try restarting your device (VP, VP2, PC, Mac or mobile device) to see if this resolves the issue. At this time, we do not know when the technical difficulty will be resolved. We are working to quickly resolve the problem. This message will no longer appear on this page when the issue is resolved.</p>
<p>Thank you for your patience.</p>
</div>
</div>
</div>
</div>
CSS
#media screen and (max-width:732px) and (min-width:425px) {
.logo-svrs {
position: relative !important;
display: block !important;
width: 114px;
height: 29.5px;
margin: 0 auto;
z-index: 9999;
border: solid #ff0000 3px !important;
overflow: visible !important;
}
.header {
display: visible;
}
.bg-banner {
position: absolute !important;
background-image: url(../imgs/apply_header.jpg) !important;
background-repeat: no-repeat;
background-size: 100% 40% !important;
z-index: 0;
}
.notices {
position: relative !important;
width: 370px !important;
height: 350px !important;
text-align: center;
margin: 0 auto;
margin-top: 200px !important;
z-index: 9999;
border-radius: 5px !important;
box-shadow: 0 0 10px rgba(0,0,0,0.5) !important;
-moz-box-shadow: 0 0 10px rgba(0,0,0,0.5) !important;
-webkit-box-shadow: 0 0 10px rgba(0,0,0,0.5) !important;
-o-box-shadow: 0 0 10px rgba(0,0,0,0.5) !important;
}
You could move the .header div inside the .bg-banner div and add this
css:
.header {
display: visible; /*this is not valid*/
position: absolute;
top: 60px;
left: 0px;
right: 0px;
}
Here is a possible solution:
https://jsfiddle.net/kd91t26L/3/

Create html layout similar to android

I have a WebView that displays a html layout. But the problem is the html layout isn't coming out how I expected it. I created a Android layout using xml but I want the layout in html. this is what i am trying trying achieve
The grey part represents a background image.
The purple part a image(Logo).
Then I have a white box with round corners and TextView and Button inside. this is done in android xml but i want something similar in html
This is how it looks in html
But as you can see the logo is behind the white box and the TextView is next to the button instead of the top.
here is my html code
<style>
div {
padding: 10px 10px;
background: #fff;
width: 300px;
border-radius: 10px;
margin : 0 auto;
}
body {
background-image: url("url to background image");
//background-size: cover;
}
.logo {
background-image: url("url to logo");
background-size: cover;
height: 70px;
width: 200px;
margin-bottom 40;
background-color: rgba(0, 0, 0, 0);
}
.container {
display: table;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
background-color: rgba(0, 0, 0, 0);
}
.helper {
#position: absolute;
#top: 50%;
display: table-cell;
vertical-align: middle;
background-color: rgba(0, 0, 0, 0);
}
.content {
#position: relative;
#top: -50%;
margin: 0 auto;
width: 200px;
}
.button {
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
<div class="container">
<div class="helper">
<div class="logo"/>
<div class="content">
<p1>Text </p1>
<input type="submit" class="button" value="Button">
</div>
</div>
</div>
Can someone please help me fix my html code to look like the android xml version
Change <p1>Text </p1> to <p>Text </p>.
A p element has the style display:block; by default and will push the button down.

z-index not working very well in ipad

I am building a site for a friend (http://pasionesargentas.com/sm/) with the fullscreen gallery with thumbnail flip (http://tympanus.net/codrops/2011/02/09/fullscreen-gallery-with-thumbnail-flip/). I didn't quite like the idea of the flip thing so I simply preferred to disable it and add a menu instead. The menu div css is something like
#top {
position:fixed;
background: transparent;
display: block;
z-index: 99999;
}
It works fine in Chrome, Safari, Explorer and Opera. But for some reason she can't see the menu on her iPad. Since I don't have an ipad I downloaded the Ripple Mission Control and it works fine too so I have no clue what's going on.
Now, the question: Do I have to do css different for tablet browsers (iPad)? Or it is the gallery that's messing up with the menu and covering it?
Had the same problem, wanted to use an overlaying div with a transparent png on top of another div. Found out that z-index will only work on an element whose position property has been explicitly set to absolute, fixed, or relative. Fixed my ipad z-index problem instantly.
.topbar {
display:block;
background: transparent;
height: 60px;
width: 1024px;
display: block;
margin: 0;
padding: 0;
z-index:6;
position:relative;
}
.middlebar {
display:block;
background: transparent;
height: 60px;
width: 1024px;
display: block;
margin: 0;
padding: 0;
z-index:5;
position:relative;
}
.bottom {
display:block;
background: transparent;
height: 758px;
width: 1024px;
display: block;
margin: 0;
padding: 0;
z-index:4;
position:relative;
}
.description {
position: fixed;
top: 5px;
left: 50px;
text-shadow: 1px 1px 1px black;
z-index: 5;
}
#nav:hover {
background: #829FB0;
opacity: 1.0;
filter: alpha(opacity=100);
z-index: 10;
}
#nav {
align: center;
background: #829FB0;
padding: 3px 7px;
display: inline;
opacity: 1.0; //change this later
filter: alpha(opacity=65);
-moz-border-radius: 9px;
border-radius: 9px;
z-index: 10;
}
The problem could be transparent overlying divs, so first replace your code with this code, where the divs/nodes that have to be placed higher are not transparent and then see, also use z-indexes that I have given, you do not need too much high values
When checking for errors in css make sure you make nodes visible and remove their opacity and never give too high values for z-indexes. Try this, if it does not work I will look closely.