How to center align text horizontally and VERTICALLY in a box/container? - html

I am trying to create a web page that looks like this:
Download page
I worked with bootstrap and created rows to align three download options next to each other. I then created containers in these rows (to replicate the boxes) and center aligned the text and download icon horizontally. Unfortunately, I am not sure how to center align the text and icon vertically in a container. Can anyone help out? My current design looks like this:
My code is the following:
.download {
font: Verdana, Helvetica, Arial, sans-serif;
color: RGB(112, 112, 112);
font-size: 18px;
text-align: center;
padding: 5px;
}
.download:hover {
color: rgb(227, 111, 30);
cursor: pointer;
}
#download-icon {
font-size: 80px;
float: left;
}
.container-border {
border-style: solid;
border-color: rgb(0, 143, 197);
padding: 5px;
min-height: 120px;
}
<div class="container">
<div class="row">
<div class="col-xs-4">
<div class="container-border">
<i class="material-icons" style="color:rgb(0,143,197);" id="download-icon">file_download</i>
<p class="download"> Download list of charities that have <b> not submitted </b> data yet </p>
</div>
</div>
</div>
</div>
Edit: Thanks everyone for their answers! I really appreciate them. For me it worked by simply adjusting my content-border class with:
.container-border {
border-style: solid;
border-color: rgb(0, 143, 197);
padding: 5px;
min-height: 120px;
display: flex;
align-items: center;
/* vertical center */
}

You don't need to complicate stuff using FlexBox. Please use something like this, a table layout or line-height and vertical-align combination:
.download {
font: Verdana, Helvetica, Arial, sans-serif;
color: RGB(112, 112, 112);
font-size: 18px;
text-align: center;
padding: 5px;
}
.download:hover {
color: rgb(227, 111, 30);
cursor: pointer;
}
#download-icon {
font-size: 80px;
vertical-align: middle;
line-height: 120px;
}
#download-icon + span {
vertical-align: middle;
line-height: 1;
}
.container-border {
border-style: solid;
border-color: rgb(0, 143, 197);
padding: 5px;
min-height: 120px;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="container">
<div class="row">
<div class="col-xs-4">
<div class="container-border">
<i class="material-icons" style="color:rgb(0,143,197);" id="download-icon">file_download</i>
<span class="download"> Download list of charities that have <b> not submitted </b> data yet </span>
</div>
</div>
</div>
</div>
Preview

I would use a flexbox for the container-border class. In that case you can remove the floats.
.download {
font: Verdana, Helvetica, Arial, sans-serif;
color: RGB(112, 112, 112);
font-size: 18px;
padding: 5px;
text-align: center;
}
.download:hover {
color: rgb(227, 111, 30);
cursor: pointer;
}
#download-icon {
font-size: 80px;
}
.container-border {
border-style: solid;
border-color: rgb(0, 143, 197);
padding: 5px;
min-height: 120px;
display: flex;
align-items: center;
/* vertical center */
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="container">
<div class="row">
<div class="col-xs-4">
<div class="container-border">
<i class="material-icons" style="color:rgb(0,143,197);" id="download-icon">file_download</i>
<p class="download"> Download list of charities that have <b> not submitted </b> data yet </p>
</div>
</div>
</div>
</div>

add display: flex;align-items: center; to .container-border
.container-border{
border-style:solid;
border-color: rgb(0,143,197);
padding: 5px;
min-height:120px;
display: flex;
align-items: center;
}

Why not just set a padding:
.download {
font: Verdana,Helvetica,Arial,sans-serif;
color: RGB(112,112,112);
font-size:18px;
text-align:center;
/* padding: 5px; <- removed */
padding: 12px 5px 5px 5px; /* New */
}
#download-icon {
font-size:80px;
float:left;
padding-top: 10px; /* New */
}
.container-border {
border-style:solid;
border-color: rgb(0,143,197);
padding: 5px;
min-height:120px;
width: 300px; /* New*/
}
Demo:
.download {
font: Verdana,Helvetica,Arial,sans-serif;
color: RGB(112,112,112);
font-size:18px;
text-align:center;
/* padding: 5px; <- removed */
padding: 12px 5px 5px 5px; /* New */
}
.download:hover {
color: rgb(227,111,30);
cursor: pointer;
}
#download-icon {
font-size:80px;
float:left;
padding-top: 10px; /* New */
}
.container-border {
border-style:solid;
border-color: rgb(0,143,197);
padding: 5px;
min-height:120px;
width: 300px; /* New*/
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="container">
<div class="row">
<div class="col-xs-4">
<div class="container-border">
<i class="material-icons" style="color:rgb(0,143,197);" id="download-icon">file_download</i>
<p class="download"> Download list of charities that have <b> not submitted </b> data yet </p>
</div>
</div>
</div>
</div>

Related

Filling Extra Space in HTML/CSS

How do I fill that circled space? I want to know how to fill the rest of the blue area with white background-color.
I tried increasing the padding, but that moved the price lower and lower and to the left a little each time I increased the padding.
My HTML looks like this..
section {
background-color: white;
}
#repair-tagline h1 {
background-color: white;
font-family: 'Open Sans Condensed', sans-serif;
letter-spacing: 0.2rem;
font-size: 3rem;
text-align: center;
padding: 40px 0 40px 0;
}
.repair-option {
background-color: rgb(0, 0, 77);
width: 80%;
padding: 50px 50px 50px 50px;
margin: 0px auto 50px auto;
}
.repair-type,
.repair-price {
display: inline-block;
color: white;
}
.repair-type {
font-size: 2rem;
}
.repair-price {
float: right;
background-color: white;
border: 1px solid black;
color: black;
font-size: 2rem;
}
<section>
<div class="repair">
<div id="repair-tagline">
<h1>Choose Your Vacuum Cleaner Repair Option:</h1>
</div>
<div class="repair-option">
<div class="repair-type">
<h1>Belt Repair</h1>
</div>
<div class="repair-price">
<h1>$10.00</h1>
</div>
</div>
<div class="repair-option">
<div class="repair-type">
<h1>Brush-Roll Repair</h1>
</div>
<div class="repair-price">
<h1>$20.00</h1>
</div>
</div>
</div>
</section>
Remove the padding from the class of repair-option and add individual paddings to the 2 child divs (repair-type and repair-price). That way, each of those had individual paddings which means the background-color corresponds to the div.
The padding for .repair-price may look weird, but I just did that because it wasn't lining up. You can change all the paddings to how you wish.
section {
background-color: white;
}
#repair-tagline h1 {
background-color: white;
font-family: 'Open Sans Condensed', sans-serif;
letter-spacing: 0.2rem;
font-size: 3rem;
text-align: center;
padding: 40px 0 40px 0;
}
.repair-option {
background-color: rgb(0, 0, 77);
width: 80%;
padding: 0px;
margin: 0px auto 50px auto;
}
.repair-type,
.repair-price {
display: inline-block;
color: white;
}
.repair-type {
font-size: 2rem;
padding: 10px;
}
.repair-price {
float: right;
background-color: white;
border: 1px solid black;
color: black;
font-size: 2rem;
padding: 10px 0px 8px 0px;
}
<section>
<div class="repair">
<div id="repair-tagline">
<h1>Choose Your Vacuum Cleaner Repair Option:</h1>
</div>
<div class="repair-option">
<div class="repair-type">
<h1>Belt Repair</h1>
</div>
<div class="repair-price">
<h1>$10.00</h1>
</div>
</div>
<div class="repair-option">
<div class="repair-type">
<h1>Brush-Roll Repair</h1>
</div>
<div class="repair-price">
<h1>$20.00</h1>
</div>
</div>
</div>
</section>

Positioning 2 elements (countdown timer and button) in row, side by side - they are not centered

I have a problem with one of sections in my HTML code.
My idea is simply: one section made by 1 row, who is divided on 2 columns.
In left column i tried to put countodwn timer, and "submit" button in right column. They have to be side by side, and on equal distance in regards to each other; but there are some problems - they are on unequal distance and i am wondering how to fix it...
Also, when i test how draft of my site looks on mobile, parts of the clock do not stay together - they just move under each other.
Here is a jsfiddle.
What i am doing wrong?
<div class="container-fluid">
<div class="row align-items-center"><div class="col-6 mx-auto">
<h3 style=" font-family: Open Sans; font-weight: light; font-size: 20px; color: 636363;letter-spacing: 1px; padding-left:110px;">Deadline:</h3>
<div id="clockdiv">
<div> <span class="days"></span>
<div class="smalltext">Days</div>
</div>
<div> <span class="hours"></span>
<div class="smalltext">Hours</div>
</div>
<div> <span class="minutes"></span>
<div class="smalltext">Minutes</div>
</div>
<div> <span class="seconds"></span>
<div class="smalltext">Seconds</div>
</div>
</div>
</div>
<div class="col-6 mx-auto">
<button class="button button1" style="width: 300px; height: 100px;">Submit</button>
</div>
</div>
</div>
And CSS:
#clockdiv{
font-family: Open Sans;
color: #ffffff;
display: inline-block;
font-weight: 100;
text-align: center;
font-size: 30px;
}
#clockdiv > div{
padding: 0px;
border-radius: 3px;
background: #fffff;
display: inline-block;
}
#clockdiv div > span{
padding: 15px;
border-radius: 3px;
background: #000;
display: inline-block;
position: relative;
}
.smalltext{
padding-top: 5px;
font-size: 16px;
color: #000;
position: relative;
}
.button {
background-color: #fff;
border: none;
color: white;
text-align: center;
text-decoration: none;
font-size: 16px;
font-family: 'Open Sans';
margin: 4px 2px;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
cursor: pointer;
}
.button1 {
background-color: white;
color: #000;
border: 2px solid #000;
}
.button1:hover {
background-color: #fff;
color: white;

Put two divs one near the other

I have the following html code:
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
and the css/less:
.rtm {
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
position: absolute;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
}
I tried to do like this in order to show the page-icon and page-title one near the other but how it is done now they are one over the other (the icon is on top of the title)
How can I solve this? Thanks
When you say "near each other" I am assuming you mean "beside each other".
You can add flexbox properties to #crumby-title. Then remove position and float properties from .page-icon and page-title. You can also remove height from .page-title
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart {
padding-top: 50px;
}
#crumby-title {
display: flex;
align-items: center;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
font-size: 20px;
font-weight: 5px 10px 10px 75px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
Give float:left to .page-icon instead of position:absolute and add <div class="clear"></div> after page-title.
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
float: left;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
.clear{
clear:both;
}
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
<div class="clear"></div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
I want to show u another version of ankita pantel's put them in a table and add padding-top to Demand
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
padding-top: 30px;
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
<div class="demand page">
<div id="crumby-title">
<table>
<tr>
<td>
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
</td>
<td>
<div class="page-title">
Demand
</div>
</td>
</tr>
</table>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
All the cool kids are using flex box.
display:flex; flex-direction:row; makes the child items stack in a row. (flex-direction:row is default so you can skip that)
#crumby-title {
...
display: flex;
flex-direction:row;
}
then you can (if you want) center the text with
.page-title {
....
display: flex;
align-items: center;
}
Fiddle

trying to center the signup form in the middle of the footer

I am trying to get the signup form in the footer to be exactly centered in the middle of the footer; in between the left and right side of the footer. It is too far to the left side if I try using the push, pull or offset classes. It just seems to go a little too far in one direction. I'm using html5, css3 and bootstrap 3. Above, I have attached an image of what I would like it to look like.
<footer class="footer-distributed">
<div class="footer-left">
<h3>Menu</h3>
<p class="footer-links">
text •
text •
text •
text •
text
</p>
<p class="footer-company-name"> hellohello<span> © 2016</span></p>
<div class="footer-social">
<!-- Social Media -->
<ul class="social">
<li>
<a href="http://wwww.fb.com/hellohello" class="Facebook">
<i class="ion-social-facebook"></i>
</a>
</li>
<li>
<a href="http://wwww.twitter.com/ hellohello " class="Twitter">
<i class="ion-social-twitter"></i>
</a>
</li>
<li>
<a href="#" class="Linkedin">
<i class="ion-social-linkedin"></i>
</a>
</li>
<li>
<a href="http://wwww.fb.com/ hellohello " class="Google Plus">
<i class="ion-social-googleplus"></i>
</a>
</li>
</ul>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-12 col-sm-push-center ">
<div class=" subscribe-foot section-wrapper">
<p class="subscribe-nowfoot">
Sign up for our newsletter to stay hellohello informed
<br>about new products, updates and discounts
</p>
<div class="col-md-8 col-sm-8 col-xs-12 col-sm-push-2">
<div class="input-group">
<input type="email" class="form-control border-radius" placeholder="Email address">
<span class="input-group-btn">
<button class="btn btn-form border-radius custom-sub-btn" type="button">Sign up</button>
</span>
</div>
<!-- /input-group -->
</div>
</div>
</div>
<div class="footer-right">
<p>Contact Us</p>
<form action="#" method="post">
<input type="text" name="email" placeholder="Email" />
<textarea name="message" placeholder="Message"></textarea>
<button>Send</button>
</form>
</div>
</footer>
CSS:
#footer {
background-color: #292c2f;
}
.footer-distributed {
background-color: #292c2f;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
box-sizing: border-box;
width: 100%;
font: bold 16px sans-serif;
text-align: left;
padding: 50px 60px 40px;
margin-top: 0px;
overflow: hidden;
}
/* Footer left */
.footer-distributed .footer-left {
float: left;
}
/* The company logo */
.footer-distributed h3 {
color: #bebebe;
font: normal 36px 'roboto', sans-serif;
margin: 0 0 10px;
}
/* Footer links */
.footer-distributed .footer-links {
color: #00bfff;
font-weight: 400;
margin: 0 0 10px;
padding: 0;
}
.footer-distributed .footer-links a {
display: inline-block;
line-height: 1.8;
text-decoration: none;
color: inherit;
}
.footer-distributed .footer-company-name {
color: #00bfff;
font-size: 14px;
font-weight: normal;
margin: 0;
}
.footer-distributed .footer-company-name span {
color: #d1d1d1;
font-size: 14px;
font-weight: normal;
margin: 0;
}
.footer-distributed .footer-company-name a {
color: #00bfff;
}
.footer-distributed .subscribe-nowfoot {
color: #eaeaea;
font-size: 16px;
line-height: 20px;
text-align: center;
margin-bottom: 20px;
font-weight: 300;
margin-left: 0px;
margin-right: 0px;
padding-right: 0px;
padding-left: 0px;
}
.footer-distributed .btn-form:hover,
.footer-distributed .btn-form:active {
border: 1px solid #00bfff;
background-color: #fff;
color: #00bfff;
}
.footer-distributed .custom-sub-btn {
background-color: #00bfff;
color: #fff;
border-color: #00bfff;
transition: all .4s ease-in-out;
letter-spacing: 1px;
margin-top: 1px;
}
.footer-distributed .custom-sub-btn:hover {
color: #00bfff;
background: #fff;
border-color: #00bfff;
font-weight: 500;
letter-spacing: 1px;
}
.subscribe-foot {
text-align: center;
margin-top: 0px;
padding-top: 0px;
}
/* Footer Right */
.footer-distributed .footer-right {
float: right;
}
.footer-distributed .footer-right p {
text-align: center;
vertical-align: top;
margin: 0px 0px 20px 0;
color: #ffffff;
color: #bebebe;
font: normal 36px 'roboto', sans-serif;
}
/* The contact form */
.footer-distributed form {
display: inline-block;
}
.footer-distributed form input,
.footer-distributed form textarea {
display: block;
border-radius: 3px;
box-sizing: border-box;
background-color: #fafafa;
box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.1);
border: none;
resize: none;
font: inherit;
font-size: 14px;
font-weight: normal;
color: #969696;
width: 280px;
padding: 18px;
}
.footer-distributed::-webkit-input-placeholder {
color: #5c666b;
}
.footer-distributed::-moz-placeholder {
color: #00aaff;
opacity: 1;
}
.footer-distributed:-ms-input-placeholder {
color: #00aaff;
}
.footer-distributed form input {
height: 20px;
margin-bottom: 15px;
}
.footer-distributed form textarea {
height: 75px;
margin-bottom: 20px;
}
.footer-distributed form button {
border-radius: 3px;
background-color: #00bbff;
color: #ffffff;
border: 0;
padding: 8px 50px;
font-weight: 500;
float: right;
letter-spacing: 1px;
}
.footer-distributed form button:hover {
border-radius: 3px;
background-color: #ffffff;
color: #00bbff;
border: 2px solid #00bfff;
padding: 8px 50px;
font-weight: 500;
float: right;
letter-spacing: 1px;
}
It's a bit weird because in the same div you're using both your own positioning (through .footer-left and .footer-right) and the grid system of bootstrap (for the sign up div). It's better (in my opinion) to stick with one of the two.
First option, Bootstrap:
To do it using bootstrap, you need:
To remove the float from your css
To add the proper class for left/right:
So the css remains mostly unchanged (just remove the float left and right) and the html has some changes. Which can be summed up as :
<div class="footer-left col-sm-3 col-xs-12">
<!-- Menu -->
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<!-- Sign up -->
</div>
<div class="footer-right col-sm-3 col-xs-12">
<!-- Contact -->
</div>
Fiddle: https://jsfiddle.net/_Py_/3uybymtk/
Second option, no Bootstrap:
Without bootstrap, I'd recommend using flex (see https://css-tricks.com/snippets/css/a-guide-to-flexbox/ or https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes for more info)
To use it properly in our case, it's quite simple:
Remove the float left/right
Remove the bootstrap code for the sign up div
Add the proper css to make it flex.
So the html is :
<div class="footer-left>
<!-- Menu -->
</div>
<div>
<!-- Sign up -->
</div>
<div class="footer-right">
<!-- Contact -->
</div>
And the css is modified as such :
.footer-distributed {
background-color: #292c2f;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
box-sizing: border-box;
width: 100%;
font: bold 16px sans-serif;
text-align: left;
padding: 50px 60px 40px;
margin-top: 0px;
overflow: hidden;
display : flex;
justify-content : space-between;
}
.footer-distributed > div {
flex: 0 0 auto;
}
.footer-distributed .footer-left {
}
.footer-distributed .footer-right{
}
I put the footer-left and footer-right to show that they now have nothing.
This works by:
Setting the .footer-distributed in a flex display (display:flex)
Changing the way elements are displayed in this flex container (justify-content : space-between will make the first element to be at the start of the line, the last at the end of the line, and the rest spaced equally in between. i.e, our signup div will be centered!).
Telling the div that are a direct child of .footer-distributed that they won't grow/shrink and that their base size is determined by their height/width (flex: 0 0 auto;)
Fiddle: https://jsfiddle.net/_Py_/segk8mxt/

how can I align the button and the text inline

I want to align the button and the text in the same line.
<div class="oferts">
<div class="container" style="line-height: 300px; text-align: center;">
<h1>Bucura-te de ofertele noastre alaturi de familia ta <button class="oferts-button">Vezi toate beneficiile terapiilor</button>
</div>
</div>
button {
background: transparent;
color: #666;
border: 1px solid #d4d4d4;
padding: 10px 20px;
margin: 0 10px 0 10px;
transition: border .3s ease-in;
}
button:hover {
border: 1px solid #909090;
padding: 10px 20px 10px 20px;
}
button a {
font-family: 'Raleway', sans-serif;
color: #666;
font-size: 14px;
}
.oferts-button a {
font-family: 'Raleway', sans-serif;
color: #fff;
}
.oferts-button:hover {
border: 1px solid #fff;
}
.oferts {
width: 100%;
display: table;
height: 300px;
background:url(../img/back.jpg) center no-repeat;
}
You can use the vertical-align css property on both elements:
container {
line-height: 300px;
text-align: center;
}
container > h1,
container > h1 a {
vertical-align: middle;
}
DEMO
HTML Removed h1 tags, as was not ending and didn't even found in css
NOTE: Used font-size - 32px because h1 tag = 32px
<div class="oferts">
<div class="container">
Bucura-te de ofertele noastre alaturi de familia ta
<button class="oferts-button">
Vezi toate beneficiile terapiilor
</button>
</div>
</div>
CSS Add this class to your CSS
.container
{
line-height: 300px;
text-align: center;
font-weight:bold;
font-size:32px;
}