I'm using the transform:translateY();to hover text over two images.
The problem is that this method is not allowing me to position my text over specific parts of the images.
Ideally, I want to the freedom of being able to move the text more to the left, or to the right. At the moment I can only move the text up and down.
Alternatives method suggestions are always welcome.
Code is below and here is a codepen - (Hover the images with your screen full width as I haven't included media queries).
HTML
<div class="projects">
<div class="art-project1">
<img class="img-img" src="https://static.standard.co.uk/s3fs-public/thumbnails/image/2014/12/16/08/138188934.png" width="600" height="400" />
<p class="project-description1">Get Involved</p>
</div>
<div class="art-project2">
<img class="img-img" src="http://i.huffpost.com/gadgets/slideshows/343100/slide_343100_3557153_free.jpg" width="600"height="500" />
<p class="project-description2">Be Apart</p>
</div>
</div>
CSS
body {
background-color:#f5f5dc;
}
* {
box-sizing: border-box;
}
p {
color: #3232CD;
font-weight:bold;
font-size: 2rem;
}
.projects {
margin-left: auto;
margin-right: auto;
display: inline-block;
}
/* Images -------------------*/
.img-img {
padding-top: 80px;
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100%;
height: auto;
}
.art-project1 {
display: inline-block;
vertical-align: middle;
margin-left: 20%;
margin-right: auto;
max-width: 100%;
height: auto;
}
.art-project2 {
display: inline-block;
vertical-align: middle;
margin-left: -20%;
margin-right: auto;
margin-top:10%;
max-width: 100%;
height: auto;
}
.project-description1 {
position:absolute;
color: #3232CD;
visibility: hidden;
opacity: 0;
transform:translateY(-1000%);
}
.art-project1:hover .project-description1 {
visibility: visible;
opacity: 1;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
/* ...and now for the proper property */
transition:.70s;
}
.project-description2 {
position:absolute;
color: #3232CD;
visibility: hidden;
opacity: 0;
transform:translateY(-400%);
}
.art-project2:hover .project-description2 {
visibility: visible;
opacity: 1;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
/* ...and now for the proper property */
transition:.70s;
}
Try using translate() ;)
Hope this helps!
If you use position: absolute on an element, you first need to give its parent container position relative. Then you can simply use the top and left (or bottom and right parameters to position the absolute element, with percentage or pixel values - no need for transform: translateat all (unless you need exact centering).
body {
background-color:#f5f5dc;
}
* {
box-sizing: border-box;
}
p {
color: #3232CD;
font-weight:bold;
font-size: 2rem;
}
.projects {
margin-left: auto;
margin-right: auto;
display: inline-block;
}
/* Images -------------------*/
.img-img {
padding-top: 80px;
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100%;
height: auto;
}
.art-project1 {
position: relative;
display: inline-block;
vertical-align: middle;
left: 20%;
max-width: 100%;
height: auto;
}
.project-description1 {
position:absolute;
top: 15%;
left: 6%;
color: #3232CD;
visibility: hidden;
opacity: 0;
}
.art-project1:hover .project-description1 {
visibility: visible;
opacity: 1;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
/* ...and now for the proper property */
transition:.70s;
}
-moz-transition:.5s;
-webkit-transition:.5s;
/* ...and now for the proper property */
transition:.70s;
}
<div class="projects">
<div class="art-project1">
<img class="img-img" src="https://static.standard.co.uk/s3fs-public/thumbnails/image/2014/12/16/08/138188934.png" width="600" height="400" />
<p class="project-description1">Get Involved</p>
</div>
Related
I was building a meme with top and bottom text.
I am in need of rotating an image so I did it with transform: rotate(90deg);, but it's overlapped parent's div like the following example.
h1 {
margin-top: 100px;
}
.parent {
border: 1px solid black;
display: inline-block;
position: relative;
background: #777;
}
.parent .rotate {
transform: rotate(90deg);
width: 100px;
}
.parent h4 {
position: absolute;
left: 0;
right: 0;
text-align: center;
color: white;
z-index: 1;
}
.parent .top {
top: 10px;
}
.parent .bottom {
bottom: 10px;
}
<div class="parent">
<h4 class="top">Top Text</h4>
<img class="rotate" src="http://2.bp.blogspot.com/-7uOyzdXhG2Y/UVpJUbwqGzI/AAAAAAAAAo0/35w5N8tPvHE/s640/iphone-5-hd-wallpapers-hd-41664-tpmw7.jpg" />
<h4 class="bottom">Bottom Text</h4>
</div>
How can I change the style of the parent div to match the position and size of the rotated image?
First, we need to change the height of the div to be same as width.
We can do it by
.parent{
background-color: red;
width: 100%;
padding-top: 100%; /* 1:1 Aspect Ratio */
position: relative; /* If you want text inside of it */
}
Second, we need an additional div inside it that has absolute position with full width and height of it.
We can use flex to center the image inside that absolute div.
Here is a working code.
h1 {
margin-top: 100px;
}
.container {
display: inline-block;
width: 300px;
}
.parent {
border: 1px solid black;
display: inline-block;
position: relative;
background: #777;
width: 100%;
padding-top: 100%;
position: relative;
}
.p-absolute {
bottom: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
margin-top: auto;
margin-bottom: 0;
display: flex;
align-items: center;
justify-content: center;
}
.parent .rotate {
transform: rotate(90deg);
max-width: 100%;
max-height: 100%;
}
.parent h4 {
position: absolute;
left: 0;
right: 0;
text-align: center;
color: white;
z-index: 1;
}
.parent .top {
top: 10px;
}
.parent .bottom {
bottom: 10px;
}
<div class="container">
<div class="parent">
<h4 class="top">Top Text</h4>
<div class="p-absolute">
<img class="rotate" src="http://2.bp.blogspot.com/-7uOyzdXhG2Y/UVpJUbwqGzI/AAAAAAAAAo0/35w5N8tPvHE/s640/iphone-5-hd-wallpapers-hd-41664-tpmw7.jpg" />
</div>
<h4 class="bottom">Bottom Text</h4>
</div>
</div>
This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Inline block adding bottom space
(3 answers)
Closed 4 years ago.
So, there seems to be some whitespace added to an element on my page when I set the display to be inline-block. Is there a way to get rid of this white space without changing the line-height to 0px or changing the display type to block and manually setting a width? I may want the red element below to expand dynamically based upon the content in the future.
This is what I want (no green below the red):
This is what I am getting (green below the red):
Here's a JSFiddle of the issue: https://jsfiddle.net/rstL6omk/5/
The additional space is from the box model for laying out the "inline" elements including all inline-block or inline element. It seems like voodoo because you don't see it in the box-model for the elements involved. If you set font-size: 0; on .nav_container it goes away.
The problem is that you have overflow: hidden on your .logo_container. Removing this will get rid of the 4 pixels at the bottom of the element.
Then you simply need to make use of height: auto (the default for height) on .brand_logo_icon in order for it to expand based on its content.
This can be seen in the following:
body {
background: rgb(40, 40, 40);
font-family: Helvetica, Arial, sans-serif;
font-weight: lighter;
user-select: none;
-moz-user-select: -moz-none;
-webkit-user-select: none;
margin: 0;
cursor: default;
color: rgb(60, 60, 60);
}
div {
box-sizing: border-box;
}
#supports(padding: max(0px)) {
.container {
padding-left: max(0px, env(safe-area-inset-left));
padding-right: max(0px, env(safe-area-inset-right));
}
#nav .nav_container {
padding-left: max(0px, env(safe-area-inset-left));
padding-right: max(0px, env(safe-area-inset-right));
}
}
#nav {
padding: 0px;
display: block;
background: rgb(55, 155, 55);
}
.brand_logo_icon {
display: block;
background-color: rgb(200, 30, 30);
width: 60px;
}
#nav .logo_link {
position: relative;
display: block;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
width: 45px;
}
#nav .nav_container {
display: block;
max-width: 1300px;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
}
#nav .nav_container .logo_container {
display: inline-block;
padding: 0px;
background: rgb(80, 80, 80);
border-radius: 0px 0px 5px 5px;
margin-left: 10px;
margin-right: 10px;
margin-bottom: 0px;
}
#nav .nav_container .brand_logo_icon {
width: 70px;
}
.container {
display: block;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
margin-top: 0px;
transition: margin 225ms linear;
}
.container .splash:before {
content: "";
display: block;
padding-top: 56.2%;
}
.container .splash {
position: relative;
display: block;
width: 90vw;
max-width: 1300px;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
text-align: center;
}
.container .splash .splashimg {
display: block;
position: absolute;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
background-size: 100%;
background-repeat: no-repeat;
opacity: 0;
}
.container .content {
display: block;
position: relative;
left: 0;
richness: 0;
margin-left: auto;
margin-right: auto;
max-width: 1300px;
opacity: 1;
animation: introAnimation 400ms ease-in-out 0ms forwards;
vertical-align: top;
white-space: 0;
font-size: 0px;
}
.container .content.c {
text-align: center;
}
.container .content .home_img:before {
content: '';
display: block;
padding-top: 56%;
}
.container .content .home_img {
display: block;
background-color: rgb(30, 30, 90);
}
.container .content .item_block {
display: inline-block;
width: 50%;
padding: 10px;
vertical-align: top;
box-sizing: border-box;
text-align: center;
}
.container .content .item_block .poster:before {
content: '';
display: block;
padding-top: 151%;
}
.container .content .item_block .poster.sqr:before {
padding-top: 100%;
}
.container .content .item_block .poster {
display: block;
max-width: 550px;
background-position: center center;
background-size: 100%;
background-repeat: no-repeat;
background-image: url('/assets/no_poster.png');
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
}
<div id="nav">
<div class="nav_container">
<div class="logo_container">
<div class="brand_logo_icon">ABC ABC ABC ABC ABC ABC ABC ABC</div>
</div>
</div>
</div>
<div id="container" class="container">
<div class="content">
<div class="home_img"></div>
</div>
</div>
Sorry for the wording, i'm not sure exactly how to phrase it.
I have a header and a container which contains a sidenav and button to toggle it. I am trying to skew the header while keeping the container normal by skewing in the opposite direction. However doing this causes the sidenav to lose it's height:100% and it doesn't stick to the left.
How can i skew the background without affecting the sidenave?
Here is the fiddle and code
https://jsfiddle.net/q0ddzw4v/
HTML
<body id="body">
<header class="header">
<div class="header__container">
<div id="mySidenav" class="sidenav">
×
About
Services
Clients
Contact
</div>
<div id="main">
<h2>Sidenav Push Example</h2>
<p>Click on the element below to open the side navigation menu, and push this content to the right.</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
</div>
</div>
</header>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
</body>
CSS
body {
font-family: sans-serif;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}
.sidenav a:hover,
.offcanvas a:focus {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#main {
padding: 16px;
}
.header {
width: 100%;
height: 100vh;
background-color: #C18D8D;
transform: skewY(-10deg);
}
.header__container {
width: 80%;
max-width: 71.25rem;
margin: auto;
display: flex;
flex-direction: column;
height: 100%;
transform: skewY(10deg);
}
Instead of skewing the .header container, add a pseduo-element and skew it:
body {
font-family: "Lato", sans-serif;
transition: margin-left 0.5s;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}
.sidenav a:hover,
.offcanvas a:focus {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#main {
transition: margin-left .5s;
padding: 16px;
}
.header {
position: relative;
width: 100%;
height: 100vh;
}
.header::before {
display: block;
position: absolute;
width: 100%;
height: 100%;
background-color: #C18D8D;
transform: skewY(-10deg);
content: '';
}
.header__container {
position: relative;
z-index: 0;
width: 80%;
max-width: 71.25rem;
margin: auto;
display: flex;
flex-direction: column;
height: 100%;
}
<header class="header">
<div class="header__container">
<div id="mySidenav" class="sidenav">
×
About
Services
Clients
Contact
</div>
<div id="main">
<h2>Sidenav Push Example</h2>
<p>Click on the element below to open the side navigation menu, and push this content to the right.</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
</div>
</div>
</header>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
// document.getElementById("body").style.marginLeft = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
// document.getElementById("body").style.marginLeft = "0";
}
</script>
I have an animation with an iframe which is reduced and let appear my .project container but it looks like my red background for this class is not computed when I use Firefox or Chrome.
Codepen: http://codepen.io/kejoff/pen/bqmQXQ
HTML
<body>
Click to resize
<div class="container">
<div class="project">
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d338195.2873427642!2d2.2500731!3d48.530343949999995!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sfr!4v1490778528424" frameborder="0" style="border:0" allowfullscreen class="map"></iframe>
</div>
</div>
</body>
CSS
* {
padding: 0;
margin: 0;
}
.button {
padding: 10px;
margin: 2rem auto;
width: 6%;
background-color: #FFC72C;
display: block;
text-decoration: none;
color: #071D49;
}
.button:hover {
background-color: #071D49;
color: #FFC72C;
}
.container {
width: 1400px;
height: 90vh;
margin: 0 auto;
background-color: blue;
}
.project {
background: red;
width: 100%;
height: 100vh;
}
.map {
width: 100%;
height: 90vh;
display: block;
transition: all 1s linear;
}
.mapAnimationIn {
animation: resize-gmap 5s;
animation-fill-mode: forwards;
display: block;
}
/* Keyframe resize Gmap */
#keyframes resize-gmap {
from {
height: 90vh;
width: 100%;
}
to {
height: 18vh;
width: 10vw;
transform: translate(0, 72vh);
}
}
your .container class is getting applied. The problem is that your .project class container completely covers the parent container i.e. .container. Add padding to .container class or reduce width of .map class to below 100%, to see it work. You can do it like so -
.container {
width: 1400px;
margin: 0 auto;
background-color: blue;
padding: 20px;
}
.project {
background: red;
width: 100%;
}
.map {
width: 90%;
}
Also its generally a bad idea to hard code height. To make your page responsive, prefer dynamic width i.e. in % for example rather than in pixels.
Hope it helps
I have a section where it is to equal columns full width across. if you look a the 2nd column where it says content here if i do 100% on the jscroll-pane it shows horizontal bars, if i give it 98% it works properly but is not full width of the column. not sure why it adds horizontal bars to 100% but not 98%. I am not sure if foundation is causing my issue or not but if i take it out of the column and put in a row the 100% works fine just not in a large-6
html
<section id="component">
<div class="row expanded collapse">
<div class="large-6 column">
<img src="images/image.png">
</div>
<div class="large-6 column">
<div class="jscroll-pane">
Content Here
</div>
</div>
</div>
</section>
css
.jscroll-pane {
display: block;
width: 100% !important;
height: 400px;
max-height: 400px;
overflow: auto;
background-color: #fff;
}
#component {
padding: 0px;
background-color: #fff;
}
jscroll external css file
.jspContainer{
overflow:hidden;
position:relative;
height:100% !important;
width: 100% !important;
}
.jspPane{
position:absolute;
width: 100%!important;
}
.jspVerticalBar
{
position: absolute;
top: 0;
right: 0;
width: 16px;
height: 100%;
background: red;
}
.jspHorizontalBar
{
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 16px;
background: red;
}
.jspCap
{
display: none;
}
.jspHorizontalBar .jspCap
{
float: left;
}
.jspTrack
{
background: #d8d8d8;
position: relative;
}
.jspDrag
{
background: #000;
position: relative;
top: 0;
left: 0;
cursor: pointer;
}
.jspHorizontalBar .jspTrack,
.jspHorizontalBar .jspDrag
{
float: left;
height: 100%;
}
.jspArrow
{
background: #50506d;
text-indent: -20000px;
display: block;
cursor: pointer;
padding: 0;
margin: 0;
}
.jspArrow.jspDisabled
{
cursor: default;
background: #80808d;
}
.jspVerticalBar .jspArrow
{
height: 16px;
}
.jspHorizontalBar .jspArrow
{
width: 16px;
float: left;
height: 100%;
}
.jspVerticalBar .jspArrow:focus
{
outline: none;
}
.jspCorner
{
background: #eeeef4;
float: left;
height: 100%;
}
/* Yuk! CSS Hack for IE6 3 pixel bug :( */
* html .jspCorner
{
margin: 0 -3px 0 0;
}
Try this, Remove the display block and change overflow: auto to hidden; I believe this should help you.
.jscroll-pane {
width: 100% !important;
height: 400px;
max-height: 400px;
overflow: hidden;
background-color: #fff;
}