Allign divs to middle of screen by their middle - html

Using bootstrap, I need to have a page with divs (4 initially) as buttons in the middle of the screen, as below image:
I succeeded to do this, but, next, I need to enlarge one of them when mouseover as below image:
so, they are aligned by their middle. and all others will be smaller when another on is hover.

Simply increase the width and height on :hover.
html, body,
.container {
height: 100%;
}
.container {
display: table;
vertical-align: middle;
}
.vertical-center-row {
display: table-cell;
vertical-align: middle;
}
.buttons-container {
vertical-align: bottom;
text-align: center;
}
.app-button:hover {
width: 75px;
height: 75px;
}
.app-button {
width: 50px;
height: 50px;
margin: 15px;
background-color: #cccccc;
display: inline-block;
vertical-align: middle;
transition: all 0.5s;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row vertical-center-row">
<div class="col-md-12 buttons-container">
<div class="app-button"></div>
<div class="app-button"></div>
<div class="app-button"></div>
<div class="app-button"></div>
</div>
</div>
</div>

You can try two methods one is to increase the height and width and the other is to use transform
With transform Fiddle
html, body, .container {
height: 100%;
}
.container {
display: table;
vertical-align: middle;
}
.vertical-center-row {
display: table-cell;
vertical-align: middle;
}
.buttons-container {
vertical-align: bottom;
text-align: center;
}
.app-button {
width: 50px;
height: 50px;
margin: 15px;
background-color: #cccccc;
display: inline-block;
}
.app-button:hover {
transform:scale(1.5,1.5);
margin: 15px;
background-color: #cccccc;
display: inline-block;
}
<div class="container">
<div class="row vertical-center-row">
<div class="col-md-12 buttons-container"> <a href="#">
<div class="app-button"></div>
</a>
<a href="#">
<div class="app-button"></div>
</a>
<a href="#">
<div class="app-button">
</div>
</a>
<a href="#">
<div class="app-button">
</div>
</a>
</div>
</div>
</div>
By changing height and width Fiddle
html, body, .container {
height: 100%;
}
.container {
display: table;
vertical-align: middle;
}
.vertical-center-row {
display: table-cell;
vertical-align: middle;
}
.app-button:hover {
height:100px;
width:100px;
}
.buttons-container {
vertical-align: bottom;
text-align: center;
}
.app-button {
width: 50px;
height: 50px;
margin: 15px;
background-color: #cccccc;
display: inline-block;
vertical-align:middle;
}
<div class="container">
<div class="row vertical-center-row">
<div class="col-md-12 buttons-container"> <a href="#">
<div class="app-button"></div>
</a>
<a href="#">
<div class="app-button"></div>
</a>
<a href="#">
<div class="app-button">
</div>
</a>
<a href="#">
<div class="app-button">
</div>
</a>
</div>
</div>
</div>

Related

CSS: the relative positioned element is now working when adding overflow-x

I want to make the images in day_time_block can cover the title class.
I also want to make all contents in day_time_block can be shown by overflow-x, but when adding overflow-x: auto; in scroll div, the images in day_time_block were covered by title div. like the following code. How to fix it?
HTML:
<html>
<body>
<div>
<div class="daily_content">
<div class="title">
<img src="https://www.google.com.hk/images/srpr/logo11w.png" class="img_title"/>
<div class="daily_title">Title</div>
</div>
<div class="scroll">
<div class="day_time_block">
<div class="day_time_text">Sunday</div>
<img src="https://www.google.com.hk/images/srpr/logo11w.png" class="daily_img"/>
</div>
<div class="day_time_block">
<div class="day_time_text">Monday</div>
<img src="https://www.google.com.hk/images/srpr/logo11w.png" class="daily_img"/>
</div>
<div class="day_time_block">
<div class="day_time_text">Tuesday</div>
<img src="https://www.google.com.hk/images/srpr/logo11w.png" class="daily_img"/>
</div>
<div class="day_time_block">
<div class="day_time_text">Wednesday</div>
<img src="https://www.google.com.hk/images/srpr/logo11w.png" class="daily_img"/>
</div>
<div class="day_time_block">
<div class="day_time_text">Thursday</div>
<img src="https://www.google.com.hk/images/srpr/logo11w.png" class="daily_img"/>
</div>
</div>
</div>
</div>
</body>
</html>
CSS:
<style>
body {
margin: 0px;
}
.title {
background: #ED3632;
height: 25px;
}
.img_title {
width: 30px;
height: 20px;
float: left;
margin-left: 15px;
margin-right: 5px;
}
.daily_title {
color: #f6ff52;
font-size: 1em;
}
.daily_content {
background: #000000;
height: 3000px;
}
.scroll {
color: #ffffff;
font-size: 1em;
width: 480px;
overflow-x: auto;
white-space: nowrap;
background-color: aqua;
border: 1px red solid;
display: flex;
}
.day_time_block {
float: left;
color: #ffffff;
font-size: 1em;
padding-left: 8px;
}
.day_time_text {
font-size: 1em;
display: inline-block;
}
.daily_img {
width: 30px;
height: 20px;
margin-left: 10px;
position: relative;
top: -10px;
}
</style>
overflow work with display:block...but if you want to use display:flex then create parent div for that and make this display:block and apply overflow on parent div.

Inline-block top align issue; blocks seemingly randomly aligned [duplicate]

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 2 years ago.
I'm trying to align multiple inline-blocks at the top of my page, but for reasons that are baffling to me, it's not working. The CSS could hardly be cleaner or less, but the top isn't aligning properly. I thought it could be a floating issue, but even after applying a clear:both it doesn't fix this.
Please see the program here:
https://jsfiddle.net/yezwocta/
#page {
text-align: center;
}
.article {
width: 350px;
height: 150px;
margin: 5px;
display: inline-block;
background-color: #fafafa;
}
.article img {
float: left;
width: 150px;
height: 130px;
margin-top: 10px;
}
.content {
position: relative;
display: inline-block;
width: 170px;
height: 130px;
margin-top: 10px;
margin-left: 10px;
text-align: left;
}
.title {
font-size: 1.2rem;
}
.source {
font-size: 0.8rem;
position: absolute;
bottom: 0;
left: 0;
}
<div id="page">
<div class="article">
<a href="https://cnn.com" target="_blank">
<img alt="News" src="https://loremflickr.com/150/130/news?random=1">
<div class="content">
<span class="title">Cable News Network</span>
<span class="source">CNN</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.mozilla.org/en-US/firefox/new/" target="_blank">
<img alt="Firefox browser" src="https://loremflickr.com/150/130/browser?random=2">
<div class="content">
<span class="title">Get the Latest Firefox Browser</span>
<span class="source">Mozilla</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.kproxy.com/" target="_blank">
<img alt="kproxy" src="https://loremflickr.com/150/130/proxy?random=3">
<div class="content">
<span class="title">Surf the web anonymously and bypass filters</span>
<span class="source">kproxy</span>
</div>
</a>
</div>
</div>
Add vertical-align: top; to your .article CSS (the default is baseline):
#page {
text-align: center;
}
.article {
width: 350px;
height: 150px;
margin: 5px;
display: inline-block;
background-color: #fafafa;
vertical-align:top;
}
.article img {
float: left;
width: 150px;
height: 130px;
margin-top: 10px;
}
.content {
position: relative;
display: inline-block;
width: 170px;
height: 130px;
margin-top: 10px;
margin-left: 10px;
text-align: left;
}
.title {
font-size: 1.2rem;
}
.source {
font-size: 0.8rem;
position: absolute;
bottom: 0;
left: 0;
}
<div id="page">
<div class="article">
<a href="https://cnn.com" target="_blank">
<img alt="News" src="https://loremflickr.com/150/130/news?random=1">
<div class="content">
<span class="title">Cable News Network</span>
<span class="source">CNN</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.mozilla.org/en-US/firefox/new/" target="_blank">
<img alt="Firefox browser" src="https://loremflickr.com/150/130/browser?random=2">
<div class="content">
<span class="title">Get the Latest Firefox Browser</span>
<span class="source">Mozilla</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.kproxy.com/" target="_blank">
<img alt="kproxy" src="https://loremflickr.com/150/130/proxy?random=3">
<div class="content">
<span class="title">Surf the web anonymously and bypass filters</span>
<span class="source">kproxy</span>
</div>
</a>
</div>
</div>

How to center 3 divs with img and label each into other div like this image (anexo)?

I need to create a header, including some contacts for a company, and in that header I need to insert images and labels (as in the attached image), how do I create a header faithful to this layout?
Remember that the labels should be vertically centered on the divs.
I tried so far:
#head {
left: 0;
top: 0;
width: 100%;
color: white;
font-weight: bold;
}
#head_center {
/*position: relative;*/
width: 100%;
float: left;
background-color: red;
text-align: center;
display: inline-block;
}
#head_left {
width: 30%;
float: left;
}
#head_right {
width: 30%;
float: left;
}
#head_center_center {
width: 30%;
float: left;
}
<div id="head">
<div id="head_center">
<div id="head_right">
<img src="images/icons/icon_phone.png"> 47 4101 8990
</div>
<div id="head_center_center">
<img src="images/icons/icon_facebook.png"> copecdigital1
</div>
<div id="head_left">
<img src="images/icons/icon_email.png"> copec#copecdigital.com.br
</div>
</div>
</div>
To center inline elements you can use display: inline-block; and text-align: center; on the parent:
.container {
background: red;
text-align: center;
padding: 5px;
color: white;
}
.single-set {
display: inline-block;
margin: 0 10px;
vertical-align: center;
overflow: hidden;
}
i, span {
vertical-align: middle;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<div class="container">
<div class="single-set">
<i class="material-icons">face</i>
<span class="text">Text</span>
</div>
<div class="single-set">
<i class="material-icons">face</i>
<span class="text">Text</span>
</div>
<div class="single-set">
<i class="material-icons">face</i>
<span class="text">Text</span>
</div>
</div>

Vertical aligning of pictures with links inside a div

I've been struggling with this simple and basic problem for the last day and can't seem to find a solution for it nowhere.
I'm having a container div on my website, in which there are four social network buttons, and what I'm trying to achieve is vertically align them in to the middle
of the container, so there's equal amount of free space on top of them and underneath them.
Please note, that I've linke normalize.css and reset.css to my html.
Muh code:
HTML
<div class="social-line-container">
<div class="social-line-buttons-group">
<a href="#0"><img src="socialicons/facebook.png" alt="FB"><a/>
<a href="#0"><img src="socialicons/twitter.png" alt="TW"><a/>
<a href="#0"><img src="socialicons/google.png" alt="GO"><a/>
<a href="#0"><img src="socialicons/youtube.png" alt="YT"><a/>
</div>
</div>
CSS
.social-line-container {
width: 66%;
height: inherit;
margin: 0 auto;
}
.social-line-buttons-group a{
display: inline-block;
vertical-align: middle;
height: 100%;
float: right;
padding: 2px;
margin: 0 3px;
}
Any help will be much appreciated.
All you need to add is clear
.social-line-container {
width: 66%;
height: inherit;
margin: 0 auto;
}
.social-line-buttons-group a {
display: inline-block;
/*vertical-align: middle;*/
height: 100%;
float: right;
clear: both; /* add */
padding: 2px;
margin: 0 3px;
}
<div class="social-line-container">
<div class="social-line-buttons-group">
<a href="#0">
<img src="socialicons/facebook.png" alt="FB"><a/>
<a href="#0">
<img src="socialicons/twitter.png" alt="TW"><a/>
<a href="#0">
<img src="socialicons/google.png" alt="GO"><a/>
<a href="#0">
<img src="socialicons/youtube.png" alt="YT"><a/>
</div>
</div>
.social-line-container{
border:2px solid black;
}
.social-line-buttons-group{
display:flex;
align-items: center;
justify-content: center;
height:100%;
}
.social-line-buttons-group a{
padding: 2px;
margin: 0 3px;
}
img{
width:50px;
height:50px;
}
<div class="social-line-container">
<div class="social-line-buttons-group">
<img src="http://lh3.googleusercontent.com/-ElsaNCI_yKg/VcXI_VFictI/AAAAAAAAINA/MeFjL1Ymaac/s640/StylzzZ%252520%252528289%252529.png" alt="FB">
<img src="https://upload.wikimedia.org/wikipedia/it/archive/0/09/20160903181541!Twitter_bird_logo.png" alt="TW">
<img src="http://www.userlogos.org/files/logos/annyella/google3.png" alt="GO">
<img src="http://logok.org/wp-content/uploads/2014/08/YouTube-logo-play-icon-219x286.png" alt="YT">
</div>
</div>

Centering all text of <a> as display block, vertically and horizontally

<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css">
<style>
#metro {
width: 100%
height: auto;
font-size: 16px;
}
#metro .metro_half_row {
width: 50%;
float: left;
height: 100px;
color: white;
background-color: grey;
}
#metro .metro_half_row a {
display: block;
height: inherit;
text-align: center;
}
</style>
<div id="metro">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
I've wrapper as #metro, .metro_half_row as each section, using a display: block
Right now the text in <a> is centered horizontally, but not vertically. I need to center the text contained in the links, and each <a> covering the entire sub div block both horizontally and vertically.
display: table and display: table-cell are your friends.
#metro {
width: 100%;
height: auto;
font-size: 16px;
}
#metro .table-block {
width: 100%;
display: table;
}
#metro .table-cell {
width: 50%;
display: table-cell;
vertical-align: middle;
}
#metro .metro_half_row {
width: 100%;
height: 100px;
color: white;
background-color: grey;
display: table;
}
#metro .metro_half_row a {
width: 100%;
display: table-cell;
height: inherit;
text-align: center;
vertical-align: middle;
}
<link href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css" rel="stylesheet" />
<div id="metro">
<div class="table-block">
<div class="table-cell">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
<div class="table-cell">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
</div>
<div class="table-block">
<div class="table-cell">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
<div class="table-cell">
<div class="metro_half_row">
<a href="#">
<h1>TEXT1</h1>
<h2>TEXT</h2>
</a>
</div>
</div>
</div>
</div>
If i understand your problem correctly in your case, the CSS may look like this:
a{
margin-top:25px;
}
or
a{
position: relative;
top: 25%;
}
Try:
#metro .metro_half_row a {
display: table-cell;
width: inherit;
vertical-align: middle;
height: inherit;
text-align: center;
}
#metro .metro_half_row {
display: table;
}
view http://jsfiddle.net/alemarch/589pqd62/