i'm create a little site like a app store page, and cant align all elements in the middle of div .game-dark
<div class="row">
<div class="game-dark col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="number col-lg-1 col-md-1 col-sm-1 col-xs-1">
<p>1</p>
</div>
<div class="col-lg-1 col-md-1 col-sm-2 col-xs-2">
<img src="img/kings-empire.png" alt="Kings Empire" title="Kings Empire" class="thumb img-responsive">
</div>
<div class="col-lg-8 col-md-8 col-sm-7 col-xs-5">
<h2 class="game-name">Kings Empire</h2>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-3">
<button type="button" class="btn btn-default">Скачать</button>
</div>
</div>
How i can vertical align all elements in the middle in my case?
Live example - here
there are multiple ways to realize this.
here a simple way:
add this to your css
.game-dark {
line-height: 100px;
}
no margin on <p>
.number p {
margin: 0;
}
set max-height to the img
.img-responsive {
min-height: 45px;
min-width: 45px;
max-height: 100px;
}
remove margin/padding of h2
h2.game-name {
margin:0;
padding: 0;
line-height: 100px
}
more ways are here http://www.vanseodesign.com/css/vertical-centering/
First set line-height to 98px on .game-dark.col-lg-12.col-md-12.col-sm-12.col-xs-12, and remove display: block style from image. That will align everything except second to last div. With h2 set top and bottom margin to 0, and also set line-height to 98px.
Related
I am doing a simple page with a bootstrap grid and I am having some problems with placing the middle row occupying the full height in the middle.
These are the 3 rows: page
I want to place the row with the logo in the middle, but I am having problems with it. I placed height: 100%;, height: auto;. I even placed the container height to 100% and auto and nothing works!
I think there is a concept about bootstrap heigh that I am missing, because its the heigh that I have problems
html:
<div class="container-fluid">
<div class="row">
<div class="col-md-1 col-2">
<img id="menuIcon" (click)="toggleRightSidenav()" onmouseover="this.src='../../../assets/Images/generic/menuIcon_hover.png'" src="/assets/Images/generic/menuIcon.png" onmouseout="this.src='/assets/Images/generic/menuIcon.png'">
</div>
<div class="col-md-10 col-8">
</div>
<div class="col-md-1 col-2">
<img id="helpIcon" routerLink="/guide" onmouseover="this.src='../../../assets/Images/home/helpIconHover.png'" src="/assets/Images/home/helpIcon.png" onmouseout="this.src='/assets/Images/home/helpIcon.png'">
</div>
</div>
<div class="row row align-items-center mh-100" >
<div class= "col-md-12">
<img id="logo" src="/assets/Images/home/Logo.png">
</div>
</div>
<div class="row align-items-center justify-content-around fixed-bottom">
<div class="col-md-2 col-sm-2">
<img id="addButton" routerLink="/addPlayer" onmouseover="this.src='../../../assets/Images/generic/addIcon_hover.png'" src="../../../assets/Images/generic/addIcon.png" onmouseout="this.src='/assets/Images/generic/addIcon.png'" />
</div>
<div class="col-md-2 col-sm-2">
<p>Players Waiting: {{playerWaiting}} </p>
</div>
<div class="col-md-2 col-sm-2">
<p>Listed Players: {{playersListed}}</p>
</div>
<div class="col-md-2 col-sm-2">
<img id="searchButton" routerLink="/search" onmouseover="this.src='../../../assets/Images/generic/searchIcon_hover.png'" src="../../../assets/Images/generic/searchIcon.png" onmouseout="this.src='/assets/Images/generic/searchIcon.png'" />
</div>
</div>
</div>
css:
div{
border: yellow 1px solid;
}
#menuIcon{
width: 100%;
height: auto;
}
#helpIcon{
width: 100%;
height: auto;
}
#addButton{
width: 100%;
height: auto;
max-width: 127px;
}
#searchButton{
width: 100%;
height: auto;
max-width: 127px;
}
https://www.codeply.com/p/Xd0xi5hFNc
Couple of things.
To be able to fill several rows, you'd need a height for the container div.
Current HTML
<div class="container-fluid">
Update as
<div class="container-fluid d-flex vh-100 flex-column">
Now you can easily make your middle div fill the remaining gap by adding a fill-height class.
Current HTML
<div class="row row align-items-center mh-100" >
Update as
<div class="row row align-items-center fill-height">
Add this to your css
.fill-height {
flex: 1;
}
.fixed-bottom {
position: sticky;
}
jsFiddle
I'm beginner in css and bootstrap,and have document whit this instruction:
Throughout the enitre website a 12 column grid is used. This allows for maximum flexibility and to serve all devices available. Within the 12 columns grid
The content is placed within the 12 column grid (1). The grid is scaled between two fixed margins (2). Grid and margins fill the entire screen width minus the width of the main navigation (3).
for that purpose write this:
<div class="row">
<div class="col-md-1 col-sm-1 col-lg-1">A</div>
<div class="col-md-1 col-sm-1 col-lg-1">B</div>
<div class="col-md-1 col-sm-1 col-lg-1">C</div>
<div class="col-md-1 col-sm-1 col-lg-1">D</div>
<div class="col-md-1 col-sm-1 col-lg-1">E</div>
<div class="col-md-1 col-sm-1 col-lg-1">F</div>
<div class="col-md-1 col-sm-1 col-lg-1">G</div>
<div class="col-md-1 col-sm-1 col-lg-1">H</div>
<div class="col-md-1 col-sm-1 col-lg-1">I</div>
<div class="col-md-1 col-sm-1 col-lg-1">J</div>
<div class="col-md-1 col-sm-1 col-lg-1">K</div>
<div class="col-md-1 col-sm-1 col-lg-1">L</div>
</div>
now want put image tag into A div:
<img src="http://hearstcommerce.ca/customcontent/members/premium/sample.jpg"/>
but now page not responsive,want that image show center of <div class="row">,how can i solve that?thanks all.
Well, your question is not really clear. Please have a look at this Fiddle and elaborate more on that what you exactly want to do or send us a design or any visual things can help.
Cheers
img {
display: block;
margin-left: auto;
margin-right: auto
}
<div class="row">
<div class="col-sm-1">A</div>
<div class="col-sm-12">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcS2Xjhc-NPN5UAWzKdY3Kpl29Tyt-zCC8aOd3Gez8i2zrF3BS9bSQ" />
</div>
<div class="col-sm-1">B</div>
<div class="col-sm-1">C</div>
<div class="col-sm-1">D</div>
<div class="col-sm-1">E</div>
<div class="col-sm-1">F</div>
<div class="col-sm-1">G</div>
<div class="col-sm-1">H</div>
<div class="col-sm-1">I</div>
<div class="col-sm-1">J</div>
<div class="col-sm-1">K</div>
<div class="col-sm-1">L</div>
</div>
Please have a look at the new example, I really have no idea what you want to do but you can play a lot with the cols and usually there is no need to add any margins! But if because of any reasons you want to add margins you can define a class (you can call it what ever you want) and then you can define the amount of margins :
In this example I called it "asset" : you can write it either on this way :
.asset {
margin-right: 20px;
margin-left: 20px;
}
or on this way:
.asset {
margin: 0 10px 20px 30px;
}
0 ===> shows margin-top(for zero there is no need to add "px")
10px ===> shows margin-right
20px ===> shows margin-bottom
30px ===> shows margin-left
now you can write :
.asset {
margin : 0 20px 0 20px;
}
img {
display: block;
margin-left: auto;
margin-right: auto
}
<div class="row">
<div class="col-sm-1">A</div>
<div class="col-sm-12">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcS2Xjhc-NPN5UAWzKdY3Kpl29Tyt-zCC8aOd3Gez8i2zrF3BS9bSQ" />
</div>
<div class="col-sm-1">B</div>
<div class="col-sm-1">C</div>
<div class="col-sm-1">D</div>
<div class="col-sm-1">E</div>
<div class="col-sm-1">F</div>
<div class="col-sm-1">G</div>
<div class="col-sm-1">H</div>
<div class="col-sm-1">I</div>
<div class="col-sm-1">J</div>
<div class="col-sm-1">K</div>
<div class="col-sm-1">L</div>
</div>
img {
display: block;
margin-left: auto;
margin-right: auto
}
.asset {
margin-right: 50px;
margin-left: 50px;
}
<div class="row asset">
<div class="">A</div>
<div class="col-xs-12">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcS2Xjhc-NPN5UAWzKdY3Kpl29Tyt-zCC8aOd3Gez8i2zrF3BS9bSQ" />
</div>
<div class="col-md-1 col-sm-1 col-lg-1">B</div>
<div class="col-md-1 col-sm-1 col-lg-1">C</div>
<div class="col-md-1 col-sm-1 col-lg-1">D</div>
<div class="col-md-1 col-sm-1 col-lg-1">E</div>
<div class="col-md-1 col-sm-1 col-lg-1">F</div>
<div class="col-md-1 col-sm-1 col-lg-1">G</div>
<div class="col-md-1 col-sm-1 col-lg-1">H</div>
<div class="col-md-1 col-sm-1 col-lg-1">I</div>
<div class="col-md-1 col-sm-1 col-lg-1">J</div>
<div class="col-md-1 col-sm-1 col-lg-1">K</div>
<div class="col-md-1 col-sm-1 col-lg-1">L</div>
</div>
If you want your image to stay inside a bootstrap column, you would need an extra css:
img {
max-width: 100%;
max-height: 100%;
}
Your html will look like this if you want to have the image inside the A div (it will be on the left of the screen):
<div class="row">
<div class="col-sm-1">
<img src="http://hearstcommerce.ca/customcontent/members/premium/sample.jpg" alt="">
</div>
<div class=" col-sm-1 ">B</div>
<div class=" col-sm-1 ">C</div>
<div class=" col-sm-1 ">D</div>
<div class=" col-sm-1 ">E</div>
<div class=" col-sm-1 ">F</div>
<div class=" col-sm-1 ">G</div>
<div class=" col-sm-1 ">H</div>
<div class=" col-sm-1 ">I</div>
<div class=" col-sm-1 ">J</div>
<div class=" col-sm-1 ">K</div>
<div class=" col-sm-1 ">L</div>
</div>
You do not need to use col-sm, col-md and col-lg together. If you are using just the col-sm it does the same effect of the others to large and medium screens.
If you want the image at the center always, you will need to use offset. Offset is just a blank column that goes on the left of your columns. Depending on the size you want, if you do like above, your image will always be at the center:
<div class="row">
<div class="col-sm-2 col-sm-offset-5">
<img src="http://hearstcommerce.ca/customcontent/members/premium/sample.jpg" alt="">
</div>
</div>
Just remember that a row can only have 12 columns. The way above I placed 5 blank columns to the left of the image, that takes 2 columns and then there are more 5 five columns to the right to complete the 12 columns.
what you can do is add a class in div tag and set image using css
.image1 {
background-image : url('../img/sample.jpg');
}
and ten in html
<div class="col-md-1 col-sm-1 col-lg-1 image1">A</div>
try, this may help
I've looked into this and follow a couple instructions and they don't seem to work.
Follow this link for the code:
https://jsfiddle.net/3h937r1q/7/
I've tried margin: 0 auto;(center-block class) and float: none; on the parent div but I can't seem to get it to work. Can anyone help me center div in the middle of the page and tell me why it isn't working?
Expected outcome: https://jsfiddle.net/3h937r1q/22/
Except I do not want to use margin-left to move it in to the middle
You can use col-offset:
<div class="col-xs-12 col-md-12 home-buttons center-block" >
<a href="#" class="col-xs-6 col-sm-4 col-md-2 HomepageBtn Animate col-sm-offset-2 col-md-offset-4" >
<div class="tile-text">
AP REVIEW
</div>
</a>
<a href="#" class="col-xs-6 col-sm-4 col-md-2 HomepageBtn Animate">
<div class="tile-text">
VAT CHECKER
</div>
</a>
</div>
I have removed height and given padding: 40px 0px to anchor tag
Updated DEMO
.home-buttons .HomepageBtn {
background-color: #4F7F64;
/*height: 140px;*/
padding: 40px 0px;
color: white;
font-size: small;
font-family: "futura-pt-n7", 'futura-pt', Helvetica, Arial, sans-serif;
font-weight: bold;
border-style: solid;
text-align: center;
}
I think you are looking for this. As you are using bootstrap grid in within a tag, you must use bootstrap offset class to center the element.
<div class="col-xs-12 col-md-12 home-buttons">
<a href="#" class="col-xs-6 col-sm-4 col-md-2 col-md-offset-4 col-sm-offset-2 HomepageBtn Animate">
<div class="tile-text">
AP REVIEW
</div>
</a>
<a href="#" class="col-xs-6 col-sm-4 col-md-2 HomepageBtn Animate">
<div class="tile-text">
VAT CHECKER
</div>
</a>
</div>
https://jsfiddle.net/25Lno6n7/
.home-buttons {
width:600px;
display:flex;
flex-direction:column;
align-items:center;
}
.home-buttons .HomepageBtn {
flex:0 0 300px;
}
I want to align different size images to the bottom of a div but the images are also in their own divs so the other answers don't work.
I have the following HTML:
<div class="row footer-links">
<section>
<div class="col-md-4">
<p>
Proudly presented and sponsored by
</p>
</div>
<div class="col-md-8 col-xs-12 logo-links">
<div class="row logo-bottom">
<div class="col-md-2 col-xs-12 logo-border col-md-offset-1">
<img id="rasv" class="center-block" src="img/rasv.png" alt="RASV logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/victoria-farmers.png" alt="Victoria Farmers logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/anz.png" alt="ANZ logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/pwc.png" alt="PWC logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/vac.png" alt="VAC logo">
</div>
</div>
</div>
</section>
</div>
I used the following CSS:
.logo-border {
border-right: 1px solid #d1d3d4;
height: 54px;
vertical-align: bottom;
display: table-cell;
}
Here is a Code Pen for more information.
You were really close.
The reason it wasn't working was because the columns are floated. Due to this, the elements weren't behaving like a table-cell, therefore rendering vertical-align: bottom useless.
You could simply add float: none and it will work as desired.
Updated Example
.logo-bottom .logo-border {
border-right: 1px solid #d1d3d4;
height: 54px;
vertical-align: bottom;
display: table-cell;
float: none;
}
As a side note, I increased the specificity of the selector .logo-border to .logo-bottom .logo-border so that float: left was overridden.
I have a section that includes three images. It looks perfectly fine on every display except mobile, where the images float right. They seem to align with a starting point at the center. Every other section on my site aligns perfectly as the boostrap rows tell them to.
<section id="press" class="parralax-window img-responsive" data- parallax="scroll" data-image-src="img/dawn.jpg">
<div class="row text-center">
<div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
<h2><strong>Omtale</strong></h2>
</div>
<div class="companies">
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-12">
<img src="http://i.imgur.com/0ETpuAx.png" class="img-responsive" alt="Iphoneguide - SvampeGuide">
</div>
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-12">
<img src="http://i.imgur.com/8W49tLt.png" class="img-responsive" alt="Politiken - SvampeGuide">
</div>
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-12">
<img src="http://i.imgur.com/pax4KwJ.png" class="img-responsive" alt="Spisesvampe - SvampeGuide">
</div>
</div>
</div>
</section>
I'm using a parralax plugin but I tried it without it and it doesn't seem to be causing anything.
My css:
#press {
color: white;
padding: 8em;
}
#press h2 {
padding-bottom: 5%;
font-size: 5vmax;
}
#press img {
min-height: 30px;
min-width: 150px;
display: inline !important;
}
I also tried removing the img-responsive class but that didn't help.
Do you any idea what's causing this?
http://jsfiddle.net/wyLqa8w5/1/
#press {
padding: 15%;
}
I think you should look into bootstrap a bit more.
For example,
<div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
can be shortened to just
<div class="col-xs-12">
Also, remember to self-close your image tags:
<img src="" />
<div class="col-md-12 col-lg-12 col-sm-12 col-xs-12">
<h2><strong>Omtale</strong></h2>
</div>
Hej,
I am pretty sure above code is incorrect and you should wrap the div for the col-md-12 around all 3 cols containing the img's - try it. Furthermore can you supply me with the .img-responsive class?
I'd like to see it.