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>
Related
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 need to adjust Bootstrap columns to look like this.
The thing is that on smaller devices I just want to hide this blank areas on the sides, thus I don't wanna use just margins or paddings.
How can I achieve that? col-md-1 seems too small for the indents, while col-md-2 is too broad.
My Codepen with Bootstrap included.
HTML
<div class="container">
</div>
CSS
.container {
height: 230px;
background-color: blue;
max-width: 1050px;
padding-left: 15px;
padding-right: 15px;
}
If you don't want to declare any new classes padding etc. You can simply nest the columns bootply.com
Not really sure what you're trying to achieve here. The container changes it width depending on the screen size using media queries. The white/blank space you're trying to get rid off is disappearing when the size of the screen is less than 768px.
What you can do, if I understand your question correct is this option:
HTML:
<!-- CONTAINER -->
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="row">
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
</div>
</div>
</div>
</div>
<!-- CONTAINER FLUID -->
<div class="container-fluid">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="row">
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
</div>
</div>
</div>
</div>
CSS:
.container-fluid,
.container {
height: 230px;
background-color: #333;
/* max-width: 1050px; */
padding-left: 15px;
padding-right: 15px;
margin-bottom: 15px;
}
html, body {
color: #fff;
}
Couldn't you just use a #media tag to cut the padding out when in mobile view? Makes it a lot easier. Just add the class below to either your container or row.
.marginClass{
margin: 0 15px 0 15px;
}
#media screen and (min-width: 480px) {
.marginClass{
margin: 0;
}
Actually you're probably better using margin. I've updated that.
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!
In my html I get 'response' from controller. Number of lines in the response varies (max is 3).
What is the best way to 'reserve' 3 lines on my html page so the next div with 'SOMETHING' paragraph is not scrolled down by 'response' ?
<div class="row">
<p ng-bind-html="response"></p>
</div>
<div class="row">
<p>SOMETHING</p>
</div>
Using CSS, fix the height occupied by your 3 rows and use overflow to scroll within that fixed height div.
CSS Overflow might help you.
.row-fixed-height {
height: 150px;
overflow: scroll;
}
and in HTML:
<div class="row-fixed-height">
<p ng-bind-html="response"></p></div>
Since the height of the lines varies based on font and font size, I would use line breaks to "reserve" the three lines. If you were to use for instance a fixed height on the div or p, it might jump around on a different browser that uses a different font.
Live Demo:
#response {
background: red;
}
<div class="row">
<p id="response" ng-bind-html="response">
<br />
<br />
<br />
</p>
</div>
<div class="row">
<p>SOMETHING</p>
</div>
JSFiddle Version: https://jsfiddle.net/rspyho74/
As oori pointed you, this is is about CSS, not Angular. The easiest way to fix the height to 3 lines is using the em unit:
.row{
margin: 10px;
padding: 5px;
border: 1px solid #000;
border-radius: 5px;
}
p{
float: left;
margin: 0 5px;
padding: 5px;
border: 1px solid #000;
height: 3em;
}
<div class="row">
<p ng-bind-html="response"></p>
<p ng-bind-html="response">Line 1</p>
<p ng-bind-html="response">Line 1<br>Line 2</p>
<p ng-bind-html="response">Line 1<br>Line 2<br>Line 3</p>
<div style='clear: both;'></div>
</div>
<div class="row">
<p>SOMETHING</p>
<div style='clear: both;'></div>
</div>
As you can see, the paragraph keeps its height no matter how many lines there are. If you remove the height property you can see the difference.
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.