How can I position these buttons at the bottom of their container? - html

I've made a site that has a section containing a background image. I've added two buttons (<a> elements) to it and I want to position them to the bottom center of the section. Is that possible without relative/absolute positioning?
If, so, how please?
.main-section {
background-image: url('../IMG/main-section-logo.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 80vh;
}
.main-section:hover,:focus {
transform:scale(1.015);
transition: 1s ease;
}
.main-section:not(:hover) {
transform:scale(1);
transition: 1s ease;
}
.buttons {
text-align: Center;
text-decoration: none;
}
.btn-red {
color: white;
border: 1px solid red;
padding: 1.3em 6.2em;
}
.btn-white {
color: red;
border: 1px solid white;
padding: 1.3em 5em;
}
<section class="main-section">
<div class="container">
<div class="buttons">
BUY NOW
WATCH TRAILER
</div>
</div>
</section>

Solution
By using flexbox
.container must occupy the entire verticle space by using height: 100%
Add flexbox set of properties on .container
.main-section .container {
height: 100%;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
Apply auto top margin to .buttons, which will automatically extend its specified margin to occupy the extra space in the flex container
.main-section {
background-image: url('../IMG/main-section-logo.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 80vh;
}
.main-section:hover,:focus {
transform:scale(1.015);
transition: 1s ease;
}
.main-section:not(:hover) {
transform:scale(1);
transition: 1s ease;
}
.main-section .container {
height: 100%;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.buttons {
margin-top: auto;
text-align: Center;
text-decoration: none;
}
.btn-red {
color: white;
border: 1px solid red;
padding: 1.3em 6.2em;
}
.btn-white {
color: red;
border: 1px solid white;
padding: 1.3em 5em;
}
<section class="main-section">
<div class="container">
<div class="buttons">
BUY NOW
WATCH TRAILER
</div>
</div>
</section>

Yes, you can do so using flexbox.
Try the code below
.buttons {
display: flex;
align-items: flex-end;
justify-content: center;
}
This should hopefully solve your problem.
Some resources to learn Flexbox:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://flexboxfroggy.com

What if you use flexbox on .main-section :
display: block;
Or
display: flex;
flex-direction: column;
Take a look at that https://developer.mozilla.org/fr/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox
Is it ok for you with flexbox?
Axel,

Have a look at place-items: end;
*{box-sizing: border-box;}
.main-section {
background-image: url('../IMG/main-section-logo.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 80vh;
}
.main-section:hover,:focus {
transform:scale(1.015);
transition: 1s ease;
}
.main-section:not(:hover) {
transform:scale(1);
transition: 1s ease;
}
.buttons {
text-align: Center;
text-decoration: none;
width: 100%;/*Add this to get the elements centered*/
}
.btn-red {
color: white;
border: 1px solid red;
padding: 1.3em 6.2em;
}
.btn-white {
color: red;
border: 1px solid white;
padding: 1.3em 5em;
}
/*have a look # place-items: end;*/
.container{
height: 90vh;
display: grid;
place-items: end;
}
<section class="main-section">
<div class="container">
<div class="buttons">
BUY NOW
WATCH TRAILER
</div>
</div>
</section>

you can try it
.buttons{
display:flex;
flex-direction:column;
align-items:flex-end;
justify-content:center;
}

Related

How to make the dark mode effect hit the circles designed with css

I'm using this dark mode toggle that affect all the text plus the background color and when I click on it the colors they switch. But I have a problem with the circles that I've designed. I'd like the dark mode affect the background color of them, having the background inside the circles "lime" on the black background and viceversa. Here's the code and the link to the page:
https://civitonia.com/26993899
HTML:
<div class="grid">
<div class="cell">
<div class="inner">
<div class="circle" style="background-image:url('https://freight.cargo.site/t/original/i/655f74e74d3b88cc9d367ba8cccd79680c3837a84a547f9e03b6f39981f424e0/3.png');"></div>
<div class="caption">
<h3>Chiara Bersani <br> Marta Montanini</h3>
</div>
</div>
</div>
DARK MODE CSS:
.colorOuterSVG {
color: black;
margin-top: 2em;
padding: 0.5em
}
.colorOuterSVG .dark { display: none }
.colorOuterSVG .light { display: block }
.dark-mode .colorOuterSVG {color:#d9ff76!important; }
.dark-mode .colorOuterSVG .dark { display: block }
.dark-mode .colorOuterSVG .light { display: none }
.colorSVG { display: block }
.colorSVG path { fill: currentColor }
.dark-mode {
background-color: black!important;
color: #d9ff76!important;
}
.dark-mode button {
color: black!important;
background-color: #d9ff76;
padding: 5px 5px 5px 5px;
border-radius: 15px;
border: solid 1px #000000;
cursor: pointer;
position: absolute;
bottom: 10px;
}
THE CIRCLES MADE WITH CSS:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.grid {
display: flex;
flex-wrap: wrap;
max-width: 980px;
width: 100%;
margin: auto;
padding-top: 5%;
padding-bottom: 5%;
}
.cell {
flex-basis: 33.3%;
display: flex;
justify-content: center;
align-items: center;
align-items : flex-start
}
.cell:before {
padding-bottom: 100%;
display: block;
content: '';
}
.circle {
width: 250px;
height: 250px;
border: 0.5px solid;
border-radius: 50%;
background-position: center;
background-size: contain;
background-repeat: no-repeat;
box-shadow: 0px 0px 15px 0px;
overflow: hidden;
margin: 0 auto 1em;
background-color: #d9ff76!important;
}
.circle img {
width: 100%;
position: relative;
height: 100%;
}
h3 {
text-align: center;
}
.inner {
text-align: start;
padding-bottom: 30%;
}
Right now I've set up a background color for the circles and if I take it away the background will stay lime on lime and black on black!
Add this css code for dark mode :
.dark-mode .circle {
background-color: #000 !important;
}

How to zoom a picture while make it contained

my "wrapper" div is the most outlayer container. It consists of a picure and some text below.
I want to use CSS (not yet learned JS...) method to realize the effect that, when mouse hovering over the picure area, the picure zoom-in a little, but still remain inside the shadowed box.
Below is my html code and css code. It did give me zoom-in effect, but the picture just ... stick out, how can I fix this (hopefully without using Javascript)
-- html code --
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>shadow block | link with graphics and info</title>
<link rel="stylesheet" type="text/css" href="sectionlink_pic.css">
</head>
<body>
<div class="wrapper">
<div class="image">
<img src="https://images.pexels.com/photos/262508/pexels-photo-262508.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
</div>
<div class="infocontent">
<h3>Home Security Blog</h3>
</div>
</div>
</body>
</html>
-- css --
.wrapper {
display: flex;
flex-direction: column;
width: 400px;
justify-content: center;
align-items: center;
border-radius: 3rem;
box-shadow: 0.6rem 0.6rem 1.2rem #d2dce9, -0.5em -0.5em 1em #ffffff;
padding: 2rem;
z-index: 100;
}
.wrapper:hover {
text-shadow: 5px 5px 4px lightgray;
transition-duration: 0.2s;
cursor: pointer;
}
.wrapper .image img {
width: 100%;
object-fit: cover;
border-radius: 2rem;
cursor: pointer;
}
.wrapper .image:hover img {
transform: scale(1.5);
}
.wrapper .infocontent {
display: flex;
justify-content: center;
align-items: center;
font-family: Consolas;
color: #36187d;
cursor: pointer;
}
body {
background-color: #f2f3f7;
padding-top: 90px;
padding-left: 100px;
}
Add transition to your image
Add overflow (hidden) and border-radius to the image wrapper DIV:
body {
background-color: #f2f3f7;
}
.wrapper {
display: flex;
flex-direction: column;
width: 400px;
justify-content: center;
align-items: center;
border-radius: 3rem;
box-shadow: 0.6rem 0.6rem 1.2rem #d2dce9, -0.5em -0.5em 1em #ffffff;
padding: 2rem;
z-index: 100;
transition-duration: 0.2s; /* ADD */
}
.wrapper:hover {
text-shadow: 5px 5px 4px lightgray;
cursor: pointer;
/*transition-duration: 0.2s; REMOVE */
}
.wrapper .image {
overflow: hidden; /* ADD */
border-radius: 2rem; /* ADD */
}
.wrapper .image img {
width: 100%;
object-fit: cover;
/* border-radius: 2rem; REMOVE */
cursor: pointer;
transition: transform 1s; /* ADD */
}
.wrapper:hover img { /* EDIT */
transform: scale(1.5);
}
.wrapper .infocontent {
display: flex;
justify-content: center;
align-items: center;
font-family: Consolas;
color: #36187d;
cursor: pointer;
}
<div class="wrapper">
<div class="image">
<img src="https://images.pexels.com/photos/262508/pexels-photo-262508.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
</div>
<div class="infocontent">
<h3>Home Security Blog</h3>
</div>
</div>

How do I get rid of this phantom element in my button

The phantom whitespace
<button onClick={onDropdownClick} className="menu-trigger">
<img
className="google-profile-photo"
src={currentUser.photoURL}
alt="User Avatar"
/>
<span>
<ArrowDown />
</span>
</button>
I want the img tag and the span to be next to each other with no space in between. I cannot get rid of this whitespace in the middle. Does anyone know how?
.menu-trigger {
display: flex;
width:auto;
min-height: 5rem;
position: relative;
background: white;
border-radius: 0.3rem;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
padding: 4px 6px;
box-shadow: 8px 16px 5rem #eeeeee;
vertical-align: middle;
transition: box-shadow 0.4s ease;
margin-top: 1rem;
border: none;
}
.google-profile-photo {
border-radius: 50%;
margin: 2%;
width: 50%;
height: 100%;
}
You'll need to give the image element flex: 1 so it can fill up that space. Here's a somewhat minimized example...
.menu-trigger {
display: flex;
min-height: 3rem;
position: relative;
background: white;
cursor: pointer;
align-items: center;
padding: 4px 6px;
border: 1px solid black;
width: auto;
}
.google-profile-photo {
margin: 2%;
border-radius: 50%;
flex: 1;
height: 100%;
}
<button class="menu-trigger">
<img
class="google-profile-photo"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAAADFBMVEXU3ej///8AAAATExOMrozEAAAAdElEQVR4XpXPsQ2DMBRF0StX4D1c4IYRmAJkeQKPwRL0NJGQp6OK0hG9L5wqRXKbf6RXfX4qrvhDCDtDXoVCWBAS4SlML8KlaTyJDa4K/9QZHPhqQT+r5Rt8g/tgu8FDyMAgJMBrK9zbLsRttneg5gMLu603mI0q2s7nekMAAAAASUVORK5CYII="
alt="User Avatar"
/>
<span>
↓
</span>
</button>
use this:
justify-content: center;
and this for your second question :
background-size: cover

How can i make css animation

i have 2 images, and one background:
(red and brown are images)
(white is background)
When i hover on first or second image it will slide to left/right side. Like a doors in shop. Slide both in same time (no only one).
Can someone help me? Thanks.
I tried the accepted answer but it's a bit buggy (in firefox more so) if you put your cursor over the center and it bounces the sides back and forth and doesn't open. Personally I'd do something more like this.
CODEPEN TO PLAY WITH
#stage {
width: 20rem;
height: 15rem;
background: green;
border: black 1px solid;
margin: 0 auto;
position: relative;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
span {
color: white;
font-size: 150%;
}
#left-curtain, #right-curtain {
position: absolute;
top: 0;
bottom: 0;
width: 10rem;
-webkit-transition: all 1s ease;
transition: all 1s ease;
display: flex;
align-items: center;
justify-content: center;
}
#left-curtain {
background: red;
left: 0;
}
#right-curtain {
background: blue;
right: 0;
}
#stage:hover #left-curtain {
left: -10rem;
}
#stage:hover #right-curtain {
right: -10rem;
}
<div id="stage">
<span>PEEK - A - BOO!</span>
<div id="left-curtain">Mouse</div>
<div id="right-curtain">Over</div>
</div>
Here is my quick and dirty solution. It's not perfect and perhaps someone else can fine tune it - but it works. Javascript/jQuery might allow you to come up with a more complete solution.
Hope this helps.
.l,
.r {
-webkit-transition: width .35s ease-in-out;
transition: width .35s ease-in-out;
width: 200px;
height: 100px;
}
.container {
width: 400px;
}
.l {
background-color: red;
float: left;
}
.r {
background-color: brown;
float: right;
}
.container:hover div {
width: 150px;
}
<div class='container'>
<div class='l'>
</div>
<div class='r'>
</div>
</div>

Centrally divided layout with animation (ONLY CSS)

IMPORTANT NOTE: only CSS/HTML, but not javascript (client does not allow it)
recently started the homepage of my site and wanted to make a centrally divided layout. Want to place the logo on the middle and one picture on top of it with a button to lead to the page, and one below it with the same function.
The animation should be a hover over the buttons (or defined area around it) as seen in the comp I did here:
GIF ANIMATION OF WHAT IS INTENDED
Similar to what is intended: https://jsfiddle.net/vja85zgL/
* {
margin: 0px;
padding: 0px;
}
#wrapper {
width: 80%;
height: 200px;
margin: auto;
}
#wrapper:hover #left:not(:hover) {
width: 25%;
transition: width 1s linear;
}
#wrapper:hover #right:not(:hover) {
width: 25%;
transition: width 1s linear;
}
#left {
width: 50%;
height: 100%;
background-color: lightblue;
display: inline-block;
position: relative;
transition: width 1s linear;
}
#innerleft {
position: absolute;
top: 100px;
width: calc(100% - 4px);
text-align: center;
border: 2px solid black;
}
#right {
width: 50%;
height: 100%;
background-color: lightgrey;
display: inline-block;
position: relative;
transition: width 1s linear;
}
#innerright {
position: absolute;
top: 100px;
width: calc(100% - 4px);
text-align: center;
border: 2px solid black;
}
#right:hover {
width: 75%;
transition: width 1s linear;
}
#left:hover {
width: 75%;
transition: width 1s linear;
}
<div id="wrapper">
<div id="left">
<div id="innerleft">
TITLE 1
</div>
</div><div id="right">
<div id="innerright">
TITLE 2
</div>
</div>
</div>
As seen, if hovering over the button, the background image behind the button shows itself "fully" (no rescaling), the logo (showed as B) moves down to 25% and the button not hovered scales down in size and font size and the image behind it slides under it where the user cannot see it properly (the user cannot see it by scrolling down).
If hovered on the other button the animation goes to the other button and image background.
There should be a delay of 2 seconds before the layout comes back to the starting position
DETAILS:
NO JAVASCRIPT ALLOWED, client doesn't allow usage
Should be responsive, so no hovering on touch devices
The image must not resize or loose proportion
Full screen layout
Mouse simulates user.
Animation should return to initial position after 3 seconds if mouse is not hovering
Initial position is 50%-50% (almost, due to the logo which is 150x150px)
End position should be 75%-25%.
Have been loosing my mind the last 2 days wondering how to do it as I am a beginner at CSS but didn't find a way yet.
Any help would be appreciated!
Available code of what has been done already to the design (total mess...):
#business-top {
height:50%
width:100%
}
#business-button {
height:3em;
width:12em;
background-color:#2B2A2A;
border: .2em solid #ff7600;
border-radius:1.8em;
margin:auto;
margin-top:3em;
}
#logo-separator {
text-align:center;
}
.separator {
display: block;
position: relative;
padding: 0;
height: 0;
width: 100%;
max-height: 0;
font-size: 1px;
line-height: 0;
clear: both;
border: none;
border-top: 1px solid #ff7600;
border-bottom: 1px solid #ff7600;
}
#logo {
margin:auto;
max-width:150px;
display:inline-block;
overflow:hidden
margin-top:-75px
}
#photography-bottom {
height:50%
width:100%
}
#photography-button {
height:3em;
width:12em;
background-color:#2B2A2A;
border: .2em solid #ff7600;
border-radius:1.8em;
margin:auto;
margin-top:3em;
}
h1 {
color:#ff7600;
text-align:center;
font-size:1.4em;
vertical-align:middle;
line-height:2.2em
}
<div id="business-top"
<a href="www.lluisballbe.smugmug.com">
<div id="business-button">
<h1>BUSINESS</h1>
</div>
</a>
</div>
<div id="logo-separator">
<div class="separator"></div>
<div id="logo"><img src="https://lluisballbe.smugmug.com/Assets-for-website/i-CsMnM3R/0/Th/800x800-round-Th.png"</div>
</div>
<div id="photography-bottom"
<a href="www.lluisballbe.smugmug.com">
<div id="photography-button">
<h1>PHOTOGRAPHY</h1>
</div>
</a>
</div>
If you increase area of buttons once hovered , then you may have some results in CSS only:
trick comes from pointer-events and pseudo to increase hoverable area
/* tricky part */
div {
width: 100%;
pointer-events: none;
overflow: hidden;
transition: 1.5s;
}
div:hover {/* will be catch by child with pointer-events auto */
flex: 3;
}
div:first-child {
background: turquoise;
}
div a {
pointer-events: auto;/* if a is hovered, so is its parent */
position: relative;/* this could be for the div parent if you want to cover its area */
padding: 5px;
border-radius: 0.25em;
border: 3px solid;
box-shadow: 2px 2px 5px;
color: #222;
background: #aaa;
}
div a:hover:before {/* increase size of button only once hovered */
content: '';
position: absolute;
top: -200px;/* coordonates used to increase pseudo size from its relative position parent. tune to your needs */
bottom: -200px;
width: 100%;
}
/* layout */
body,
div {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
div {
flex: 1;
}
hr {
width: 100%;
height: 5px;
background: red;
text-align: center;
}
hr:before {
content: url(http://dummyimage.com/50x50);
display: inline-block;
height: 50px;
border-radius: 50%;
overflow: hidden;
margin-top: -25px;
}
html,
body {
height: 100%;
width: 100%;
margin: 0;
}
<div>
button style
</div>
<hr/>
<div>
button style
</div>
From your update snippet :
html,
body {
height: 100%;
width: 100%;
margin: 0;
}
body {
display: flex;
flex-direction: column;
}
h1 {
margin: 0;
}
a {
display: inline-block;
}
#business-top {
display: flex;
flex: 1;
width: 100%;
align-items: center;
justify-content: center;
text-align: center;
}
#business-button {
height: 3em;
width: 12em;
background-color: #2B2A2A;
border: .2em solid #ff7600;
border-radius: 1.8em;
margin: auto;
}
#logo-separator {
text-align: center;
}
.separator {
display: block;
position: relative;
padding: 0;
height: 0;
width: 100%;
max-height: 0;
font-size: 1px;
line-height: 0;
flex: 0;
border-top: 1px solid #ff7600;
border-bottom: 1px solid #ff7600;
}
#logo {
margin: auto;
max-width: 150px;
display: inline-block;
overflow: hidden;
margin: -75px;
position: absolute;
}
#photography-bottom {
display: flex;
flex: 1;
width: 100%;
align-items: center;
justify-content: center;
}
#photography-button {
height: 3em;
width: 12em;
background-color: #2B2A2A;
border: .2em solid #ff7600;
border-radius: 1.8em;
margin: auto;
}
h1 {
color: #ff7600;
text-align: center;
font-size: 1.4em;
vertical-align: middle;
line-height: 2.2em
}
#business-top,
#photography-bottom {
pointer-events: none;
position: relative;
z-index: 1;
transition: 1s;
/* min-height: 200px; you ma want this to avoid logo and button to overlap */
}
#business-top a,
#photography-bottom a {
pointer-events: auto;
}
#business-top:hover,
#photography-bottom:hover {
flex: 3;
}
#business-top a:hover:before,
#photography-bottom a:hover:before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div id="business-top">
<a href="www.lluisballbe.smugmug.com">
<div id="business-button">
<h1>BUSINESS</h1>
</div>
</a>
</div>
<div id="logo-separator">
<div class="separator"></div>
<div id="logo"><img src="https://lluisballbe.smugmug.com/Assets-for-website/i-CsMnM3R/0/Th/800x800-round-Th.png"> </div>
</div>
<div id="photography-bottom">
<a href="www.lluisballbe.smugmug.com">
<div id="photography-button">
<h1>PHOTOGRAPHY</h1>
</div>
</a>
</div>
http://codepen.io/anon/pen/qbvgga