I have the following html and CSS that I need to make responsive.
It starts with a lightweight YouTube video embedding (less YouTube code to download) found from labnol.org. I then wrapped the youtube-player div with two other divs to horizontally center the video.
I've tried a few solutions I've seen here in SO, but have not been able to make this work. I would like to be able to set the max width in any display, but not have it go off the edge of the screen when viewed on mobile devices.
I would greatly appreciate any help. Thank you.
HTML:
<div id="videoParent" class="videoParent">
<div id="videoDiv" class="videoDiv">
<div class="youtube-player" data-id="gmX8VFlrv38"></div>
</div>
</div>
with the following CSS.
<style>
<style>
.videoDiv {
max-width:560px;
display:inline-block;
width:90%;
}
.videoParent {
text-align:center;
}
.youtube-player {
position: relative;
padding-bottom: 56.23%;
/* Use 75% for 4:3 videos */
height: 0;
/*width:400px; */
overflow: hidden;
max-width: 100%;
background: #000;
margin: 5px;
}
.youtube-player iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
background: transparent;
}
.youtube-player img {
bottom: 0;
display: block;
left: 0;
margin: auto;
max-width: 100%;
width: 100%;
position: absolute;
right: 0;
top: 0;
border: none;
height: auto;
cursor: pointer;
-webkit-transition: .4s all;
-moz-transition: .4s all;
transition: .4s all;
}
.youtube-player img:hover {
-webkit-filter: brightness(75%);
}
.youtube-player .play {
height: 72px;
width: 72px;
left: 50%;
top: 50%;
margin-left: -36px;
margin-top: -36px;
position: absolute;
background: url("//i.imgur.com/TxzC70f.png") no-repeat;
cursor: pointer;
}</style>
I simplified my CSS to the following at it appears to be doing what I need it to.
.videoParent {
text-align:center;
}
.videoDiv {
max-width:560px;
display:inline-block;
width:60%;
}
Related
To start off, I am not very experienced with web development. I know enough, however when I get to browser compatiblity I struggle. I am trying to figure out why Chrome and Safari are reading my website's code so differently. I understand different browsers read code differently, however I have been trying to figure out how to fix this problem on my website for awhile now and I am unable to.
I'm hoping that I can at least figure out why the menu is on the left in the Safari browser and not on the right like it should be in the Firefox browser. If I figure this out I feel it can help me figure out how to clean up the rest of my code so it looks like it should in the Safari browser. I've been trying to figure out how to implement webkit properly, but I do not know how to do so yet.
One reason it may look this way is because I am using Safari on a PC, which may make the Safari version look the way it does on my computer. Below are screenshots of the landing page and how they look on Firefox and Safari:
[Firefox Version (How the website is supposed to look)][1]
[Safari Version][2]
.nav {
position: fixed;
}
.navbar-fixed-top {
transition: background-color .25s linear;
position: fixed;
top: 0;
background-color: transparent !important;
height: 100px;
width: 100%;
z-index: 1000;
}
.navbar-fixed-top.scrolled {
transition: background-color .25s linear;
position: fixed;
top: 0;
background-color: white !important;
display: initial;
height: 100px;
width: 100%;
z-index: 1000;
}
.navigation {
position: fixed;
top: 0;
left: 0;
background-color: #ddbe6e;
height: 100%;
width: 100%;
display: none;
z-index: 999;
transition: all 1s ease-in 0s;
font-family: bebas-kai, sans-serif;
}
.navigation ul {
list-style-type: none;
text-align: center;
}
.navigation li a {
color: #222658;
}
.navigation ul li {
padding: 30px;
}
#nav-list {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
font-size: 40px;
}
.navigation.show {
display: initial;
animation: fade-in .5s ease-in;
}
#logo {
position: absolute;
top: 50%;
float: left;
transform: translateY(-50%);
margin-left: 50px;
z-index: 1000;
user-select: none;
cursor: pointer;
}
#logo.close {
position: absolute;
top: 50%;
float: left;
transform: translateY(-50%);
margin-left: 50px;
z-index: 1000;
user-select: none;
cursor: pointer;
display: none;
}
#logo.scrolled {
position: absolute;
top: 50%;
float: left;
transform: translateY(-50%);
margin-left: 50px;
z-index: 1000;
user-select: none;
cursor: pointer;
}
#wrapper {
background: transparent;
display: inline-block;
position: absolute;
left: 90vw;
margin: 20px;
padding: 10px;
cursor: pointer;
z-index: 1000;
}
#menuTitle {
position: relative;
top: 2px;
color: #222658;
font-size: 25px;
user-select: none;
transition: color .25s linear;
}
.circle {
width: 40px;
height: 40px;
position: relative;
cursor: pointer;
}
.line {
position: absolute;
height: 3px;
width: 70%;
background-color: #222658;
border-radius: 10px;
transition: all cubic-bezier(0.26, 0.1, 0.27, 1.55) 0.35s;
left: 50px;
}
.top {
top: 32%;
}
.middle {
top: 53%;
}
.bottom {
top: 72%;
}
.icon.close .top {
top: 48%;
transform: rotate(45deg);
}
.icon.close .middle,
.icon.close .bottom {
transform: rotate(-45deg);
top: 48%;
}
<html>
<body>
<nav class="navbar-fixed-top">
<img id="logo" src="images/core-logo.png" alt="logo" height="46" width="176">
<div id="wrapper">
<div class="circle icon">
<h1 id="menuTitle">Menu</h1>
<span class="line top"></span>
<span class="line middle"></span>
<span class="line bottom"></span>
</div>
</div>
<div class="navigation">
<ul id="nav-list">
<li>Home</li>
<li>About Us</li>
<li>Team</li>
<li>Services</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
</nav>
</body>
</html>
I suggest you take a look at some documentations about CSS and browser support. w3schools has a very interesting table with all the tags and its compatibilities.
Also, there's an answer that might help you figure out webkits: How to provide CSS properties for Different browsers like Mozilla and Chrome
I have a map element wrapped inside of a container and I'm trying to change its position to sticky (as opposed to relative). I have text that I would like to scroll over the map as the viewer scrolls down, however when I open up the inspection tools I see the position of the #map element reverts back to relative, despite it being sticky in my actual code. When I change it to sticky in the browser, it works fine. Can someone tell me what I'm doing wrong here
Here is my HTML
<div id="mapContainer" class="container-map">
<div id="map" style="position: sticky;" class="leaflet-container
leaflet-touch leaflet-retina leaflet-fade-anim leaflet-grab leaflet-
touch-drag leaflet-touch-zoom" tabindex="0">
</div>
<div id='sections'>
<div>
<h1>Operation Entebbe</h1>
<p class="text">
<span class="text-decorate">O</span>Sample Text
</p>
</div>
</div>
</div>
Here is my CSS
#mapContainer{
position: relative;
}
#sections{
z-index: 99;
max-width: 100%;
width: 640px;
position: relative;
margin-left: auto;
margin-right: auto;
}
#sections > div{
background: white;
height: 100%;
opacity: .75;
transition: 0.5s;
}
#sections > div p.text {
display: block;
color: #000000;
z-index: 10;
}
#sections > div.graph-scroll-active{
opacity: 1;
}
#map {
margin-left: 40px;
z-index: 3;
width: 500px;
position: -webkit-sticky;
position: sticky;
top: calc(50% - 250px);
}
#map svg {
z-index: 2;
}
#map svg {
-webkit-transition: transition .6s;
-moz-transition: transition .6s;
-ms-transition: transition .6s;
-o-transition: transition .6s;
transition: transition .6s;
}
#media (max-width: 925px) {
#map{
width: 100%;
margin-left: 0px;
float: none;
}
#sections{
width: auto;
position: relative;
margin: 0px auto;
}
#sections > div{
background: rgba(255,255,255,.5);
padding: 10px;
border-top: 1px solid;
border-bottom: 1px solid;
margin-bottom: 80vh;
}
pre{
overflow: hidden;
}
h1{
margin: 10px;
}
}
#map {
width: 1000px;
height: 600px;
margin-left: 140px;
margin-top: 50px;
position: sticky;
}
svg {
position: relative;
}
Any help would be immensely appreciated.
I have a div with a hamburger sign on, covered by another div. I want the burger sign to stack on top of everything. So I applied z-index values to the places I thought appropriate. However it doesn't work. Can anyone explain why? Here is my codepen below please take a look.
codepen:
http://codepen.io/tbeckett24/pen/qORBbE
html:
<body>
<div id="photoCover">
<nav id="menu" class="menu">
<span>Menu</span>
</nav>
</div><!--photoCover-->
<div id="entryMenu"></div><!--entryMenu-->
</body>
css:
html {
background: green;
width: 100%;
height:100%;
}
body {
width: 100%;
height:100%;
position: relative;
}
#photoCover {
width:100%;
height:100%;
position: fixed;
top: 0;
left:0;
background-color: rgba(0,0,0,0.6);
}
.menu {
position: fixed;
top: 0; right: 0;
width: 100%;
background-color: rgba(0,0,0,0);
-webkit-backface-visibility: hidden;
}
.menu-trigger {
position: fixed;
top: 2%; right: 2%;
display: block;
width: 60px; height: 60px;
cursor: pointer;
background: red;
z-index:3000;
}
.menu-trigger span {
position: absolute;
top: 50%; left: 0;
display: block;
width: 100%; height: 6px;
margin-top: -2px;
background-color: #fff;
font-size: 0px;
-webkit-touch-callout: none;
user-select: none;
-webkit-transition: background-color 0.3s;
transition: background-color 0.3s;
z-index: 2000;
}
.menu-trigger span:before,
.menu-trigger span:after {
position: absolute;
left: 0;
width: 100%; height: 100%;
background: #fff;
content: '';
}
.menu-trigger span:before {
-webkit-transform: translateY(-270%);
transform: translateY(-270%);
}
.menu-trigger span:after {
-webkit-transform: translateY(270%);
transform: translateY(270%);
}
#entryMenu {
position: fixed;
top:0;
left:0;
height:100%;
width:100%;
background-color: rgba(0,0,0,0.9);
}
By adding a z-index to the parent-div, I got the "hamburger" on the top layer.
#photoCover {
(...)
z-index:99;
}
I would believe that the reason why, is that both the #photoCover and the #entryMenu is fixed and in the same place, the #entryMenu is on top, because it is added last.
Add z-index: 1; for div with id=photoCover.
Add z-index to the wrapper div
#photoCover {
width:100%;
height:100%;
position: fixed;
top: 0;
left:0;
background-color: rgba(0,0,0,0.6);
z-index: 1;
}
Demo URL
Right now I'm doing this to animate an element background color.
<style>
.container{
padding: 30px;
}
.element {
position: relative;
font-size: 20px;
line-height: 20px;
background-color: #c00;
display: inline-block;
overflow: hidden;
}
.element div {
position: absolute;
top: -20px;
left: 0;
background-color: #0c0;
transition:top 0.5s ease;
}
.element:hover div {
top: 0px;
transition:top 0.5s ease;
}
</style>
<div class="container">
<div class="element">some text<div>some text</div></div>
</div>
JsFiddle demo.
Is there any "cleaner" way to have the same animation? Right now I'm duplicating my content to achieve this.
You can use pseudo elements for this, and not have to duplicate any content:
It's basically moving one pseudo from above the element, and bringing it down over the element on the hover
div {
position: relative;
display: inline-block;
overflow: hidden;
}
div:before,
div:after {
content: "";
position: absolute;
left: 0;
height: 100%;
width: 100%;
transition: all 0.6s;
z-index: -1;
}
div:before {
top: 0;
background: red;
}
div:after {
top: -100%;
background: green;
}
div:hover:before {
top: 100%;
}
div:hover:after {
top: 0;
}
<div>Text? Why would you ever want text?</div>
If you want the text to 'move' as well, you can do something similar:
div {
position: relative;
display: inline-block;
overflow: hidden;
height:20px;
width:300px;
}
div:before,
div:after {
content: attr(data-text);
position: absolute;
left: 0;
height: 100%;
width: 100%;
transition: all 0.6s;
z-index: -1;
}
div:before {
top: 0;
background: red;
}
div:after {
top: -100%;
background: green;
}
div:hover:before {
top: 100%;
}
div:hover:after {
top: 0;
}
<div data-text="Text? Why would you ever want text?"></div>
Note: canIuse suggests it is widely supported (bit I admit only tested in latest chrome, so only going by this for cross browser). However, This may affect SEO, and so I would be reluctant to use this in production.
If you just wanted the 'upper' element to flow over the top of the text (instead of 'lower' text scrolling as well), You could do:
div {
position: relative;
display: inline-block;
overflow: hidden;
height: 20px;
width: 300px;
background: red;
}
div:before {
content: attr(data-text);
position: absolute;
left: 0;
height: 100%;
width: 100%;
transition: all 0.6s;
top: -100%;
background: green;
}
div:hover:before {
top: 0;
}
<div data-text="The text I always wanted">The text I always wanted</div>
You could do it with background-position
Set a linear-gradient to 50% of each of the background colors and set the background size to be 200% of the actual div.
Then animate it and move the background 100% up. Like this:
.container {
padding: 30px;
}
.element {
position: relative;
font-size: 20px;
line-height: 20px;
background-color: #c00;
display: inline-block;
overflow: hidden;
background-size: 100% 200%;
background-image: linear-gradient(to bottom, #c00 50%, #0c0 50%);
}
.element:hover {
background-position: 0 -100%;
transition: background-position 1s;
}
<div class="container">
<div class="element">some text</div>
</div>
This cuts out the need for any duplicate content in either the css or the html.
Yes, you can use pseudo element :before and get the text with attribute like:
<div class="container">
<div class="element" data-text="some text">some text</div>
</div>
And css:
.container{
padding: 30px;
}
.element {
position: relative;
font-size: 20px;
line-height: 20px;
background-color: #c00;
display: inline-block;
overflow: hidden;
}
.element:before {
content: attr(data-text);
position: absolute;
top: -20px;
left: 0;
background-color: #0c0;
transition:top 0.5s ease;
}
.element:hover:before {
top: 0px;
transition:top 0.5s ease;
}
http://jsfiddle.net/Pik_at/g3Lxrou4/3/
just similar to jbutler483, but using just a single pseudo class. FIDDLE
.container {
padding: 30px;
}
.element {
position: relative;
font-size: 20px;
line-height: 20px;
background-color: #c00;
display: inline-block;
transition: top 0.5s ease;
overflow: hidden;
}
.element:after {
position: absolute;
top: -60px;
content: 'some text';
font-size: 20px;
line-height: 20px;
left: 0;
display: inline-block;
background-color: #0c0;
transition: top 0.5s ease;
}
.element:hover:after {
top: 0px;
}
<div class="element">some text</div>
Hello i am trying to create hover effect on img.
HTML
<div>
<img src="http://placehold.it/350x150"/>
<div class="link-cont">click here to see more info</div>
</div>
css
div {
width: 350px;
position: relative;
}
.link-cont {
background: red;
position: absolute;
bottom: 0;
height: 100px;
opacity: 0;
transition: all 0.4s;
}
div:hover .link-cont {
opacity: 1;
bottom:-100px;
}
i need a something like this , when the user hover on it
but i am getting something like this
can someone help me to achieve what i am trying to do..
jsFid--> http://jsfiddle.net/Nnd7w/
You want like this, check DEMO http://jsfiddle.net/yeyene/Nnd7w/17/
div {
width: 350px;
font-size:12px;
position: relative;
}
div img{
padding:0 10px;
}
.link-cont {
background: red;
position: absolute;
bottom: 0;
width: 370px;
height: 210px;
opacity: 0;
transition: all 0.4s;
z-index: -1
}
div:hover .link-cont {
opacity: 1;
bottom:-40px;
}
.link-cont a{
opacity: 0;
}
div:hover .link-cont a{
position: relative;
opacity: 1;
bottom:-175px;
left:10px;
background:#fff;
color:red;
text-decoration:none;
padding:0 10px;
}
Try this - and let me know if it works for you..
Fiddle
Just a few changes - Could use some cleaning up.
div {
position: relative;
top: 50px;
background-color: blue;
width: 350px;
height: 150px;
margin: auto;
}
.link-cont {
background: red;
position: relative;
left: -50px;
top: -200px;
width: 450px;
height: 250px;
opacity: 0;
transition: all 0.4s;
z-index: -1
}
div a {
position: relative;
top: 210px;
left: 50px;
opacity: 0;
}
div:hover .link-cont {
opacity: 1;
}
a {
text-decoration: none;
color: #fff;
}
div:hover a {
opacity: 1;
}
Made a few modifications to you CSS
div {
width: 370px;
position: relative;
}
.link-cont {
background: red;
position: absolute;
top: 0;
width: 370px;
height: 200px;
opacity: 0;
transition: all 0.4s;
z-index: -1
}
div:hover .link-cont {
opacity: 1;
}
div:hover img {
margin-left: 10px;
margin-top: 10px;
}
.link {
display: block;
margin-top: 170px;
margin-left: 50px;
}
Instead of playing with bottom property, I just changed opacity. I also assigned a class to anchor tag to make it display under the image. Also, you can see I have given some margin to the image to make it center and changed the width and height of your link-count div.
See Fiddle
I just changed bottom:-100px; to top: 160px; and it works fine!
Fiddle
Edit: Some more options because I don't understand:
Fiddle, and the one I think you want: Fiddle (that one's messy, but the hover only activates if you actually hover on the image.)