How to use display:block properly with buttons in css? - html

When I use display:block it doesn't want to work which was working before. When I inspect it shows me strike through on display:block. Now the buttons are positioned on the right side of the col, I'd need them to be positioned in the middle under the image.
html
<div class="sectionLight">
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-12 col-lg-4">
<img class="img-fluid imgCenter" src="images/square.png">
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-danger btn-lg btnCenter" data-toggle="modal" data-target=".square-modal-lg">Prime</button>
</div>
</div>
</div>
<div class="col-sm-12 col-lg-4">
<img class="img-fluid imgCenter" src="images/fibo.png">
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-danger btn-lg btnCenter" data-toggle="modal" data-target=".fibo-modal-lg">Fibo</button>
</div>
</div>
</div>
<div class="col-sm-12 col-lg-4">
<img class="img-fluid imgCenter" src="images/square_copy.png">
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-danger btn-lg btnCenter" data-toggle="modal" data-target=".prime-modal-lg">Square</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS
.btnCenter {
display: block;
margin: auto;
margin-top: 15px;
margin-bottom: 20px;
width: 50%;
}

You probably have included another css script that overwrites your current one.
You can try to make it !important. If that doesnt work, you might have to make your selector more spesific than the one currently overwriting it.
.btnCenter {
display: block !important;
margin: auto;
margin-top: 15px;
margin-bottom: 20px;
width: 50%;
}
You can debug this in the dev-tools. See the example image below:
In this example, primary.css is higher in the css hierarchy (meaning the file primary.css is included later than stacks.css) Therefore, it will overwrite the selector.

Related

Bootstrap Class col-lg... removes box-shadow

I have a css class:
.content-shadow {
box-shadow: 0 0 5px #888888 !important;
}
I am using this class at to locations in the file:
<div class="root-content-padder">
<div class="container">
<h1><strong>"</strong>Die Freiarbeit ist nur das Ergebnis deiner Basis</h1>
<div class="content-shadow">
<div class="text-center st-padding">
<iframe style="width: 50vw; height: 430px"
src="youtube.com...."></iframe>
</div>
<div class="text-center st-padding">
<button class="btn btn-default btn-lg">Text</button>
<strong>Or</strong>
<button class="btn btn-default btn-lg">Text</button>
</div>
</div>
</div>
<div style="height: 25px;"></div>
<div class="container">
<div class="content-shadow">
<div class="col-lg-4">
<h1>LoL</h1>
</div>
<div class="col-lg-8">
<p>Text</p>
<br/>
<a class="btn btn-default btn-lg" href="?page=me">Weiter lesen</a>
</div>
</div>
</div>
</div>
Now the first div which has the class content-shadow works fine, without a problem, but on the second one the shadow does not appear.
I can make the shadow visible on the second, if i remove the two divs <div class="col-lg-4">...</div> and <div class="col-lg-8">...</div>
That is extremely strange and i have no idea why, maybe here someone can help.
Regards Liz3
If you remove any style from debugger tool, it means it comments your style at run time.
As you are using external style and if you remove it from debugger tool, it comments the styles written in content-shadow, so where ever you have used content-shadow doesn't work.
But if you use inline-style and apply box-shadow in two different div and then remove any one of the box-shadow from debugger tool, it just comment your internal-style of that particular div at run-time where as another one will work
So, it's a normal behaviour
Coming to your second point, col-lg-* removes box-shadow
It is working with col-lg-* also as you can see the snippet. But shadow at the bottom is not visible, to make it visible apply padding-bottom: 10px; in the parent element of content-shadow.
.content-shadow {
box-shadow: 0 0 10px darkgreen !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="root-content-padder">
<div class="container">
<h1><strong>"</strong>Die Freiarbeit ist nur das Ergebnis deiner Basis</h1>
<div class="content-shadow">
<div class="text-center st-padding">
<iframe style="width: 50vw; height: 230px" src="youtube.com...."></iframe>
</div>
<div class="text-center st-padding">
<button class="btn btn-default btn-lg">Text</button>
<strong>Or</strong>
<button class="btn btn-default btn-lg">Text</button>
</div>
</div>
</div>
<div style="height: 25px;"></div>
<div class="container" style="padding-bottom: 10px;">
<div class="content-shadow">
<div class="col-lg-4">
<h1>LoL</h1>
</div>
<div class="col-lg-8">
<p>Text</p>
<br/>
<a class="btn btn-default btn-lg" href="?page=me">Weiter lesen</a>
</div>
</div>
</div>
</div>
So the solution was pretty straight forward:
I had to put a <div style="clear: both;"></div> after the
<div class="col-lg-4">
<h1>LoL</h1>
</div>
<div class="col-lg-8">
<p>Text</p>
<br/>
<a class="btn btn-default btn-lg" href="?page=me">Weiter lesen</a>
</div>

working with the grid system in Bootstrap

I am relatively new to web development in general and am having a layout crisis: I have a container-fluid that has a row split into two *col-md-6*s. Within a col-md-6 I want to be able to position elements horizontally. As shown in my code/picture; I am trying to make a simple div that is 95% the height of the button-group and shows up next to it...however it is showing up below it and is very short (I want it to be as tall as the button group). What is the protocol for sizing/positioning elements next to each other in Bootstrap like this?
<div class="container-fluid">
<div class="row">
<div class="col-md-6" style="background-color: lightcyan">
<div class="btn-group-vertical btn-group-lg">
<button type="button" class="btn btn-primary">Quick Select</button>
<button type="button" class="btn btn-primary">Show in Depth</button>
<button type="button" class="btn btn-primary">Delete Product</button>
</div>
<div id="prod_view">
yo
</div>
CSS:
#prod_view{
background: lightcoral;
width: 69%;
height: 95%;
margin-left: 23%;
border: solid;
}
What it looks like now:
I want the "yo" box to be more rectangular and to the right of the button group.
Here's a flex layout that will do that. You can use the justify-content property to affect the horizontal alignment, and align-items will affect the vertical alignment. Here's a visual guide for flexbox https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.custom-row {
display: flex;
justify-content: space-between;
}
.custom-row > div:last-child {
width: 69%;
}
#prod_view {
height: 95%;
background: lightcoral;
border: solid;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 custom-row" style="background-color: lightcyan">
<div class="btn-group-vertical btn-group-lg">
<button type="button" class="btn btn-primary">Quick Select</button>
<button type="button" class="btn btn-primary">Show in Depth</button>
<button type="button" class="btn btn-primary">Delete Product</button>
</div>
<div>
<div id="prod_view">
yo
</div>
</div>
</div>
</div>
</div>
Another way is with a single flexbox class. Add it to the row and col-md-6:
.flex {
display: flex;
}
<div class="container-fluid">
<div class="row flex">
<div class="col-md-6 flex" style="background-color: lightcyan">
<div class="btn-group-vertical btn-group-lg">
<button type="button" class="btn btn-primary">Quick Select</button>
<button type="button" class="btn btn-primary">Show in Depth</button>
<button type="button" class="btn btn-primary">Delete Product</button>
</div>
<div id="prod_view">
yo
</div>
</div>
</div>
</div>
http://www.codeply.com/go/wvCRJ0ufEB
In Bootstrap 4, flexbox is default so there is no need for the extra class.

Horizontally center-align a bootstrap button with accompanying text

I am trying to horizontally center-align a bootstrap button with accompanying text. But am not getting the expected output. Could someone tell me why its not centering?
<div class="col-md-12 well">
<div class="col-md-6">
<h2 class="btn btn-warning btn-lg btn-block">Sign in via google</h2>
</div>
<div class="col-md-6 text-center">
<span><em> Already have an account? Login</em></span>
</div>
</div>
I created a Plunker demo. In smaller screens it works as expected. But in larger screens it's not aligned properly.
Use col-md-offset-3 along with col-md-6 to center align your content:
<div class="col-md-offset-3 col-md-6">
...
</div>
Further more, set text-center class on the outside div and not on span tag:
<div class="col-md-offset-3 col-md-6 text-center">
<em> Already have an account? Login</em>
</div>
See fiddle here.
Try this:
.flex-centered {
display: flex;
justify-content: center;
margin-top: 31px;
height: 46px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-md-12 well">
<div class="col-md-6 text-center">
<h2 class="btn btn-warning btn-lg btn-block">Sign in via google</h2>
</div>
<div class="col-md-6">
<div class="flex-centered">
<em> Already have an account? Login</em>
</div>
</div>
</div>
use div outside of span tag
<div style="text-align:center;" ><span class="text-center"><em> Already have an account? Login</em></span>
</div>
Try this code...
<body>
<div class="row">
<div class="col-md-6 col-md-push-3">
<h2 class="btn btn-warning btn-lg btn-block">Sign in via google</h2>
</div>
<div class="col-md-6 col-md-offset-3">
<span><em> Already have an account? Login</em></span>
</div>
</div>
</body>
Plunker Link
After some fiddling around I found a solution..Its not a bootstrap solution. But its only few lines of css. If anyone found a bootsrap way post here and I will change the accepted answer. Thank you.
<div class="row well row-centered">
<div class="col-md-6 col-centered">
<h2 class="btn btn-warning btn-lg center-block">Sign in via google</h2>
</div>
<div class="col-md-6 text-center col-centered" >
<span><em> Already have an account?Login
</div>
</div>
here is the custom css
/* centered columns styles */
.row-centered {
text-align:center;
}
.col-centered {
display:inline-block;
float:none;
/* reset the text-align */
text-align:left;
/* inline-block space fix */
margin-right:-4px;
}

Horizontal align center with offset in Bootstrap 3

I have a bootstrap 3 based layout, with two columns, how can I make sure the text in the second aligns with the center (horizontal) of the page?
HTML:
<div class="row spaced">
<div class="col-sm-2 text-center">
<img src="Images/picture.png" alt="Image" height="100%" width="100%">
</div>
<div class="col-sm-10 text-center horizontal-center">
<h1 class="text-box text-center horizontal-center">Are you interested?</h1>
<button type="button" class="btn btn-primary btn-lg outline text-center">Find Out More</button>
</div>
</div>
CSS:
.horizontal-center {
display: inline-block;
vertical-align: middle;
text-align: center;
float: none;
}
JSFiddle
You can pull the image left and take it out of the container, then make the div 12 so it will use the whole screen
<div class="col-sm-2 pull-left">
<img src="Images/picture.png" alt="space taking image to push other columns off center" height="100%" width="100%">
</div>
<div class="container">
<div class="row spaced">
<div class="col-sm-12 text-center horizontal-center">
<h1 class="text-box text-center horizontal-center">Are you interested to find out more? Then click the button below.</h1>
<button type="button" class="btn btn-primary btn-lg outline text-center">Find Out More</button>
</div>
</div>
</div>
https://jsfiddle.net/ygznu3gy/

Vertical align a Row bootstrap Full Page

<div class="container">
<div class="row">
<div class="col-lg-4 col-sm-6"><div class="text-center"><a class="btn btn-default btn-lg" href="#" role="button">Sell</a></div></div>
<div class="col-lg-4 col-sm-6"><div></div></div>
<div class="col-lg-4 col-sm-12"><div class="text-center"><a class="btn btn-default btn-lg" href="#" role="button">Buy</a></div></div>
</div>
</div>
Ok so iam wanting the 2 buttons next to eachother as they are but want them both in the middle of the screen (Vertically)
Hey try setting the columns text-align left and right like this:
This will make 2 columns and format the left column as text-right and the right column as text left, which will bring them together in the center of the screen:
<div class="container">
<div class="row">
<div class="col-xs-6 text-right">
<a class="btn btn-default btn-lg" href="#" role="button">Sell</a>
</div>
<div class="col-xs-6 text-left">
<a class="btn btn-default btn-lg" href="#" role="button">Buy</a>
</div>
</div>
</div>
From this refference, you can check this out:
<div class="outer">
<div class="middle">
<div class="inner">
<a class="btn btn-default btn-lg" href="#" role="button">Sell</a>
<a class="btn btn-default btn-lg" href="#" role="button">Buy</a>
</div>
</div>
</div>
CSS:
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.inner {
text-align:center;
margin-left: auto;
margin-right: auto;
}
Codepen link: http://codepen.io/anon/pen/zGmagX