I know this question has been asked a lot about center a button or a div, but I can't find an answer for multiple buttons/divs.
I have a few sections in my design that require 2 or 3 buttons to be center aligned with a 10px margin between them, I also require them to span 2 cols. I'll paste the code below that I'm using and hopefully one of you can tell me where I'm making the mistake, thanks in advance.
<div class="container">
<div class="row">
<div class="col-lg-2 col-lg-offset-3 sec-1-btn">More</div>
<div class="col-lg-2 sec-1-btn">More</div>
<div class="col-lg-2 sec-1-btn">More</div>
</div>
</div>
#mixin btns {
background: $yellow;
color: $cream;
font-weight: 700;
font-size: 1.3em;
text-transform: uppercase;
text-align: center;
padding: 12px 0;
}
I have tried adding a margin-right: 10px to the buttons but then they aren't centered due the first being stuck in it's position. I have also tried using the center-block class but can't seem to get it to work. I'm sure I'm not the only person to have had this problem and it's probably me just not seeing the obvious. Once again, thanks in advance.
Use Bootstrap's text-center class..
<div class="container">
<div class="row">
<div class="col-lg-2 col-lg-offset-3 sec-1-btn text-center">More</div>
<div class="col-lg-2 sec-1-btn text-center">More</div>
<div class="col-lg-2 sec-1-btn text-center">More</div>
</div>
</div>
http://www.bootply.com/cK0rmAOcXR
Okay so, I had a similar problem where I needed two buttons centered at the top of the page. Due to the problem I just dropped it to one button (it was easier that way). Since I'm having the same problem now with three buttons, I can't drop them to one, so I reverted back to the two original buttons that caused me a problem and came up with this...
<div class="row start-btns">
<div class="col-lg-6 col-lg-offset-3 test">
<div class="row">
<div class="col-lg-5 pull-left start-btn">Get Started</div>
<div class="col-lg-5 pull-right tour-btn">Tour The Site</div>
</div>
</div>
</div> <!-- End .row .start-btns -->
#mixin btns {
background: $yellow;
color: $cream;
font-weight: 700;
font-size: 1.3em;
text-transform: uppercase;
text-align: center;
padding: 12px 0px;
}
.call-btn, .start-btn, .tour-btn {
#include btns;
}
.start-btn {
margin-right: 1em;
}
Having the parent ".test" span 6 cols and centered allowed me to nest another row with two buttons spanning 5 cols (actually 3 due to nesting) and pull one left and other right. This gives the effect that both buttons are spanning 3 columns and centered perfectly with a 10px spacing.
Related
I have a problem with my web application.
Explanation:
The longer the text displayed on the left (so another column), the larger the image.
So how can I get one column completely independent from another?
<section class="section">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-4 col-xs-4 p-4">
<h1>nosfera.app</h1>
<p>Oops, I think you got lost in the humble abode of Nosfera.
<p>But don't worry ! We will take care of you, you will be treated like a king, and soon everyone will
notice you, but for that, you have to join the dark side by clicking one of the two little buttons
below.
<div class=fields>
<div class=item>Log in</button></div>
<div class=item>Register</button></div>
</div>
</div>
<div class="col-md-6 col-xs-4 col-sm-4">
<div class="block"></div>
</div>
</div>
</div>
</section>
.section {
display: grid;
height: 90vh;
align-content: center;
}
.section p {
font-weight: 400;
font-size: 1.2rem;
}
.block {
background:url(../img/block.png);
background-size:contain;
background-repeat:no-repeat;
background-position:center;
width:100%;
height:100%
}
Demo
You are applying height:100% on the .block element CSS. It will grows with the text. Just set an fixed size (100px for instance), or limit the max-height and it will stop growing
I've made a short bio for me, which has my picture, my name and e-mail. I've been trying for hours to centralize it in my page, but I can't find a way to do it.
I used Bootstrap for this, making a column with size 2 for the picture and a column with size 10 for the text. I tried removing the whole grid thing, working with float: left and float: right to align the image and text and then centralizing everything, tried display: block; margin: 0 auto; too, but no success.
I believe the solution lies in creating a single element which has the image and text side to side and then centralizing it, though I can't seem to find a way to do it.
I would be grateful if someone explained how to achieve the desired effect.
Edit: Here's a picture of what I mean to achieve: https://i.imgur.com/vWgPg2M.png
That's what I got right now:
.profile-pic {
border-radius: 50%;
}
<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-2 col-xs-9">
<img class="img-responsive profile-pic" src="https://avatars0.githubusercontent.com/u/9438853">
</div>
<div class="col-md-10 col-xs-auto">
<h1>Telmo "Trooper"</h1>
<h4>telmo.trooper#gmail.com</h4>
</div>
</div>
</div>
I defined a class mycenter and set the flexbox property for it. The class is added to the row.
Please note the flex property may have compliance issues for older browsers. See here for details.
.profile-pic {
border-radius: 50%;
}
.mycenter {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
<div class="container-fluid">
<div class="row mycenter">
<div class="col-md-2 col-xs-9">
<img class="img-responsive profile-pic" src="https://avatars0.githubusercontent.com/u/9438853" width="200">
</div>
<div class="col-md-10 col-xs-auto">
<h1>Telmo "Trooper"</h1>
<h4>telmo.trooper#gmail.com</h4>
</div>
</div>
</div>
I used the offset class of Bootstrap to push the div, and added text-align:center;
NOTE: This is only applicable when the browser's size is within the range of col-xs, this is because you included col-md, meaning when it reached the range of col-md, it will use whatever you put in col-md. To make it applicable to all, you can remove col-md in both div so that the col-xs will be the default class for all sizes
body {
text-align: center;
}
.profile-pic {
border-radius: 50%;
}
<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-2 col-xs-8 col-xs-offset-2">
<img class="img-responsive profile-pic" src="https://avatars0.githubusercontent.com/u/9438853">
</div>
<div class="col-md-10 col-xs-8 col-xs-offset-2">
<h1>Telmo "Trooper"</h1>
<h4>telmo.trooper#gmail.com</h4>
</div>
</div>
</div>
I'm trying to stack text in a Bootstrap column but can't quite figure out how I would go about doing it.
Here's a crude mockup of what I'm trying to achieve:
The first word "THE" should take up 2 lines, while the 3 "SOMETHINGS" are 1 line each. Also is there a way to stretch the "SOMETHINGS" out to equal length if they were different words?
<div class="row">
<div class="col-lg-6">
<img class="img-responsive" src="img/logo.png"</img>
</div>
<div class="col-lg-6">
THE SOMETHING SOMETHING SOMETHING
</div>
</div>
Below is a start if you must use Bootstrap columns. If you adjust column sizing or font or text used, then adjust the font-sizes, line-heights and letter-spacing values.
Font-size mostly helped fill the view vertically, line-height assisted with vertical alignment, and letter-spacing helped the horizontal spacing for text (with 'SOMETHING' being the baseline length for this col size). I tweaked the numbers so it looked nice within the jsFiddle output, but on your site you should adjust the values as needed and wrap it accordingly so you don't get any unexpected output (stacking columns when view becomes smaller).
If you need it to be more flexible, you can create a function to calculate the measurements depending on each word length/col size. Your font family and words chosen will not be what I chose, so your mileage may vary.
If anyone else has a better solution without the use of external existing libraries, then please share! I'd like to know.
Output from my browser:
See jsFiddle
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.col-xs-4,
.col-xs-8 {
margin: 0;
padding: 0;
}
.content-text {
width: 100%;
}
#content-text-THE {
float: right;
font-size: 10.0vh;
line-height: 0.75em;
}
#content-text-top {
float: left;
font-size: 5vh;
line-height: 0.7em;
letter-spacing: 1.04em;
}
#content-text-mid {
float: left;
clear: left;
font-size: 5vh;
line-height: 0.8em;
letter-spacing: 0.08em;
}
#content-text-bot {
font-size: 5vh;
line-height: 0.8em;
letter-spacing: 0em;
}
<div class="container">
<div class="row">
<div class="col-xs-4">
<span id="content-text-THE">THE</span>
</div>
<div class="col-xs-8">
<div class="content-text">
<span id="content-text-top">COOL</span>
</div>
<div class="content-text">
<span id="content-text-mid">ESPRESSO</span>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-4">
</div>
<div class="col-xs-8">
<div class="content-text">
<span id="content-text-bot">SOMETHING</span>
</div>
</div>
</div>
</div>
I am using Bootstrap 4 Alpha 5 and I have the following HTML:
<div class="home-content">
<div class="container">
<div class="row flex-items-xs-middle">
<div class="col-md-7">
<h1 class="site-title text-xs-center text-md-left">
<span class="name">I'm Shivam Paw</span>
<span class="title">I create beautiful and bespoke websites to fit your needs</span>
</h1>
</div>
<div class="col-md-5">
<img src="https://www.shivampaw.com/wp-content/uploads/2016/10/shivampaw.png" class="float-md-right img-fluid logo-me mx-auto" alt="Shivam Paw">
</div>
</div>
</div>
</div>
However, if you see the image below then you will see that the content is misaligned to the left. I saw a post on this on SO but it said you have to put the row class in a container which I have already done.
You can see the site live at https://www.shivampaw.com
I looked at the .row CSS which has margin for left and right of -15px. Removing those margins fixed it but I don't think that's how it should be?
If this is what you expect then look at your CSS. This is the line centering your content
.text-xs-center {
text-align: center!important;
}
This should fix it though
.site-title {
font-size: 36px;
color: white;
font-weight: bold;
text-align: left !important;
}
Turns out I had some offending CSS in my style.css:
*, img.full-size{
max-width: 100%;
}
Changing it to:
img.full-size{
max-width: 100%;
}
Fixed the problem.
I'm currently making a website using Zurb Foundation. (See pictures further down)
The way I've layed out my navigation is using the foundation grid as follows:
HTML
<div class="row">
<!-- Navigation -->
<nav class="top-bar">
<div class="five columns">
<div class="one columns"></div>
<div class="five columns menu-elements rightalign">
About
</div>
<div class="one columns">
<div class="split"></div>
</div>
<div class="five columns menu-elements rightalign">
Testimonials
</div>
</div>
<div class="two columns logo">
<img src="images/logo.png" alt="">
</div>
<div class="five columns">
<div class="five columns menu-elements leftalign">
Services
</div>
<div class="one columns">
<div class="split"></div>
</div>
<div class="five columns menu-elements leftalign">
Contact
</div>
<div class="one columns"></div>
</div>
CSS
.top-bar { font-family: 'bebas_neueregular'; display: flex; text-align:center; margin-bottom:0px;
.menu-elements{ color: white; display: block; font-size: 32px; font-weight: normal; height: 45px; ; margin: 60px 0 0 0;}
.menu-elements > a{ color: white; }
.menu-elements > a:hover{ color:#e87524;}
.logo{padding: 10px 0 0 0; text-align:center; margin:auto;}
.split{width: 3px;background: white;height: 28px; font-size: 32px; margin: 60px 0 0 0; text-align:center;}
.leftalign{text-align:left}
.rightalign{text-align:right;}
The problem I'm having is with the way my menu actually looks.
This is with the rightalign and leftalign classes included.
And this is without them included.
I want the menu to be:
1: With the Logo dead center, hence why I've made the navigation into separate div's.
2: The links should take up an even amount of space each, however the way I've coded this makes the Testimonials link take up way more space that the other links, as it is longer which makes it look out of place and closer to the Logo. I tried fixing this by using the text-align style to align both inner links closer to the logo. But it still doesn't look right.
I'm wondering if anyone can think of any other ways I can try? Perhaps making the actual font stretch the letters to meet the edge of the div's or a certain percentage of the div by assigning more space in between the letters? I'll take any advice at this point.
If this isn't necessarily a programming question please point me in the right direction. I am looking for answers as to what I could try in code or in external reading: ie: "Look this up it might help" or "Here try this code it should correct them".
Thanks for any advice!