DIv inside my Bootstrap div will not right align (but text does) - html

I am trying to align two divs, each of which are inside Bootstrap column divs. I want to align the one in the first column to the right, and the one in the second column to the left. The divs inside are positioned relative, so that content inside them can align absolutely. But even removing that positioning didn't fix my issue. I can't figure it out, because it works on teh plain text i place inside the columns/divs, just as a test, but not on the divs.
Here is my html:
<div class="container">
<div class="row">
<div class="leftFeature col-md-6">TESTTEXT<br>
<div class="blockFeature">
[types field='square-feature-image' size='full'][/types]
<div class="blockFeatureOverlay"></div>
<div class="blockFeatureText">
<h2>[types field='front-page-feature-tagline'][/types]</h2>
<h3>[types field='tag-line'][/types]</h3>
</div>
</div>
</div>
<div class="rightFeature col-md-6">TESTTEXT<br>
<div class="blockFeature">
[types field='square-feature-image' size='full'][/types]
<div class="blockFeatureOverlay"></div>
<div class="blockFeatureText">
<h2>[types field='front-page-feature-tagline'][/types]</h2>
<h3>[types field='tag-line'][/types]</h3>
</div>
</div>
</div>
</div>
</div>
Here is my css:
.leftFeature {
background-color:#F9D069;
text-align:center!important;
}
.rightFeature {
background-color:#B6DEFF;
text-align:center!important;
}
.col-sm-6 {padding:0;}
.blockFeature {
width:80%;
background-color:#7F9FA1;
background-size:100%;
line-height:0;
position:relative; /*removing this rule did not fix my issue */
}
.blockFeatureOverlay {
position:absolute;
width:100%;
height:100%;
top:0;
left:0;
background-color:rgba(0, 0, 0, 0.25);
/*background-color:rgb(158,84,6, 0.25);*/
}
.blockFeature a {
text-decoration:none;
}
.blockFeature img {
width:100%;
height:auto;
}
.blockFeatureText {
position:absolute;
bottom:20px;
left:20px;
}
.blockFeatureText h2 {
font-size:2.4em;
font-weight:700;
color:#fff;
text-transform:uppercase;
margin-bottom:10px!important;
line-height:100%!important;
text-align:left;
}
.blockFeatureText h3 {
font-size:1.2em;
font-weight:300;
color:#fff;
text-transform:uppercase;
margin-bottom:0!important;
line-height:100%!important;
text-align:left;
}
And this is a representation of what i am getting: http://imgur.com/a/LekqV
but this is what i want: http://imgur.com/a/ER1kB
It's probably (hopefully) something really obvious. But after 24 hours of messing around, I cannot seem to fix it. I have tried adding text-right or pull-right class on the left hand div, but it either does something different than I need, or doesn't work at all.
thank you for anyone who can maybe help me out?
EDIT: Here are two fiddles i created
forked from a fiddle where someone seemed to have already created the bootstrap environment: https://jsfiddle.net/Katrina_B/w4dt8qq7/
one with no bootstrap, in case the above is not correct, and someone knows better how to add bootstrap to it: https://jsfiddle.net/Katrina_B/c4kxa06s/
I am completely new to Bootstrap, and rarely use Jfiddle, so apologies if i have done this incorrectly. In any case, in neither example, are the divs doing what i expect or wish them to do.

simple you should use bootstrap pull-left and pull-right class to align your divs
<div class="leftFeature col-md-6 pull-left">TESTTEXT<br> .... </div>
<div class="rightFeature col-md-6 pull-right">TESTTEXT<br>....</div>

.leftFeature .blockFeature {
float: right;
}
This style may keep your complete div in right

Below the div with the class col-md-6 you can use bootstrap again. Try adding a div with class="col-md-10 col-md-offset-2" for the left side, and on the right side class="col-md-10"
<div class="container">
<div class="row">
<div class="leftFeature col-md-6">TESTTEXT<br>
<div class="col-md-10 col-md-offset-2>
<div class="blockFeature">
[types field='square-feature-image' size='full'][/types]
<div class="blockFeatureOverlay"></div>
<div class="blockFeatureText">
<h2>[types field='front-page-feature-tagline'][/types]</h2>
<h3>[types field='tag-line'][/types]</h3>
</div>
</div>
</div>
</div>
<div class="rightFeature col-md-6">TESTTEXT<br>
<div class="col-md-10">
<div class="blockFeature">
[types field='square-feature-image' size='full'][/types]
<div class="blockFeatureOverlay"></div>
<div class="blockFeatureText">
<h2>[types field='front-page-feature-tagline'][/types]</h2>
<h3>[types field='tag-line'][/types]</h3>
</div>
</div>
</div>
</div>
</div>
</div>

You should use bootsrap predefined pull-left and pull-right class to positioning div left and right. This could work for you.
Or you can use css float: left and float: right property.
Example:
.leftFeature {float: left;} and .rightFeature {float: right}

Related

How can I get my elements to align properly?

I need help with css in my angular app.
Here's my plunker:
https://plnkr.co/edit/5GvpLHcGq93yfpqHAJwy?p=preview
But here's the main code snippets as well:
import {Component} from '#angular/core'
#Component({
selector: 'app-child-component',
template: `<div class="header">
<div style="text-align:left;">
<div class="headerText"> Foo
<div style="float:right;">
<span class="headerText">Language</span>
<span>
<select style="margin-right:10px;margin-top:4px;">
<option *ngFor="let language of languages">{{language}}</option>
</select>
</span>
</div>
</div>
<div class="headerText"> Bar
<div style="text-align:-webkit-right; padding-right:10px;">
<span class="headerText">
user: admin
</span>
</div>
</div>
</div>
<div style="float:right;">
<div>
<button class="signOutButton">Sign Out</button>
</div>
</div>
</div>
`,
styles: [`.signOutButton {
background:#5dacb4 !important;
width:100px;
height:30px;
font-size:14px;
margin:5px;
float:right;
}
.header {
background:#3f3f3f;
}
.headerText {
color:#ffffff;
font-size:16px;
margin-bottom:0px;
margin-left:10px;
}`]
})
export class ChildComponent {}
The issue I'm having is I need user:admin to be on the same line as Bar
and the sign out button to align all the way right after the language and user and vertically aligned centered on the right.
How can I achieve that?
Something a bit like this?
.signOutButton {
background:#5dacb4 !important;
width:100px;
height:30px;
font-size:14px;
position:absolute;
right:10px;
top:50%;
transform:translateY(-50%);
}
.header {
background:#3f3f3f;
color:#ffffff;
font-size:16px;
position:relative;
padding:10px;
}
.left {
float:left;
}
.right {
float:right;
}
.line {
width:calc(100% - 110px);
}
.line::after { /* CLEARFIX */
content: "";
clear: both;
display: table;
}
<div class="header">
<div class="line">
<div class="left">
Foo
</div>
<div class="right">
<select>
<option>English</option>
</select>
</div>
</div>
<div class="line">
<div class="left">
Bar
</div>
<div class="right">
user:admin
</div>
</div>
<button class="signOutButton">Sign Out</button>
</div>
Explaination
Essentially, with a design like this, the approach that I took was to break it up into two parts: the two "Foo" / "Bar" lines, and the Sign Out button.
Each line needed to have something aligned to it's left, and something aligned to it's right. A normal line of text can't do this, but it is the perfect scenario in which to use float!
Unfortunately, floating elements don't take up any space, and since these lines are entirely comprised of floating elements, this means that they themselves don't take up any space. Thankfully, this problem was solved long ago, with a solution commonly known as the clearfix hack. This is what we use here.
For the Sign Out button, a little absolute positioning is all that we need to pop it in the right place (remember that absolute positioned elements inside elements positioned with relative or absolute will be positioned relative to that element, not the entire page). However, the lines will overlap with the button. Not good.
Therefore, we simply need to make the lines slightly shorter. How much shorter? I'd say 110px, as the button is 100px and it'll look nicer if we leave 10px of space between the end of the lines and the button, rather than having them pushed up against each other. We can use calc() to make these lines exactly 110px shorter, by simply having this value subtracted off of 100%.

Html <div class="row"> not centering

First I'd like to say that I know very little about coding.
In this website I made http://academiadae.com, I added two small divs at each side, so I could get a div class="6u" centered.
<div class="row">
<div class="3u"></div>
<div class="6u"><img src="images/logo.png" /></div>
<div class="3u"></div>
</div>
Can you help me to get it centered without the need for the other divs?
I tried making different elements =center in the CSS, but it didn't work.
Thanks.
First of all, your are using as class 6u which will not be selected. A CSS name must begin with an underscore (_), a hyphen (-), or a letter(a–z) to use it as an CSS selector. You can check this page for any reference.
Second if you want to have the a single div centered you could apply this:
<div class="row">
<div class="item6u">
test
</div>
</div>
Where there is only one div with a class name that starts with a letter.
For you CSS you need to set the width of the div and like #Sprazer told you need to set the margin:
.row{
background-color:yellow;
}
.item6u{
background-color:red;
width:50%; //changed to 50% percentage as wawa suggested
margin:0 auto;
text-align:center;
}
See code here: JSFIDDLE.
So, you currently have something like: HTML
<div class="row">
<div class="3u">
</div>
<div class="6u">
<img src="images/logo.png">
</div>
<div class="3u">
</div>
</div>
and CSS:
div.6u{
width: 50%;
clear: none;
float:left;
margin-left: 0;
}
You need to change this to HTML:
<div class="row>
<div class="6u">
...contents of the div here...
</div>
</div>
and CSS (note: do remove float:left, otherwise it will not work):
div.6u{
width:50%;
clear:none;
margin-left:auto;
margin-right:auto;
}

Create thee divs in one line and 4th div in bottom. CSS/HTML

I want to create html page the next vision. Location of divs 1,2 and 3 in one line was done, but with 4th div I have some troubles and can't make it.
You really should post your code to see whats wrong with it.. But i made the example for you.
Here you go, you could use float.
Html Code:
<div id="wrapper">
<div id="first">
</div>
<div id="second">
</div>
<div id="third">
</div>
<div id="fourth">
</div>
</div>
Css Code:
#wrapper{width:300px; margin:0;}
#first { height:300px; width:100px; background:black; float:left;}
#second{ height:250px; width:100px; background:red;float:left;}
#third{ height:250px; width:100px; background:green;float:left;}
#fourth{ height:50px; width:200px; background:blue;float:left;}
Working DEMO
Here's an example that uses non-fixed heights and widths. The key is wrapping the subsections in divs as well and styling accordingly. div is short for division after all.
<div class="left">
1
</div>
<div class="right">
<div class="second-third-wrapper">
<div class="second">
2
</div>
<div class="third">
3
</div>
</div>
<div class="fourth">
4
</div>
</div>
http://jsfiddle.net/Pb5NX/2/
The divs then use percentage height and widths to size them properly. These percentages take up a percentage of the parent element (the <body>, which then inherits from the <html>), so the parents height needs to be set as well.
body, html {
width: 100%;
height: 100%;
}
.left {
background-color: blue;
width: 50%;
height: 100%;
float: left;
}
If you want them a fixed size, you can just set a specific height and width style on the specific elements and the percentages will do the rest.

Align div right in Bootstrap 3

Is there a way in Bootstrap 3 to right align a div?
I am aware of the offsetting possibilitys but I want to align a formatted div to the right of its container while it should be centered in a fullwidth mobile view. The class 'pull-right' is not working anymore. Did they forgot to replace it or am I missing something obvious?
<div class="row">
<div class="container">
<div class="col-md-4">
left content
</div>
<div class="col-md-4 col-md-offset-4">
<!-- The next div has a background color and its own paddings and should be aligned right-->
<!-- It is now in the right column but aligned left in that column -->
<div class="yellow_background">right content</div>
</div>
</div>
</div>
Shure I know how to do this in CSS, but can it be done in pure bootstrap 3?
The class pull-right is still there in Bootstrap 3
See the 'helper classes' here
pull-right is defined by
.pull-right {
float: right !important;
}
without more info on styles and content, it's difficult to say.
It definitely pulls right in this JSBIN
when the page is wider than 990px - which is when the col-md styling kicks in,
Bootstrap 3 being mobile first and all.
Bootstrap 4
Note that for Bootstrap 4 .pull-right has been replaced with .float-right
https://www.geeksforgeeks.org/pull-left-and-pull-right-classes-in-bootstrap-4/#:~:text=pull%2Dright%20classes%20have%20been,based%20on%20the%20Bootstrap%20Grid.
Do you mean something like this:
HTML
<div class="row">
<div class="container">
<div class="col-md-4">
left content
</div>
<div class="col-md-4 col-md-offset-4">
<div class="yellow-background">
text
<div class="pull-right">right content</div>
</div>
</div>
</div>
</div>
CSS
.yellow-background {
background: blue;
}
.pull-right {
background: yellow;
}
A full example can be found on Codepen.
i think you try to align the content to the right within the div, the div with offset already push itself to the right, here some code and LIVE sample:
FYI: .pull-right only push the div to the right, but not the content inside the div.
HTML:
<div class="row">
<div class="container">
<div class="col-md-4 someclass">
left content
</div>
<div class="col-md-4 col-md-offset-4 someclass">
<div class="yellow_background totheright">right content</div>
</div>
</div>
</div>
CSS:
.someclass{ /*this class for testing purpose only*/
border:1px solid blue;
line-height:2em;
}
.totheright{ /*this will align the text to the right*/
text-align:right;
}
.yellow_background{
background-color:yellow;
}
Another modification:
...
<div class="yellow_background totheright">
<span>right content</span>
<br/>image also align-right<br/>
<img width="15%" src="https://www.google.com/images/srpr/logo11w.png"/>
</div>
...
hope it will clear your problem
Bootstrap 4+ has made changes to the utility classes for this. From the documentation:
Added .float-{sm,md,lg,xl}-{left,right,none} classes for responsive floats and removed .pull-left and .pull-right since they’re redundant to .float-left and .float-right.
So use the .float-right (or a size equivalent such as .float-lg-right) instead of .pull-right for your right alignment if you're using a newer Bootstrap version.
Add offset8 to your class, for example:
<div class="offset8">aligns to the right</div>

How can I increase the height of a span to a different row?

I know the title doesn't make sense but I don't know how to put it.
Take a look at this: http://jsfiddle.net/nr33k/embedded/result/
I want to increase the height of the well on the right to match the height of the two wells on the left together, so it looks like I have three small wells in one large rectangle. If I try to increase the height the obvious way by adding height:150px it causes the bottom well on the left to fall down. How do I solve this?
Please try to float:left; your row class and then set the height of the span on the right.
.row {float:left;}
Here's a working sample http://jsfiddle.net/BUgQc/
The issue is that the first two ''wells'' are in a row, while the third is in another row.
Try this:
<div class="row">
<div class="span4">
<div class="well well-small" style="height:50px">
<p>hello</p>
</div>
<div class="well well-small" style="height:100px">
<p>hello again</p>
</div>
</div>
<div class="span8">
<div class="well well-small" style="height:190px;">
<p>hello one more time</p>
</div>
</div>
</div>
Make the left side two DIV's in one single DIV and float it left and make the Right side bigger Well div in a single DIV and float if left.... hope this will help for you....
Check this example. Hope it helps
HTML
<div id="container2">
<div id="container1">
<div id="col1" style="height:250px">
<!-- Column one start -->
<h2>Equal height columns</h2>
<!-- Column one end -->
</div>
<div id="col2">
<!-- Column two start -->
<h3>Mac</h3>
<!-- Column two end -->
</div>
</div>
</div>​
CSS
#container2 {
float:left;
width:100%;
background:yellow;
position:relative;
right:30%;
}
#container1 {
float:left;
width:100%;
background:red;
position:relative;
right:40%;
}
#col1 {
float:left;
width:26%;
position:relative;
left:72%;
overflow:hidden;
}
#col2 {
float:left;
width:36%;
position:relative;
left:76%;
overflow:hidden;
}​
DEMO
Source link