I have this hamburger I'm creating. I'm trying to understand how to position the bars with precise calculation without eyeballing it. The hamburger height is 24px
so I would assume in order to position the middle bar it would be half the height so 12px(top: 12px;) or incase of the example 0.5em but that doesn't look centered to the overall menu. (top: 10px looks right or 0.625em).
Overall whats a better way to calculate anything in css?
http://codepen.io/anon/pen/Bjjqez
<div class="hamburger">
<div class="hamburger__top"></div>
<div class="hamburger__middle"></div>
<div class="hamburger__bottom"></div>
</div>
SASS
.hamburger {
position: relative;
width: 3em;
height: 1.5em;
cursor: pointer;
div {
background-color: red;
position: absolute;
width: 100%;
height: .25em;
}
&__top {
top: 0;
}
&__middle {
background-color: green;
top: 0.5em;
}
&__bottom {
bottom: 0;
}
}
Flexbox can do that....no positioning required.
Here's a couple of options.
.hamburger {
width: 3em;
height: 1.5em;
cursor: pointer;
display: flex;
flex-direction: column;
margin: 1em auto;
}
.hamburger div {
background-color: red;
height: .25em;
}
.around {
justify-content: space-around;
background: lightblue;
}
.between {
justify-content: space-between;
background: lightgreen;
}
<div class="hamburger around">
<div class="hamburger__top"></div>
<div class="hamburger__middle"></div>
<div class="hamburger__bottom"></div>
</div>
<div class="hamburger between">
<div class="hamburger__top"></div>
<div class="hamburger__middle"></div>
<div class="hamburger__bottom"></div>
</div>
Replace your top: 0.5em with:
top: 50%;
transform: translateY(-50%);
From my understanding of how this works, the top: 50% will move the top of the element to be half way down. The translateY(-50%) will then move the element up by half it's own height, and therefore centrally position it.
Example: http://codepen.io/anon/pen/RrrqWP
Related
I tried putting the animated image into a table, but the animation doesn't work in that case.
I can only use HTML and CSS to make this work.
I'm wanting to center the green, spinning circle on the page both vertically and horizontally, have the logo sit without spinning inside of the circle, and have text that changes every 5 seconds right beneath it, centered horizontally and not too far vertically from the edge of the circle.
Right now, with the following code, the mobile version looks like:
(The red circle circles the logo, which is also appearing smaller than I want it to be)
The desktop view currently looks like:
As you can see here, the logo is still slightly off center vertically and the circle is really close to the top of the screen, rather than center.
So far I have in HTML:
<div id="animatedLogo">
<div id="loadingCircle">
<img id="loadingLogo" src="../Content/images/HCSS_GooglePresentation_Spinner_Green.PNG" class="circle" />
</div>
<div id="wordLogo">
<img id="HCSSLogo" src="../Content/images/hcss logo2.jpg" class="logo" />
</div>
<div id="myPhrase" class="phrase"></div>
</div>
<div class="main-container container-fluid">
<div class="row">
<div class="span6">
<form method="post" action="{responseUri}">
{responseFields}
</form>
</div>
</div>
</div>
<link href="../Content/please-wait.css" rel="stylesheet" />
<script src="/Scripts/logoAnimation.js"></script>
<script src="/Scripts/formPostResponse.js"></script>
And in CSS I have:
#animatedLogo {
text-align: center;
}
#loadingLogo {
animation: rotation 2.5s infinite linear;
min-height: 100%;
min-width: 35%;
padding: 1% 0;
}
#keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
#loadingCircle {
min-height: 77%;
min-width: 35%;
}
#wordLogo {
width: 100%;
height: 67%;
position: absolute;
top: 0;
left: 0;
/*padding: 5% 0;*/
margin-top: 5%;
}
.circle {
}
.logo {
width: 10%;
padding: 11% 0;
}
.phrase {
font-family: "Proxima Nova", sans-serif;
font-size: 24px;
font-style: oblique;
position: absolute;
/* top: 625px; */
margin-left: 50%;
/* text-align: center; */
transform: translateX(-50%);
}
(Added 3:58 pm on 6/20) In addition, I need to make sure the circle doesn't alter its shape and become an oval like it did here when I changed my solution to fit a suggested answer:
Added at 8:19 a.m. on 6/21/18The circle no longer becomes an oval! However, nothing is centered now.
Update as of 9:24 am
We're getting closer!!
1) I realize that I probably should pick a certain ratio of the size of the logo to the size of the spinner to use so that the logo doesn't get so small on mobile versions. I'm searching the web for ideas, but if you know of one particularly fitting for this project, let me know!
2) Now we need to get the phrases under the spinner, rather than out to the side.
Update 3
Bring the phrase out of the centered class like this:
<div id="centered">
<div id="animatedLogo">
<div id="loadingCircle">
<img id="loadingLogo" src="../Content/images/HCSS_GooglePresentation_Spinner_Green.PNG" class="circle" />
</div>
</div>
<div id="wordLogo">
<img id="HCSSLogo" src="../Content/images/hcss logo2.jpg" class="logo" />
</div>
</div>
<div id="myPhrase" class="phrase">phrase phrase phrase phrasephrase</div>
Then in the css change this:
.phrase {
font-family: "Proxima Nova", sans-serif;
font-size: 4vmin;
font-style: oblique;
position: absolute;
bottom: 20px;
width: 100%;
left: 50%;
height: 10%;
text-align: center;
transform: translateX(-50%);
}
To change things on smaller screens use media query:
#media only screen and (max-width: 767px) {
.someClass {
color: red;
}
}
Update 2
Okay, I tested things out and this should work:
html:
<div id="centered">
<div id="animatedLogo">
<div id="loadingCircle">
<img id="loadingLogo" src="../Content/images/HCSS_GooglePresentation_Spinner_Green.PNG" class="circle" />
</div>
</div>
<div id="wordLogo">
<img id="HCSSLogo" src="../Content/images/hcss logo2.jpg" class="logo" />
</div>
<div id="myPhrase" class="phrase"></div>
</div>
css:
#centered {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#wordLogo {
position: absolute;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
/* height: 67%; */
/* position: absolute;
top: 0;
left: 0; */
/*padding: 5% 0;*/
/* margin-top: 5%; */
}
update
Try this out if flexbox is not working:
#loadingCircle, #wordLogo {
position: relative;
}
#loadingCircle img, #wordLogo img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Try using flexbox:
#loadingCircle, #wordLogo {
display: flex;
justify-content: center;
align-items: center;
}
Let me know if it works or not.
I have the following code for putting my signature in the footer of a website: https://codepen.io/BarrieO/pen/ayQxoZ
However, when implemting the code on my Wordpress website (http://bartoml215.215.axc.nl/), the icons within the divs are not centered as in the Codepen. I think this has to do with the css property align-items: center for my .icon-footer class, but not sure?
To be clear: I want to allign the icons perfectly in the middle of the rounded squares, not in the bottom-middle as currenctly on the website. I want the same result as in the Codpen.
How come my icons are not alligned in the .icon-footers divs?
You need to do 3 modifications for it to work for your website:
1- Change the main wingedHelmet element class to main-icon-footer
<div id="starter" class="main-icon-footer ">
<img src="https://www.petasos.be/wp-content/uploads/2017/05/wingedHelmetSmall.png" class="petasos">
</div>
2- Add the class main-icon-footer to your CSS file
.main-icon-footer {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
border-radius: 25%;
background: white;
border: 1px #818181 solid;
}
3- Remove align-items: center; from .icon-footer in your CSS file
.icon-footer {
position: absolute;
display: flex;
justify-content: center;
width: 50px;
height: 50px;
border-radius: 25%;
background: white;
border: 1px #818181 solid;
}
This is a fix. I tested it on your site.
I really prefer if you do this. but if you don't want this... go below..
note that for this to work you have to replace this code below with the "bottom-bar" div that you already have...
<div id="bottom-bar" class="solid-bg" role="contentinfo">
<div class="wf-wrap">
<div class="wf-container-bottom">
<div class="wf-table wf-mobile-collapsed" style="
text-align: center;
padding-top: 15px;
">
<div id="starter" class="icon-footer" style="
transform: none;
position: static;
margin: auto;
">
<img src="https://www.petasos.be/wp-content/uploads/2017/05/wingedHelmetSmall.png" class="petasos">
</div>
</div>
</div><!-- .wf-container-bottom -->
</div><!-- .wf-wrap -->
</div>
ok the second solution:
just change this css selectors to what i have provided below:
#starter {
cursor: pointer;
width: 70px;
height: 50px;
z-index: 5;
/* left: 215px; */
/* transform: translate(-100%, -100%); */
transition: all 0.6s linear;
filter: invert(100%);
}
.iconHolder {
position: absolute;
/* top: 57px; */
width: 215px;
/* right: 20px; */
}
I am trying to create a graoh to show positive and negative value by percentage so if value will be negative it will be red bar if value will be positive it will run red bar so the thing is that I am having issue when I set width to 46 or 50% the bar is showing to be of full size as it shouldn't be can anyone help me out with this please
.box {
position: relative;
width: 400px;
height: 30px;
background-color: #333
}
.bar_red {
background-color: #d40216 !important;
left: 50%;
width: 13%;
max-width: 180px;
}
.bar_green {
right: 50%;
}
.bar_green,
.bar_red {
width: 42%;
height: 20px;
background-color: #88c500;
position: absolute;
top: 50%;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
}
<div class="box">
<div class="bar_red" style="width: 50%;"></div>
<div class="bar_green" style="width: 50%;"></div>
</div>
https://jsfiddle.net/vck8wchh/
First of all your bars are pulled 50%. see example below
.bar_green {
right: 50%;
}
.bar_red {
left: 50%;
}
So this means that if you fill in 50% or higher in your <div style="50%"> it will be full width. Go to your fiddle and for example replace your HTML with the following:
<div class="box">
<div class="bar_red" style="width: 10%;"></div>
<div class="bar_green" style="width: 30%;"></div>
</div>
You'll see that they won't be fully filled. new jsfiddle
May I suggest a simpler solution? In my snippet the green bar is 100% wide, while the red bar gets a percentage width, is right-aligned and covers the green one using a higher z-index. So you only have to set the percentage of the red bar.
.box {
position: relative;
width: 390px;
height: 20px;
background-color: #333;
border: 5px solid #333;
}
.bar_green,
.bar_red {
height: 20px;
position: absolute;
}
.bar_green {
left: 0;
width: 100%;
background-color: #88c500;
z-index: 1;
}
.bar_red {
background-color: #d40216 !important;
right: 0;
width: 42%;
z-index: 2;
}
<div class="box">
<div class="bar_red"></div>
<div class="bar_green"></div>
</div>
I have tried adapting this post and its alistapart links. But I can't get my three blocks in a container to act responsively and maintain their aspect ratio
<div class="hpGridTopRow">
<span class="hpBox lightBlue one">
<p class="hbBoxesp">New to Restore</p>
</span>
<span class="hpBox green two">
<p class="hbBoxesp">Events</p>
</span>
<span class="hpBox midBlue three">
<p class="hbBoxesp">Talks</p>
</span>
</div>
I need them to arrange themselves to the borders of the hpGridTopRow div so I am using flex - and its working well.
However, the layout has to be responsive - the aspect ratio of the containers needs to stay fixed as their widths change.
Here's the css
.hpGridTopRow,
.hpGridBottomRow {
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
position: relative;
padding-bottom: 20%;
height: 0;
overflow:hidden;
background:yellow;
}
.hpBox {
width:24.18803418803419%;
text-align:center;
height:264px;
height:100%;
}
.hpBox.one {
width:49.4017094017094%;
}
.lightBlue {
background:#15b2d2;
}
.green {
background:#8cc63f;
}
.midBlue {
background:#6a8aa8;
}
.hbBoxesp {
color:#fff;
margin-top:40px;
}
I have created a jsfiddle - as you can the container background shows, but not the actual boxes and said container is behaving responsively.
How can I get the spans to behave properly?
I've removed those extra colors and simplified the percentages to simplify the code.
The idea is that I've added position: relative; to the parent and position: absolute; to the children. This ensures that the children positions are bounded to the parent.
I've also added top: 0; bottom: 0; to the children, to make the children span spans the height as the parent div.
Then you have to place the spans in the correct places by using left and right positioning.
.hpGridTopRow {
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
position: relative;
padding-bottom: 20%;
height: 0;
overflow: hidden;
background: yellow;
position: relative;
}
.hpBox {
width: 25%;
text-align: center;
position: absolute;
top: 0;
bottom: 0;
}
.hpBox.one {
width: 50%;
}
.hpBox.two {
left: 50%;
}
.hpBox.three {
right: 0;
}
.lightBlue {
background: #15b2d2;
}
.green {
background: #8cc63f;
}
.midBlue {
background: #6a8aa8;
}
.hbBoxesp {
color: #fff;
margin-top: 40px;
}
<div class="hpGridTopRow">
<span class="hpBox lightBlue one">
<p class="hbBoxesp">New to Restore</p>
</span>
<span class="hpBox green two">
<p class="hbBoxesp">Events</p>
</span>
<span class="hpBox midBlue three">
<p class="hbBoxesp">Talks</p>
</span>
</div>
I have a container div for the main content but am trying to have a sidebar float to the left of it. For example (http://www.bureautonic.com/en/) the menu button.
This is the code
.main-wrapper {
position: relative;
top: 50%;
height: 500px;
}
.container {
position: relative;
height: 100%;
}
.body {
height: 100%;
}
.slider {
display: block;
width: 940px;
height: 500px;
margin-right: auto;
margin-left: auto;
float: none;
}
.img {
position: absolute;
width: 100%;
height: 100%;
max-height: 100%;
}
.tagline {
position: absolute;
left: 50%;
top: 50%;
z-index: 1;
display: block;
width: 332px;
margin-right: auto;
margin-left: auto;
padding: 1em 3em;
border: 1px solid white;
-webkit-transform: translate(-50%, 0px) translate(0px, -50%);
-ms-transform: translate(-50%, 0px) translate(0px, -50%);
transform: translate(-50%, 0px) translate(0px, -50%);
font-family: 'Josefin Sans', sans-serif;
color: white;
text-align: center;
text-decoration: none;
text-transform: none;
}
.header {
margin-top: 33px;
margin-bottom: -61px;
}
.brand {
font-family: Cardo, sans-serif;
text-align: center;
}
<body class="body">
<div class="w-section container">
<div class="w-container header">
<h1 class="brand">The One And Only</h1>
</div>
<div class="w-container main-wrapper">
<div data-animation="outin" data-duration="500" data-infinite="1" data-easing="ease-in-cubic" data-hide-arrows="1" class="w-slider slider">
<div class="w-slider-mask">
<div class="w-slide slide">
<div class="tagline">
<h1>Marc Cain</h1>
<h3>F/W 2015-16</h3>
</div>
<img width="846" src="http://uploads.webflow.com/567a26541a69a693654038a1/567b15da06a9675444fc740d_marc_cain_campaign.jpg" class="img">
</div>
</div>
<div class="w-slider-arrow-left">
<div class="w-icon-slider-left"></div>
</div>
<div class="w-slider-arrow-right">
<div class="w-icon-slider-right"></div>
</div>
<div class="w-slider-nav"></div>
</div>
</div>
</div>
</body>
I'm using webflow and uploaded the site for you guys http://the-one-and-only.webflow.io/
I originally tried making another absolute div with a set width and 100% height, but the menu button wasn't relative to the main container. Any help would be appreciated.
Give this a look, it mimics what http://www.bureautonic.com/en/ has for their menu
$(function() {
$('#menu-container').click(
function() {
ToggleMenu();
}
);
});
function ToggleMenu() {
var $menu = $('#menu');
var newleft = +$menu.css('left').replace('px', '') <= -150 ? '0' : '-300px';
$('#menu').css('left', newleft);
}
#menu,
#content {
width: 300px;
height: 200px;
}
#menu-container {
display: inline-block;
height: 200px;
width: 30px;
background-color: yellow;
position: relative;
}
#menu {
display: inline-block;
position: absolute;
}
#content {
display: inline-block;
position: relative;
overflow: hidden;
background-color: red;
}
#menu {
transition: left 1s;
left: -300px;
background-color: orange;
}
#menu-label {
-moz-transform: translateX(-50%) translateY(-50%) rotate(-90deg);
-webkit-transform: translateX(-50%) translateY(-50%) rotate(-90deg);
transform: translateX(-50%) translateY(-50%) rotate(-90deg);
position: absolute;
top: 50%;
text-align: center;
width: 200px;
left: 50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div id="menu-container">
<div id="menu-label">
This is my Menu Label
</div>
</div>
<div id="content">
This is the content
<div id="menu">
Menu
</div>
</div>
For the sliding menu
The basic concept is a parent div with position:relative and overflow:hidden , and a child div with position:absolute, beginning with a negative left equal to the width of the div
I used the css transition property for the smooth slide effect
Edit:
For the left aligned & rotated menu label
This effect is created with a combination of several properties.
My code block has been updated with the appropriate css.
See here http://jsfiddle.net/CCMyf/79/ (not my fiddle) for alterations
to the css if you need to have a dynamic height
If you want to float a menu to left of the main content, you need to firstly create the menu element that you want to be the menu (obviously), then float it to the left with float: left. e.g.
HTML
<div class="floated-menu">
Menu
</div>
CSS
.floated-menu {
float: left;
width: 50px;
height: 600px;
background-color: #ccc;
}
Then you have to float the main content container as well. .e.g
.container {
float: left;
position: relative;
width: 800px;
height: 100%;
}
I could be wrong, but I believe if you don't float both the items, the normal (non-floated context) behaviour of the container divs display: block; property kicks in and it will move down the page to the next "line". Which is weird because all items next to something thats floated should lose their display block behaviour and sit next to the floated item - i.e. float was originally intended to make block type headings and paragraphs sit next to pictures like in a magazine or newspaper, but yep, welcome to the world of CSS - you fill find many nonsensical things like this.
Also, the combined width of both floated elements border box (the widest and largest of the boxes that an element is contained in) cannot be wider than their parent element - other wise the second element will drop down to the next line - which actually does make sense. I have reduced the sizes for you in my demo, but you will have to manage that as you build your page.
You also need to remember that, by default the browser uses the
"content-box" box-sizing property. from the docs
content-box
This is the default style as specified by the CSS standard. The width
and height properties are measured including only the content, but not
the padding, border or margin. Note: Padding, border & margin will be
outside of the box e.g. IF .box {width: 350px}; THEN you apply
{border: 10px solid black;} RESULT {rendered in the browser} .box
{width: 370px;}
Here is a demo - http://codepen.io/anon/pen/QyKyVV?editors=110