Centering translated div inside div (css logo) - html

I'm experimenting with a logo in css. I build this with different div's.
The logo contains two parts, the right and the left part. Each part contains two div's with the 2d- front material and one with the 3d extrusion parts. These last two are each split up into an upper and a lower div.
I made the logo bigger than it is supposed to so I translated the outer div to the correct size. I wasn't able to set the measurements of that outer div to automatically wrap the translated div container, so I did this manually.
I want to add this css logo into a horizontal navigation list, one of the item's needs to contain this logo.
I'm breaking my head on how to align this div in the center of my list item. I searched for it but I can't seem to find a descent solution. Can someone put me in the right direction ? It would be much appreciated !
---> I gave the div main-nav-logo tbe same size as my list item, now I want to accomplish that I get the logo div in the center of the main-nav-logo div ...
.main-nav-logo {
position: relative;
width: 200px;
/* for testing purpose */
height: 144px;
/* for testing purpose */
text-align: center;
/* for testing purpose */
margin-left: auto;
/* for testing purpose */
margin-right: auto;
/* for testing purpose */
float: left;
/* for testing purpose */
overflow: auto;
/* for testing purpose */
padding: 0px;
display: table;
/* for testing purpose */
clear: both;
/* for testing purpose */
}
.logo {
position: relative;
top: -110px;
width: 300px;
height: 300px;
display: block;
margin-left: auto;
/* for testing purpose */
margin-right: auto;
/* for testing purpose */
-moz-transform: scale(0.351);
-webkit-transform: scale(0.351);
-o-transform: scale(0.351);
-ms-transform: scale(0.351);
transform: scale(0.351);
}
.left-cap {
position: relative;
height: 100%;
width: 100%;
left: 0;
}
.right-cap {
position: relative;
height: 100%;
width: 100%;
top: -100%;
left: 0;
}
.left-cap-front {
position: relative;
height: 100%;
width: 100%;
z-index: 3;
display: inline-block;
}
.left-cap-extrusion {
position: relative;
height: 100%;
width: 100%;
top: -102%;
z-index: 2;
}
.right-cap-front {
position: relative;
height: 100%;
width: 100%;
z-index: 3;
}
.right-cap-extrusion {
position: relative;
height: 100%;
width: 100%;
top: -100%;
z-index: 2;
}
.left-cap-front-upper {
position: absolute;
}
.left-cap-front-lower {
position: absolute;
}
.left-cap-extrusion-upper {
position: absolute;
}
.left-cap-extrusion-lower {
position: absolute;
}
.right-cap-front-upper {
position: absolute;
}
.right-cap-front-lower {
position: absolute;
}
.right-cap-extrusion-upper {
position: relative;
}
.right-cap-extrusion-lower {
position: relative;
}
<div class="main-nav-logo">
<div class="logo">
<div class="left-cap">
<div class="left-cap-front">
<div class="left-cap-front-upper">
</div>
<div class="left-cap-front-lower">
</div>
</div>
<div class="left-cap-extrusion">
<div class="left-cap-extrusion-upper">
</div>
<div class="left-cap-extrusion-lower">
</div>
</div>
</div>
<div class="right-cap">
<div class="right-cap-front">
<div class="right-cap-front-upper">
</div>
<div class="right-cap-front-lower">
</div>
</div>
<div class="right-cap-extrusion">
<div class="right-cap-extrusion-upper">
</div>
<div class="right-cap-extrusion-lower">
</div>
</div>
</div>
</div>
</div>
Hoping for some insight ... (Also if it means that I will have to rewrite the whole thing)
Thanks in advance !
A screenshot from the above code in JSFiddle gives me :
logo

Related

Iframe - Problems with centering

I have some problems with an iframe centering.
The code is setup to keep the same ratio, so it is 100% reposonsive.
This also causes VERY LIMITED possibilies for adding formattiong and - Centering
I have tired to both add a container box, and changing the css styling but I cant seam to get it to work...
any idears
<div class="background background_video">
<div id="video_container">
<div class="youtube-video-container">
<iframe class="youtube-video" src="https://www.youtube.com/embed/8aGhZQkoFbQ"></iframe>
</div>
</div>
</div>
.youtube-video-container {
padding-top: 56.25%;
height: 0px;
position: relative;
}
.youtube-video {
width: 60%;
height: 60%;
position: absolute;
top: 0;
left: 0;
border: 0;
}
.youtube-video-container {
height: 300px; // some height
position: relative;
}
.youtube-video {
width: 60%;
height: 60%;
position: absolute;
bottom: 0;
left: 0;
border: 0;
display: block;
}
as I correct understand question
FROM ANOTHER POST I FOUND...
Thanks for the trying to help anyways guys!
Without knowing the width/height of the positioned1 element, it is still possible to align it as follows:
EXAMPLE HERE
.child {
position: absolute;
top: 50%; /* position the top edge of the element at the middle of the parent */
left: 50%; /* position the left edge of the element at the middle of the parent */
transform: translate(-50%, -50%); /* This is a shorthand of
translateX(-50%) and translateY(-50%) */
}
It's worth noting that CSS Transform is supported in IE9 and above. (Vendor prefixes omitted
In this responsive 16:9 youtube css, all parents of #video_container have to be set to an height 100%.
Click on Run code, then 'Full page' to see the result.
html, body {
height: 100%;
margin: 0;
}
.background_video {
height: 100%;
display: flex;
}
#video_container {
width: 60%;
margin: auto;
}
.youtube-video-container {
position: relative;
display: block;
width: 100%;
padding: 0;
overflow: hidden;
}
.youtube-video-container::before {
display: block;
content: "";
padding-top: 56.25%;
}
.youtube-video-container iframe {
position: absolute;
top: 0; bottom: 0; left: 0;
width: 100%;
height: 100%;
border: 0;
}
<div class="background background_video">
<div id="video_container">
<div class="youtube-video-container">
<iframe class="youtube-video" src="https://www.youtube.com/embed/8aGhZQkoFbQ"></iframe>
</div>
</div>
</div>

How to I position something sticky so that it follows the screen in the center vertically

As you can see in my snippet I have almost acheived my desired effect, by using top: 50%;. But is not exactly centered on the screen. If I add transform: translateY(-50%); I do acheive centering, however now the red div is position too far up initially and doesnt go all the way to the bottom. Anyone got any ideas?
(also please note that I cant know the height of this red div because it is supposed to be an image first of all, and second I need it to be responsive meaning the height will change)
* {
margin: 0;
padding: 0;
}
.other_content {
height: 80vh;
width: 100%;
background-color: #eee;
}
section {
background-color: skyblue;
height: 300vh;
width: 100%;
position: relative;
}
.sticky {
position: sticky;
top: 50%;
/* transform: translateY(-50%); *//* DOES NOT WORK */
width: 90%;
margin-left: 5%;
background-color: red;
}
<div class="other_content"></div>
<section>
<div class="sticky">
<p>IMAGE WITH <br> UNKNOWN <br> HEIGHT <br> GOES HERE</p>
</div>
</section>
<div class="other_content"></div>
.sticky {
position: sticky;
top: 45%
/* transform: translateY(-50%); *//* DOES NOT WORK */
width: 90%;
margin-left: 5%;
background-color: red;
}
Just change the top percentage from 50% to 45%;
If I understand your question correctly, can you change the top to 40% to make it higher? 45% (should) perfectly align it in the middle.
* {
margin: 0;
padding: 0;
}
.other_content {
height: 80vh;
width: 100%;
background-color: #eee;
}
section {
background-color: skyblue;
height: 300vh;
width: 100%;
position: relative;
}
.sticky {
position: sticky;
top: 45%;
/* transform: translateY(-50%); *//* DOES NOT WORK */
width: 90%;
margin-left: 5%;
background-color: red;
}
<div class="other_content"></div>
<section>
<div class="sticky">
<p>IMAGE WITH <br> UNKNOWN <br> HEIGHT <br> GOES HERE</p>
</div>
</section>
<div class="other_content"></div>

Image not aligning horizontally after trying several common solutions

It works fine on Desktop because I use width: 100%. But on Mobile I do width: 50% and try to center it.
I have tried setting the img.youtube-thumb to margin-left: auto; and margin-right: auto; I've also tried setting the images parent element to text-align: center; and having the image displayed as inline-block, and that doesn't work either.
I'm not sure what else to try, as it seems that every S.O answer I run into provides one of the two above solutions.
Here's a CodePen but I'm not sure how valuable it'll be since I cant seem to get it exact without pasting the entire project into the pen. http://codepen.io/anon/pen/yOEQKg
Here's the HTML for one of the images:
<section class="container-fluid">
<div class="section group">
<div class="col span_6_of_12">
<div class="thumbnail project">
<h3>Some title</h3>
<div class="youtube-container">
<div class="youtube-player" data-id="ZMJP-FFzaZk">
<div>
<img class="youtube-thumb" src="//i.ytimg.com/vi/ZMJP-FFzaZk/hqdefault.jpg">
<div class="play-button"></div>
</div>
</div>
</div>
<div class="caption">
<p>blablablablabla</p>
</div>
</div>
</div>
my CSS code:
/* inside media query */
.youtube-player {
position: absolute;
text-align: center;
width: 100%;
height: 100%;
}
/* inside media query*/
img.youtube-thumb {
bottom: 0;
display: inline-block;
margin-left: auto;
margin-right: auto;
max-width: 50%;
width: 50%;
height: 100%;
position: absolute;
}
.project {
text-align: center;
}
/* for entire site */
.youtube-container {
position: relative;
padding-bottom: 300px; /* 16:9 */
padding-top: 25px;
height: 0;
}
/* for entire site */
div {
text-align: left;
}
/* 12 Grid Column Setup??? */
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
img.youtube-thumb {
bottom: 0;
display: inline-block;
margin-left: auto;
margin-right: auto;
max-width: 50%;
width: 50%;
height: 100%;
position: absolute;
}
into this:
img.youtube-thumb {
top: 0;
display:block;
left:0;
right:0;
margin:auto;
max-width: 50%;
width: 50%;
height: 100%;
position: absolute;
}
Hope it helps

Vertical centering image in unknown height div does not properly position image on mobile Safari/iOS

I'm using the vertical centering technique explained here on CSS-Tricks: http://css-tricks.com/centering-in-the-unknown
I have an image that needs to be vertically centered in a div. It seems to work just fine on every platform except mobile Safari/iOS, where the image is placed out of view. I can't seem to work out what the quirk or compliance issue is on mobile Safari that is causing this.
Here's the issue in a CodePen: http://codepen.io/anon/pen/iDalc
Here's my stripped down HTML and CSS
<div class="headline">
<div class="wrapper">
<a>
<div class="background">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Durga%2C_Burdwan%2C_2011.JPG/1920px-Durga%2C_Burdwan%2C_2011.JPG">
</div>
</a>
</div>
</div>
<div class="headline">
<div class="wrapper">
<a>
<div class="background">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Upper_Antelope_Canyon_Heart_Formation_2013.jpg/640px-Upper_Antelope_Canyon_Heart_Formation_2013.jpg">
</div>
</a>
</div>
</div>
<div class="headline">
<div class="wrapper">
<a>
<div class="background">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Maly_Krashokholmsky_bridge_4exp_Oloneo.jpg/1920px-Maly_Krashokholmsky_bridge_4exp_Oloneo.jpg">
</div>
</a>
</div>
</div>
And my CSS:
.headline {
background: gray;
padding: 0 3.125%;
width: 93.75%;
margin-left: auto;
margin-right: auto;
max-width: 768px;
}
.wrapper {
position: relative;
overflow: hidden;
min-height: 190px;
width: 100%;
margin-bottom: 2px;
}
.background {
position: absolute;
top: 0;
height: 100%; width: 100%;
z-index: 1;
background-color: #000;
text-align: center;
}
.background img {
width: 100%;
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.background:before {
content: "";
position: absolute;
z-index: 2;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
}
Can anyone advise what CSS issue is happening in mobile Safari? So far, I've diagnosed it may have something to do with the transform: translate-Y property. All mobile Safari testing done on device as well as iOS simulator.
Thanks in advance!
For anyone who comes across this in any searches, I managed to fix this on my own. Changed .background img to position: absolute; and left: 0;
I don't entirely understand what's going on but whatever it fixed it. I'd also like to add that I was mistaken in my original post. Somewhere I credited CSS Tricks for the vertical centering technique I implemented, which wasn't the actual source. I had referenced the following URL: http://davidwalsh.name/css-vertical-center
Updated CodePen: http://codepen.io/anon/pen/zJugd
.headline {
background: gray;
padding: 0 3.125%;
width: 93.75%;
margin-left: auto;
margin-right: auto;
max-width: 768px;
}
.wrapper {
position: relative;
overflow: hidden;
min-height: 190px;
width: 100%;
margin-bottom: 2px;
}
.background {
position: absolute;
top: 0;
height: 100%; width: 100%;
z-index: 1;
background-color: #000;
text-align: center;
}
.background img {
width: 100%;
position: absolute;
left: 0;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.background:before {
content: "";
position: absolute;
z-index: 2;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
}

html5/css3 DIV on DIVs layout issue

i have div area which is devided in to 4 equal parts, like the one atached.
now i need another div to be placed at the bottom area as an overlay to the above div. Imagine it like a text scroll area on the bottom side of the TV and the TV screen is constructed by 4 divs.
I am able to create the 5 divs. now the issue is that the 5th div(scroll area) is not going above the bottom edge of the 2 lower divs (3 and 4). I also had put z-index also but failed
can anybody share a sample for styling this.
You can solve it this way:
HTML:
<div class="area"></div>
<div class="area"></div>
<div class="area"></div>
<div class="area"></div>
<div class="overlay"></div>​
CSS:
.area{
float: left;
width: 49%;
height: 300px;
border: 1px solid black;
}
.overlay{
width: 200px;
height: 100px;
background-color: blue;
clear: both;
position: absolute;
bottom: 30px;
margin: -100px;
left: 50%;
}
​
Please note that I have used hard coded example values. The actual values depends on which context the markup is in.
Without your code it's hard to figure what's not working.
If I understand what you want this is what I would have done:
<div class="container">
<div class="block1"></div>
<div class="block2"></div>
<div class="block3"></div>
<div class="block4"></div>
<div class="overlay"></div>
</div>
css:
.container {
position: relative;
width: 600px; /* use the size you want */
height: 400px;
}
.container div {
position: absolute;
width: 50%;
height: 50%;
}
.container .block1 { top: 0; left: 0; background: pink; }
.container .block2 { top: 50%; left: 0; background: red; }
.container .block3 { top: 0; left: 50%; background: green; }
.container .block4 { top: 50%; left: 50%; background: blue; }
.container .overlay {
position: absolute;
width: 80%;
height: 100px;
left: 10%;
bottom: 30px; /* distance from the bottom */
z-index: 1;
background: yellow;
}