elements will not center within a div - html

I have three elements that are coded similarly .infobtnlg, .twitter, .infobtnsm.
The first .infobtnlg is centered nicely within a div .section1 as I want it to be, the second .twitter and third .infobtnsm are not centered within their respective sections. The width is set, the left/right margins are auto. I added text-align: center; for good measure.
What am I missing?
DEMO PLAYGROUND
HTML
<div class="trisection">
<div class="section1">
<button type="button" class="infobtnlg">The May Difference</button>
<button type="button" class="infobtnlg">Parent Reflections</button>
<button type="button" class="infobtnlg">Make a Gift</button>
</div>
<div class="section2">
<div class="twitter">
<img src="/images/twitter-bl.png" alt="twitter"/>Announcements
<hr>
</div>
</div>
<div class="section3">
<button type="button" class="infobtnsm" style="background-color: #003b76;">In the News</button>
<button type="button" class="infobtnsm" style="background-color: #5a9331;">The May Way</button>
<button type="button" class="infobtnsm" style="background-color: #ff0000;">Meet Our Teachers</button>
<button type="button" class="infobtnsm" style="background-color: #ffcc00;">Friends of May</button>
<button type="button" class="infobtnsm" style="background-color: #fb8d20;">The May Center</button>
</div>
</div>
CSS
.section1, .section2, .section3 {
width: 90%;
margin: 0px auto;
height: 255px;
text-align: center;
}
.infobtnlg, .twitter, .infobtnsm {
display: block;
width: 93%;
margin: 6px auto;
border-radius: 10px;
}
.infobtnlg {
font-family: Garamond, Georgia, 'Times New Roman', serif;
font-size: 1.5em;
background-color: #5a9332;
height: 77px;
text-shadow: -1px -1px 1px #3c3c3c;
box-shadow: -2px 2px 1px #3c3c3c;
}
.twitter {
height: 240px;
background-color: #fff;
background-image: url("/images/twfeed.png");
background-size: contain;
color: #5a9332;
font-size: 18px;
vertical-align: middle;
font-weight: bold;
border: solid 1px #e2dce0;
}
.infobtnsm{
font-family: Scala, Myriadbold, sans-serif;
font-size: 18px;
text-align: center;
height: 40px;
margin-bottom: 5px;
}

Add float: none; to .twitter and .infobtnsm or remove float: left; from
.vista .ie8 .infobtnlg, .twitter, .infobtnsm {
float: left;
width: 30%;
}

text-align will help you centering text inside those div
//to center contents inside div you shoul use:
#div {
margin:auto;
}
OR
you may simply choose to use bootstrap div columns which will do all your things very easy these contents will be fully responsive
//html
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 section1">
//section1 contents
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 twitter">
//twitter contents
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 infobtnsm">
//infobtnsm contents
</div>
</div>
</div>
</div>

Related

CSS Bootstrap setting button width for landscape and portrait

I wish to set multiple buttons to equal width in a container. I also wish to get the button to resize when it is in landscape mode or wider screen. How am I able to achieve that?
What I am trying to achieve is as follow
But what I get when I switch it back to Potrait
The code is in JSFiddle JSFiddle Code
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
.card{
border:0px solid;
position:relative;
height:200px;
background:url("https://preview.ibb.co/kJvJ5e/1847p.png") no-repeat top center;
background-size:cover;
}
.card img {
width:100%;
}
.search-box {
position : absolute;
display:inline-block;
bottom:-30px;
left:0;
right:0;
padding:15px;
text-align:center;
}
.drop-shadow {
-webkit-box-shadow: 0 0 2px 2px rgba(0, 0, 0, .5);
box-shadow: 0 0 10px 1px rgb(211, 211, 211, 0.8);
border-radius:0px;
}
.container-fluid{
width:auto
}
.container-fluid.drop-shadow {
margin-top:2%;
margin-left:5%;
margin-right:5%
}
#child{
width:100%;
height: 20px;
margin: auto;
text-align: center;
margin-top: 40px;
}
.form-group {
width:100%;
margin-bottom:10px;
}
.btn-checkin{
display: inline-block;
text-align: center;
white-space: nowrap;
color: #fff;
border-color: #EC008c;
text-transform: uppercase;
background-color: #EC008c;
font-family:'Open Sans','Helvetica Neue',Arial,sans-serif;
padding: 0.375rem .75rem;
font-size: 13px;
border-radius: .25rem;
}
.icon-addon {
position:relative;
}
.icon-addon label {
position: absolute;
left: 2px;
top: 2px;
padding: 8px;
font-size: 20px;
}
.icon-addon input {
height:40px;
padding-left:35px;
}
.currentposition{
position: -webkit-sticky;
position: sticky;
right:20px
}
.wrap {
width: 100%;
height: 50px;
padding-top: 10px;
padding-bottom:10px;
text-align: center;
}
button{
margin-left: 15px;
display: inline-block;
text-align: center;
white-space: nowrap;
color: #000000;
border-color: #B9E5fB;
text-transform: uppercase;
background-color: #B9E5fB;
font-family:'Open Sans','Helvetica Neue',Arial,sans-serif;
padding: 10px 10px;
font-size: 13px;
border-radius: 10px;
width:20%;
}
button:first-child{
margin-left: 0;
}
<body id="page-top" style="font-family:Arial">
<div class="card" >
<div class="search-box">
<div class="form-group">
<div class="icon-addon addon-lg">
<input type="text" placeholder="Search classes" class="form-control" id="searchBar">
<label for="searchBar" class="glyphicon glyphicon-search" rel="tooltip" title="searchBar"></label>
</div>
</div>
<button class="btn-checkin" style="font-family:Arial">Check in</button>
</div>
</div>
<div id="child">
<div class="container-fluid">
<img src="img/location.png" class="pull-left" style="width:25px;height:20px;padding-left:10px" />
<p class="pull-left" style="padding-left:10px;font-family:Arial">Current Location <b>Sri Petaling</b></p>
</div>
<div class="container-fluid drop-shadow">
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="img/7557.jpg" style="width:104px;height:64px;padding:10px 10px 10px 5px" alt="Generic placeholder image">
</a>
</div>
<div class="media-body">
<h5 class="media-left" style="padding-top:12px;color:#B9E5fB;font-family:Arial" >PERSONAL TRAINING</h5>
<p class="pull-left" style="font-size:12px;font-family:Arial;padding-top:3px">Strike Academy Fitness</p>
</div>
</div>
</div>
<div class="container-fluid drop-shadow" style="margin-top:20px">
<div class="container">
<p class="pull-left" style="font-size:12px;font-family:Arial;padding-top:3px">Plan your time</p>
</div>
<div class="wrap">
<button>All</button>
<button >Morning</button>
<button >Afternoon</button>
</div>
<div class="wrap">
<button>Evening</button>
<button>Tomorrow</button>
<button>This Week</button>
</div>
</div>
</div>
</body>
Results still not working? Please help
You can use bootstrap grid to achieve your goal. Wrap your buttons inside bootstrap columns as below. This creates columns of equal width and your buttons reside within each columns.
<div class="row">
<div class="col"> <button class="mybtn"> All </button> </div>
<div class="col"> <button class="mybtn">Morning</button> </div>
<div class="col"> <button class="mybtn">Afternoon</button> </div>
</div>
You can add spacing between your buttons by providing a margin:
.mybtn
{
margin:0 5px;
}
Read more Here
Use col-md-4 for medium size devices, col-sm-4 for small devices, col-xs-4 for extra small devices.
Try this link.
http://jsfiddle.net/my5hdu6k/7/
To settle the button the way you want, you need to limit the width of them not exceeding 33.33% of total width in any screen size.For that, you need to use parent row div and wrap each button inside col div as shown in the code below.
<div class="wrap">
<div class="row">
<div class="col">
<button>Button 1</button>
</div>
<div class="col">
<button>Button 2</button>
</div>
<div class="col">
<button>Button 3</button>
</div>
</div>
Then, you have to trick the text to be ellipsis to safe guard the exceeding text for the smaller screen ( this may not be require for your this instance but it is good practice to plan for worst ). Look closely to the changes I made for the .button class in CSS.
.wrap {
width: 250px;
height: 50px;
padding: 25px;
text-align: center;
display: inline-block;
width:100%;
}
.col{padding:0 5px;display:inline-block;width:33.33%;}
.row{margin:0 -5px;} /* Customized the .row class of bootstrap */
button{
margin:5px 0; /* to undo your older style */
width:100%;
text-overflow: ellipsis;
white-space:nowrap;
overflow:hidden;
}
button:first-child{
margin:5px 0; /* to undo your older style */
}
Please check the provided jsfiddle

Align button at bottom of floating div

I have an overview page with tiles and I use the matchheight library to dynamically determine the height of a row. Now I would like to align the 'more' buttons at the bottom of the div so that it doesn't look as messy as in the screenshot on smaller screens.
I tried making the button "position: absolute" with "bottom: 20px" and "left: 40%" but that causes problems with responsiveness. On some resolutions that's okay, but on other's the button is too far to the right.
Can I solve this in a nice way without having to use the media attribute for each resolution?
/* Block: Overview */
#overview {
padding-top: 50px;
width: 100%;
}
.overview {
text-align: center;
padding-bottom: 50px;
}
.overview img {
width: 100%;
vertical-align: middle;
padding-bottom: 30px;
}
.card-title {
text-align: center;
letter-spacing: -1px;
font-weight: 600;
font-size: 20px;
}
.card-subtitle {
margin-bottom: 0;
font-style: italic;
font-weight: 400;
font-size: 15px;
font-family: "Lora", serif;
color: #cccccc;
margin-top: -1rem;
line-height: 1.7857;
padding-bottom: 1rem;
text-align: center;
}
.btn-card {
background-color: #cccccc;
border-color: #404040;
color: #404040;
letter-spacing: 2px;
padding: 10px 20px;
horiz-align: center;
position: relative;
margin-bottom: 0;
}
.btn-card:hover {
background-color: #ffffff;
color: #404040;
border-color: #404040;
letter-spacing: 2px;
padding: 10px 20px;
}
<div class="col-sm-3 overview row-eq-height">
<div class="col-sm-12 text-center wow fadeInLeft">
<img alt="Heavy Entertainment Show" src="/images/discography/the-heavy-entertainment-show-1.jpg">
</div>
<h3 class="card-title">Heavy Entertainment Show</h3>
<h4 class="card-subtitle">November 4<sup>th</sup>, 2016</h4>
<a href="/album/the-heavy-entertainment-show/" title="Show details of Heavy Entertainment Show">
<button class="btn btn-card">MORE</button>
</a>
</div>
<div class="col-sm-3 overview row-eq-height">
<div class="col-sm-12 text-center wow fadeInLeft">
<img alt="Under the Radar Vol 1" src="/images/discography/under-the-radar-vol-1-1.jpg">
</div>
<h3 class="card-title">Under the Radar Vol 1</h3>
<h4 class="card-subtitle">December 1<sup>st</sup>, 2014</h4>
<a href="/album/under-the-radar-vol-1/" title="Show details of Under the Radar Vol 1">
<button class="btn btn-card">MORE</button>
</a>
</div>
<div class="col-sm-3 overview row-eq-height">
<div class="col-sm-12 text-center wow fadeInLeft">
<img alt="Swings Both Ways" src="/images/discography/swings-both-ways-1.jpg">
</div>
<h3 class="card-title">Swings Both Ways</h3>
<h4 class="card-subtitle">November 18<sup>th</sup>, 2013</h4>
<a href="/album/swings-both-ways/" title="Show details of Swings Both Ways">
<button class="btn btn-card">MORE</button>
</a>
</div>
<div class="col-sm-3 overview row-eq-height">
<div class="col-sm-12 text-center wow fadeInLeft">
<img alt="Take the Crown" src="/images/discography/take-the-crown-1.jpg">
</div>
<h3 class="card-title">Take the Crown</h3>
<h4 class="card-subtitle">November 2<sup>nd</sup>, 2012</h4>
<a href="/album/take-the-crown/" title="Show details of Take the Crown">
<button class="btn btn-card">MORE</button>
</a>
</div>
This is the correct solution, adding a "transform:translateX(-50%);" for alignment. Thanks for the help!
.btn-card {
background-color: #cccccc;
border-color: #404040;
color: #404040;
letter-spacing: 2px;
padding: 10px 20px;
position: absolute;
bottom: 0;
left: 50%;
transform:translateX(-50%);
margin-bottom: 20px;

Any ideas how to display divs vertically in bootstrap container?

I have these divs that are products
<div class="container">
<div class="product">
<div class="image"><img class="img-responsive" src="http://www.shingpoint.com.pk/Images/Thumbnails/pc-a1-470-59100-080316082835.jpg"/></div>
<div class="description">
<h4 class="productname">ASUS VivoMini PC - UN65H-M030M</h4>
</div>
<div class="price">
<span>Rs. 37,900</span>
<input type="button" class="btn btn-primary btn-sm" value="Details"/>
</div>
</div>
<div class="product">
<div class="image"><img class="img-responsive" src="http://www.shingpoint.com.pk/Images/Thumbnails/pc-a1-470-59100-080316082835.jpg"/></div>
<div class="description">
<h4 class="productname">ASUS VivoMini PC - UN65H-M030M</h4>
</div>
<div class="price">
<span>Rs. 37,900</span>
<input type="button" class="btn btn-primary btn-sm" value="Details"/>
</div>
</div>
</div>
And its CSS
.image{
display: block;
overflow: hidden;
position: relative;
text-align: center;
width: 100%;
max-height: 180px;
height: 60%;
margin-left: auto;
margin-right: auto;
padding-left:.40cm;
}
.description{
margin: 0 auto;
max-width: 95%;
}
.productname{
overflow: hidden;
display: block;
margin: 25px 0 0;
padding: 0;
line-height: 24px;
}
.price{
margin-top: 10px;
margin-bottom: 8px;
font-size: 18px;
font-weight: 500;
color: #E40613;
}
.product{
height: 320px;
border: 1px solid #DDDDDD;
border-bottom: 1px solid #DDDDDD;
text-align: center;
padding: 10px 0;
}
Now these are just two divs but they can be 10 or 15 through foreach loop when data is fetched from mysql
Now these divs are showing horizontally I want to have them vertically in a container with a slider, if not slider possible then how could displaying vertically be achieved?
You have to add display: inline-block to the product class. You may need to define widths as well if you have many divs.

Adding a gap between two column divs with the same class side-by-side

I know this was asked many times in SO but I can't find the answer for my question. I used bootstrap with this one and tried to have a two six columns in a row. It works as expected but what I want to achieve is that I wanted to out a gap between them. To see what I mean you can check it here.
I don't want to override the bootstrap cols here. I wanted to use only the added class which is survey-extra.
HTML
<div class="container">
<div class="row visit-redeem text-center">
<h5>Visit Site To Redeem</h5>
</div>
<div class="row">
<div class="col-xs-6 survey-extra">
<h5>FROM OUR SPONSORS</h5>
<span class="money-extra">$0.00</span>
</div>
<div class="col-xs-6 survey-extra">
<h5>FREEBIES</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
</div>
CSS
.survey-extra {
background: #1e90ff;
color: #fff;
padding: 5px;
border-radius: 10px;
text-transform: uppercase;
}
.visit-redeem {
background: #56a4da;
margin-top: 5px;
margin-bottom: 6px;
color: #fff;
padding: 5px;
border-radius: 20px 20px 0 0;
text-transform: uppercase;
}
I also tried the CSS3 :nth-of-type() Selector but no luck!
I wanted to do this using css only.
Try putting survey-extra within col-xs-6 instead. Hope that help
.survey-extra {
background: #1e90ff;
color: #fff;
padding: 10px;
border-radius: 10px;
text-transform: uppercase;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="survey-extra">
<h5>FROM OUR SPONSORS</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
<div class="col-xs-6">
<div class="survey-extra">
<h5>FREEBIES</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
</div>
</div>
I was able to put a visual space between the two divs by using CSS to set the width of .survey-extra to a percentage and then giving either one of the divs (using the :nth-of-type() Selector) or both of them margins, like this:
.survey-extra {
width: 45%;
margin-right: 5px;
background: #1e90ff;
color: #fff;
padding: 5px;
border-radius: 10px;
text-transform: uppercase;
}
Check it out on JSFiddle.
Of course you'd have to play around with the width percentage and margins to get exactly what you want.
If you don't want to use margins, you could also keep the width set to a percentage and then use floating, like this:
.survey-extra {
background: #1e90ff;
color: #fff;
width: 45%;
padding: 5px;
border-radius: 10px;
text-transform: uppercase;
}
.survey-extra:nth-of-type(0) {
float: left;
}
.survey-extra:nth-of-type(1) {
float: right;
}
Check it out using floating on fiddle
I found a solution for my problem and I would like to share it to you for future references. What I did is add nth-of-type(2) and applied css.
CSS:
.survey-extra {
background: #1e90ff;
color: #fff;
padding: 5px;
border-radius: 10px;
text-transform: uppercase;
}
.survey-extra:nth-of-type(2) {
width: 49%;
float: right;
}
.visit-redeem {
background: #56a4da;
margin-top: 5px;
margin-bottom: 6px;
color: #fff;
padding: 5px;
border-radius: 20px 20px 0 0;
text-transform: uppercase;
}
HTML:
<div class="container">
<div class="row visit-redeem text-center">
<h5>Visit Site To Redeem</h5>
</div>
<div class="row">
<div class="col-xs-6 survey-extra">
<h5>FROM OUR SPONSORS</h5>
<span class="money-extra">$0.00</span>
</div>
<div class="col-xs-6 survey-extra">
<h5>FREEBIES</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
</div>
fiddle here
.survey-extra {
display: inline-block;
float: none;
margin: 0 2% 2% 0;
width: 49%;
}
.survey-extra:last-child {
margin-right: 0;
}
And if you have more than 1 row you can replace last-child with nth-child(2n)
no need to change in css just change html like below:
<div class="container">
<div class="row visit-redeem text-center">
<h5>Visit Site To Redeem</h5>
</div>
<div class="row">
<div class="col-xs-6">
<div class="survey-extra">
<h5>FROM OUR SPONSORS</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
<div class="col-xs-6">
<div class="survey-extra">
<h5>FREEBIES</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
</div>
</div>

Trouble with a checkbox inside a div with a dynamic height, how to do?

I've got a lot of trouble with getting my checkboxes vertical aligned in my divs with a dynamic height.
I have some of my view:
<div class="col-md-7">
<div class="row recent-information">
<div class="product-navigation">
<div class="product-header-text">
<div class="col-md-3 product-details">
<p>Product name</p>
</div>
<div class="col-md-4 product-details">
<p>Note</p>
</div>
<div class="col-md-2 product-details">
<p>Price</p>
</div>
<div class="col-md-2 product-details">
<p>Stock</p>
</div>
</div>
</div>
#foreach (var item in Model.Products)
{
<div class="product-header">
<div class="product-header-text">
<div class="col-md-3 product-details-entity">
<h6>#item.Name</h6>
</div>
<div class="col-md-4 product-details-entity">
<h6>#item.Description</h6>
</div>
<div class="col-md-2 product-details-entity">
<h6>#item.Price DKK</h6>
</div>
<div class="col-md-1 product-details-entity">
<h6>#item.Stock</h6>
</div>
<div class="col-md-1 product-details-checkbox">
#Html.CheckBox("naem", new { #class = "products-checkbox" })
</div>
</div>
</div>
}
</div>
</div>
And the style:
.product-header {
min-height: 7%;
min-width: 100%;
margin-bottom: 3px;
border-bottom: 1px solid #e6e6e6;
overflow: hidden;
}
.product-header-text {
width: 98%;
margin-left: 10px !important;
margin-right: 10px !important;
float: left;
font-weight: 700 !important;
margin-bottom: 3px;
height: 100%;
}
.product-details {
font-weight: 500 !important;
margin-top: 13px;
font-family: 'Raleway', sans-serif;
font-size: 12px;
height: auto;
min-height: 100%;
}
.product-details-entity {
margin-top: 20px;
height: auto;
}
input[type="checkbox"] {
background: #f8f8f5;
-webkit-appearance: none;
height: 22px;
width: 22px;
margin-top: 20%;
cursor: pointer;
margin-left: 65px;
}
input[type="checkbox"]:checked {
background-image: url("../Images/checkmark2.png");
height: 22px;
width: 22px;
}
My problem is, that my divs, the product-details are dynamically based on the content from the database, and I can't get my checkboxes to follow.