Center form content vertically - html

I've got the following landing page form (I've cut all the unnecessary stuff I don't think matters leaving only minimum of style). Here is the code (I'm using Bootstrap 3.3.5):
<div class="col-md-6 app-door">
<form class="image-hover text-center">
<h3>Application name</h3>
<div class="landing-page-form-group">
<label class="landing-page-label">Label: </label>
<input class="form-control landing-page-input">
</div>
<button class="btn">Submit</button>
</form>
<div class="center-block app-link some-img"/>
</div>
..and css
.image-hover {
width: 300px;
height: 300px;
background-color: rgba(0, 0, 0, 0.7) !important;
position: absolute;
z-index: 100;
color: #cccccc;
margin: 0 auto;
left: 0;
right: 0;
border-radius: 25px;
}
.landing-page-form-group {
padding-top: 16px;
padding-bottom: 16px;
}
.landing-page-label {
width: 100px;
vertical-align: middle;
}
.landing-page-input {
width: 150px;
display: inline-block;
}
.app-link {
width: 300px;
height: 300px;
background-size: 100% 100%;
border-radius: 25px;
}
.some-img {
background-image: url("http://dl.hiapphere.com/data/icon/201511/HiAppHere_com_com.ludicside.mrsquare.png");
}
I want to center all the form inputs and etc vertically. I've tried such things as playing with position (relative on parent, absolute on child), vertical-align, top, maybe something else I don't remember right now as I spent lots of hours trying.
I'm not a great specialist in frontend development (I mean html/css) so I will be extremely happy to see understanding although the problem seems to be basic enough.
Thank you for any ideas!

updated
check the solution without flex demo here
Try this
check demo here
add the following styles to your existing .image-hover class
CSS:
.image-hover {
align-items: center;
display: flex;
flex-direction: column;
justify-content: center;
}

Simplest method would be to use
.image-hover {
display: flex;
align-items : center;
justify-content: center;
}
The align-items takes care of vertical centering, and justify-contents, the horizontal centering.

This is my solution:
https://jsfiddle.net/0x9epxah/1/
add div .inner-form:
<div class="col-md-6 app-door">
<form class="image-hover text-center">
<div class="inner-form">
<h3>Application name</h3>
<div class="landing-page-form-group">
<label class="landing-page-label">Label: </label>
<input class="form-control landing-page-input">
</div>
<button class="btn">Submit</button>
</div>
</form>
<div class="center-block app-link some-img"/>
</div>
and this css class:
.inner-form {
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%,-50%);
}

Related

Align the bottom of images on different columns(Bootstrap)

On my website I have 3 bootstrap columns and each has a photo at the end. The problem is that the titles have different lengths and because of that when I resize the browser (at 1100px width) one of the pictures and the paragraph above it shift a little bit lower then the other 2. Is it possible to align the photos and pragraphs at the bottom and the title at the top?
Here is a JsFiddle of the problem I have
I don't now why but in JsFiddle the columns are all in one column and not multiple (like on a mobile device) but maybe if you save it and then open it in your browser you can see the problem.
HTML:
<div class="container-fluid">
<div class="row ">
<div class="col-md-4 column">
<center>
<h1>Babababababababababababababa</h1>
<p>2013 - Now</p>
<div>
<div class="container-images"> <img class="image" src="https://iso.500px.com/wp-content/uploads/2016/05/stock-photo-93725859-1500x1000.jpg">
<div class="over">
<p class="title">aaa</p>
<p class="rayal">aaaaaa</p>
</div>
</div>
</div>
</center>
</div>
<div class="col-md-4 column">
<center>
<h1>Bababababababababababababababababa</h1>
<p>2009 - 2013</p>
<div class="container-images"> <img class="image" src="https://iso.500px.com/wp-content/uploads/2016/05/stock-photo-93725859-1500x1000.jpg">
<div class="over">
<p class="title">aaa</p>
<p class="rayal">aaaaa</p>
</div>
</center>
</div>
<div class="col-md-4 column">
<center>
<h1>Babababababababababababababab</h1>
<p>2007 - 2009</p>
<div class="container-images"> <img class="image" src="https://iso.500px.com/wp-content/uploads/2016/05/stock-photo-93725859-1500x1000.jpg">
<div class="over">
<p class="title">aaa</p>
<p class="rayal">aaaaa</p>
</div>
</center>
</div>
</div>
</div>
CSS:
.container-images {
height: 300px;
width: 75%;
overflow: hidden;
display: flex;
/* align-items: center;*/
justify-content: center;
position: relative;
border-radius: 100px;
}
.image {
width: 100%;
height: 100%;
position: relative;
z-index: 1;
background-size: cover;
border-radius: 100px;
display: block;
float: left;
box-sizing: border-box;
-moz-box-sizing: border-box;
margin-bottom: 50px;
}
.over {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
z-index: 2;
background: rgba(0, 0, 0, 0.2);
transition: all 0.3s ease-in-out;
border-radius: 100px;
}
.title {
margin-top: 100px;
color: white;
transition: all 0.5s ease-in-out;
font-family: RobotoSlab-Regular;
opacity: 0;
}
.rayal {
opacity: 0;
color: white;
transition: all 0.5s ease-in-out;
font-family: RobotoSlab-Regular;
}
.over:hover {
background: rgba(0, 0, 0, 0.5);
}
.over:hover .title {
margin-top: 0;
opacity: 1;
}
.over:hover .rayal {
opacity: 1;
}
This is a good example for flexbox.
Here's an updated example of your plunker:
https://jsfiddle.net/eqcyyae9/9/
A few notes on this:
I removed your <center> tags. These are depreciated, and it's not a good practice to use them (as described here). The same effect can be achieved using the Bootstrap center-block CSS class.
I removed the flexbox properties on your container-images class. The centering you were doing in that case is handled by center-block, and as a personal preference I only use Flexbox when necessary so my CSS degrades as gracefully as possible for older browsers.
I added a container-content class which does have flexbox on it. Using the space-between attribute with the flex-direction: column allows your content to take up the designated space (570px in this example). Your header will always stick to the top, and your image will stick to the bottom and any extra space will end up in-between (thus, space-between). There's a really good article on this here if you have more interest in looking into it.
As a side note, plunker asks that you add all file dependencies to the "External Resources" section rather then directly to the HTML. That's why you weren't seeing your Bootstrap styles come through.

Box (div) is placed lower than the first?

I'm trying to make different boxes that are placed in the same line using CSS.
However, without any style rule (at least that I've noticed) making it do so, the second box is lower than the first. Why is that? How can I fix it?
If you have any question, feel free to ask, I'll do my best to answer.
Thank you in advance.
Code snippet below.
JSFiddle
.index-links {
width: 90%;
position: relative;
left: 5%;
padding: 1%;
}
.index-link {
display: table-cell;
height: 150px;
width: 150px;
border: 2px solid black;
margin: 1%;
padding: 0.5%;
text-align: center;
vertical-align: middle;
position: relative;
cursor: pointer;
float: left;
}
.index-link > .index-link-perms::before {
content: " | "
}
<div class="index-links">
<br>
<div class="index-link" data-color="black" data-x-index="1" data-y-index="1">Link 1<span class="index-link-perms">Access: Everyone</span>
</div>
<br>
<div class="index-link" data-color="pink" data-x-index="2" data-y-index="1">Link 2<span class="index-link-perms">Access: SM</span>
</div>
</div>
Remove the br tag between the divs.
<div class="index-links">
<br>
<div class="index-link" data-color="black" data-x-index="1" data-y-index="1">Link 1<span class="index-link-perms">Access: Everyone</span>
</div>
<div class="index-link" data-color="pink" data-x-index="2" data-y-index="1">Link 2<span class="index-link-perms">Access: SM</span>
</div>
</div>
change the CSS as below
.index-links {
display:flex;
width: 90%;
position: relative;
left: 5%;
padding: 1%;
}

Make button in absolute centered and middle of page

I'm trying to make a single page with a large button that is always in the absolute middle/center of the page. I want the button-text to be large, but when I make it large it offsets the button and it is no longer in the middle. What am I doing wrong here?
(I also have bootstrap installed and am glad to use rows/columns/offsets too)
CSS
.btn-text {
vertical-align: middle;
font-family: 'Corben';
font-size: 580%;
}
.wrapper {
text-align: center;
}
.btn {
position: absolute;
top: 50%;
padding: 20%;
}
HTML
...
<body>
<div class="wrapper">
<div class="btn btn-large btn-primary" id="oujh-button">
<div class="btn-text">BUTTON</div>
</div>
</div>
</body>
...
JSFiddle: https://jsfiddle.net/50ye58oe/1/
If using CSS3 transforms is OK(if you don't need to support IE<9) you could do this:
.btn{
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
Another solution is to use the Bootstrap center-block class to horizontally center the button and a flexbox to vertically center it.
HTML
<div class="wrapper">
<div class="center-block btn btn-large btn-primary" id="oujh-button">
<div class="btn-text">BUTTON</div>
</div>
</div>
CSS
.btn-text {
font-family: 'Corben';
font-size: 280%;
}
.wrapper {
position: fixed;
width: 100%;
height: 100%;
display: flex;
align-items: center;
}

Responsive text fixed positioning with Button

http://i.imgur.com/Veauoig.png
I am currently trying to work out how to make the 'From £' text to keep in the same position as the buttons above. The page is responsive so I have been unable to keep the text in one position.
The CSS I have used so far -
element.style {position: absolute; width: 97%;}
I put each of the 'From £' parts in their own class. Not sure if there is an easier way?
<div class="price2">From £300</div>
Any help would be great. Thanks!
Add a container for the element for the price and button so that they remain in context with each other.
http://jsfiddle.net/05orkj1a/
.prices{
width: 100%;
}
.price-column{
display: table-cell;
width: 33%;
text-align: center;
margin: 0 auto;
padding: 0 5px;
}
<div class="prices">
<div class="price-column">
<button>Bass</button>
<div class="price2">From £65</div>
</div>
<div class="price-column">
<button>Mid</button>
<div class="price2">From £300</div>
</div>
<div class="price-column">
<button>Treble</button>
<div class="price2">From £715</div>
</div>
</div>
You could also Float the columns left to cause them to collapse vertically as the screen shrinks with the same html. Just change the margin or padding depending on how far apart you want them spaced
http://jsfiddle.net/z6agt11e/
.prices{
width: 100%;
overflow: hidden;
}
.price-column{
display: block;
float: left;
text-align: center;
padding: 5px 5px;
}
You can also add an outer container and then create a inner container for each button-price set.
Here is the HTML code:
<div class="outter">
<div class="block">
<div class="button">button1</div>
<div class="price2">From £65</div>
</div>
<div class="block">
<div class="button">button2</div>
<div class="price2">From £300</div>
</div>
<div class="block">
<div class="button">button3</div>
<div class="price2">From £715</div>
</div>
</div>
Here the CSS:
.outter{
width:100%;
}
.block{
width:33%;
background-color: yellow;
float:left;
text-align: center;
}
And here a jsfiddle:
http://jsfiddle.net/SoniaGM/ej4mdwx9/1/
Hope it helps.
You can use the CSS3 ::after pseudo-selector.
Give at button class:
position: relative;
Then you have to write something lime this:
.button-class::after {
content: 'From £300';
background: transparent;
height: 1%;
width: 3%;
position: absolute;
top: 20px;
left: 0px;
}
Obviously, you have to change height: 1%; width: 3%; and top: 20px; left: 0px;with whatever you want!

Centering a div in Skeleton

For a project of mine, I'm using Skeleton Boilerplate for the first time. And I'm looking for the best practice of centring a div in Skeleton without bashing into the rules of Skeleton.
At the moment, I've the following structure for a login page.
HTML:
<div class="container">
<div class="sixteen columns vertical-offset-by-one">
<div id="loginBox">
<img src="images/yeditepeLogo.png" alt="Yeditepe Logo" class="yeditepeLogo" />
<form action="" id="loginForm">
<input type="text" name="username" required placeholder="username" class="loginTextField">
<input type="password" name="password" required placeholder="password" class="loginTextField">
<input type="submit" value="Log In" class="loginButton" />
</form>
</div><!-- loginBox -->
</div><!-- sixteen columns -->
<div class="sixteen columns">
<p align="center">Click here to register</p>
</div>
</div><!-- container -->
CSS:
#loginBox, #registrationBox {
width: 470px;
height: 450px;
background-color: white;
left: 245px; */
top: 20px; */
position: relative;
margin: 0px auto; }
#registrationBox {
height: 500px; }
.yeditepeLogo {
position: relative;
left: 40px;
top: 33px; }
#loginForm, #registrationForm {
position: relative;
top: 45px; }
.loginTextField, .registrationTextField {
position: relative;
height: 40px;
width: 388px;
left: 40px;
border-color: #dedede;
border-style: solid;
border-width: 1px;
margin-bottom: 10px;
text-align: left;
font-size: 18px;
text-indent: 10px;
-webkit-appearance: none; }
.loginTextField:focus, .registrationTextField:focus {
outline-color: #ff9800;
outline-style: solid;
outline-width: 1px;
border-color: white; }
.loginTextField:nth-child(2), .registrationTextField:nth-child(3) {
margin-bottom: 40px; }
.loginButton, .registrationButton {
background-color: #77a942;
position: relative;
border: none;
width: 390px;
height: 60px;
left: 40px;
color: white;
font-size: 24px;
text-align: center;
opacity: 0.8; }
.loginButton:hover, .registrationButton:hover {
opacity: 1; }
As you can see, that #loginBox has a fixed width/height and it should always be on the centre of the page. margin: 0px auto code gives it the horizontal centring. But is it the best practice in Skeleton? Does Skeleton provide a better way?
Also how can I provide it's vertical centring?
There's actually a built in way of centering divs in Skeleton.
<div class="sixteen columns">
<div class="four columns offset-by-six">
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>
The offset-by-six in this case can be altered from one to fifteen, and offsets the column at hand by as many columns as entered. As a neat feature, the offsetting is not affecting alignment when smaller screens are used.
To clarify: This doesn't center the actual content in the div, but centers the div itself.
I know it has been a while since this question was asked, but maybe somebody else can use the answer.
I was able to accomplish centering with Skeleton by filling one-third column class with a space, then the next one-third column class with content, then another one-third column class with a space again.
<div class="one-third column"> </div>
<div class="one-third column"><p>Center of the screen.</p></div>
<div class="one-third column"> </div>
You can set the container to
.container {
position: absolute;
top: 50%;
left: 50%;
margin-left: -43 //replace with half of the width of the container
margin-top: -52 //replace with half of the height of the container
}
set the parent container or element to position: relative;
Here's a good article about How to Center Anything With CSS
Asus3000's answer is good as that is what I do and it works well. I would only add that on mobile, it adds quite a bit of unwanted vertical space. To avoid mobile vertical space, I use a class .filler and hide it on mobile.
HTML
<div class="one-third column filler"> </div>
<div class="one-third column"><p>Center of the screen.</p></div>
<div class="one-third column filler"> </div>
CSS
/* or whatever mobile viewport */
#media only screen and (max-width: 960px) {
.filler { display: none}
}
A way I believe works pretty good is:
<div class="container">
<div class="row">
<div class="two-half column">
centered div content
</div>
</div>
</div>
This makes the div centered and responsive. You can change margin-top to make it all the way in the middle, however changing width will (of course) not make it centered anymore.
Correct me if I'm wrong but this works for me! :)