How to align vertically an element to the bottom within a bootstrap column? - html

I'm using twitter-bootstrap framework, and bootstrap touchspin plugin. And I want to align the touchspin at the bottom of an column .col-md-6 which has variable height.
I tried adding the following (like this solution):
.row {
position: relative;
}
.bootstrap-touchspin {
position: absolute;
bottom:0;
right:0;
}
But nothing changes. (see jsfiddle)
Why does it not work? Do you have another way to do it?
Here is a jsfiddle where you can try: http://jsfiddle.net/R5n9j/1/
ACTUAL OUTPUT
DESIRED OUTPUT
HTML
<div class="container">
<div class="row">
<div class="col-md-7">
<div id="form-guardar-medidas">
<ul class="nav nav-tabs">
<li class="active">Tab1
</li>
<li>Tab2
</li>
</ul>
<div id='content' class="tab-content">
<div class="tab-pane active fade in" id="tab1">
<div class="row">
<div class="col-md-6">
<img class="img-responsive" src="http://placehold.it/200x200">
</div>
<div class="col-md-6">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam blandit mattis pretium. Interdum et malesuada fames ac ante ipsum primis in faucibus.</p>
<input id="input-cm" type="text" class="input-lg" name="input-cm">
</div>
</div>
</div>
<div class="tab-pane fade" id="tab2">Hello tab2</div>
</div>
</div>
</div>
</div>
</div>
CSS
body{
padding: 20px;
}
.tab-content {
border: 1px solid #ccc;
padding: 15px;
}
JS
$(document).ready(function () {
$("input[name='input-cm']").TouchSpin();
$('.nav-tabs a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
});

By switching to CSS table layout, you can have columns of same height for free, with the constraint of not being able to relatively position "(visual) cells" (in Firefox, at least) so you must do that on the '(visual) table"
EDIT2: .bootstrap-touchspin is also displayed as table and that fails in Chrome. Adding a div around this component that'll be absolutely positioned (and not the component itself anymore) solves this problem.
Demo: http://jsfiddle.net/R5n9j/9/
Compatibility is IE8+ (because of / thanks to display: table and table-cell)
HTML
<div class="table pos-reference">
<div class="cell">
<img class="img-responsive" src="http://placehold.it/200x200">
</div>
<div class="cell has-touchspin">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam blandit mattis pretium. Interdum et malesuada fames ac ante ipsum primis in faucibus.</p>
<div class="pos-abs">
<input id="input-cm" type="text" class="input-lg" name="input-cm">
</div>
</div>
</div>
CSS
.table {
display: table;
table-layout: fixed;
}
.pos-reference {
position: relative;
}
.cell {
display: table-cell;
vertical-align: top;
}
.has-touchspin {
height: 100%;
padding-bottom: 50px; /* Avoids superposition of content and absolutely positioned touchspin */
}
.pos-abs {
position: absolute;
bottom: 0;
border: 1px solid #F00;
}
EDIT: Explanation about why your attempt at positioning the .input-group failed: TWBS .col-AZ-NN are already relatively positioned so the closest ancestor to .input-group being positioned isn't the one you set but .col-md-6. See Firebug screenshot below. Otherwise, your attempt was a good one ;)

The easiest way is to use flex:
.tab-pane .row{
display:flex;
}
If you notice the height of the two col-md-6 containers inside the tabs, they are not equal, flex when used applies equal height to its child containers.
DEMO
Limitation:
The Safari browser does not support the flex property.

My solution is:
I've added col1 and col2 ids to each columns, and with js I set the same height.
col1h = $("#col1").height();
col2h = $("#col2").height();
if (col1h > col2h) {
def_height = col1h;
} else {
def_height = col2h;
}
$("#col1,#col2").height(def_height);
And adding left: 15px; to .bootstrap-touchspin.
The result http://jsfiddle.net/R5n9j/16/embedded/result

Related

Not the right method for css?

im trying to reproduce this piece of website:
here's mine now and im gonna explain why im struggling
Im struggling with the way to do it, i can move the description close to the logo playing with margin but when i move the size of my screen everything gonna be messed up and i feel like its not the right move to do. Im trying to use flex-boxe but i feel like i messed up the whole part and i should restart again i show you the big picture now:
And here's the whole code for all that part
<div class="container-services_display">
<img src="images/main-feature.png">
<div class="circle">
<div class="icon_placement">
<i class="material-icons">android</i>
</div>
<div class="icon_placement2 ball_design">
<i class="fas fa-circle"></i>
</div>
</div>
<div class="description-services_right">
<h2> UX design </h2>
<p>Coucou les amis je suis entrain de faire un site chiant</p>
<p>Coucou les amis je suis entrain de faire un site chiant</p>
</div>
</div>
css:
.container-services_display
{
margin-top: 110px;
display: flex;
justify-content: space-around;
}
.ball_display
{
display: flex;
justify-content: center;
}
.ball_design
{
color: rgb(82, 162, 201);
font-size: 14px;
}
.circle
{
width: 75px;
height: 75px;
background-color: white;
border-radius: 75px;
border: 1px solid rgb(237, 238, 239, 1);
border-opacity: 0.5;
}
.icon_placement
{
position: relative;
left: 24px;
top: 22px;
color: rgb(96, 174, 209);
}
.icon_placement2
{
position: relative;
left: 68px;
}
So basically its wrapper on a container, im trying to display it on the horizontal with flex and they space it but i feel like i miss a part of this, what i would do is making another div for the logo + description and displaying again with flex but it seemed like its not working, i just need some hint and sorry i only got less than 20 hours of css =D
since you are using css flex then you need to add flex: 1 and little margin if you want it for spacing
.description-services_right {
flex: 1;
margin-left: 20px;
}
see the fiddle
here is bootstrap version if you want to go with bootstrap
.side-pic{
max-width: 100%;
width: 100px;
height: auto;
}
.mtop{
margin-top: 20px;
}
.side-pic-holder{
text-align: center;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-2 side-pic-holder">
<img class="side-pic" src="http://random-ize.com/lorem-ipsum-generators/lorem-ipsum/lorem-ipsum.jpg" />
</div>
<div class="col-md-10">
<h4>some title</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet</p>
</div>
</div>
<div class="row mtop">
<div class="col-md-10">
<h4>some title</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet</p>
</div>
<div class="col-md-2 side-pic-holder">
<img class="side-pic" src="http://random-ize.com/lorem-ipsum-generators/lorem-ipsum/lorem-ipsum.jpg" />
</div>
</div>
</div>
make sure you view it as full screen
Media Query
In Order to have a clean and responsive Website you will need to use some Media Queries. If your are new to Media Query, check it out here.
In the Media Query you can define your CSS Classes and stylings like
usually, the only difference is it will be only applied if the
condition is true. For Example: If the screen-width is less than 768px
#media(max-width: 768px){
.description-services_right{
width: 100%;
}
}
Bootstrap
There is an other Way, probably the easier and quicker one, using Bootstrap 3/4, if your never heard of Bootstrap you can read their Doc here.
Bootstrap lets you create Quickly Responsive Websites just by adding
premade classes to your HTML Elements.
Bootstrap biggest Advantage is its Grid System, before i get into too much explanations you should check it out if you are interested.
I created two Pens where i made your Code Responsive, i kept all the HTML Elements but deleted all unnecessary CSS.
You can even compare the Bootstrap and Non-Bootstrap Version i made to see how much Coding you can avoid.
Pen without Bootstrap
Pen with bootstrap
And here a Demo how Bootstraps Grid System works

HTML/CSS Text flows outside div trough floating divs

PURPOSE
Having an editable div in which the text flows in different "simulated" pages, so to obtain an effect like Word. At the moment, I'm interested to have this working in Chrome (no crossbrowser compatibility).
WHAT I'VE DONE
I've created an editable div (pagina) already filled with some text. Inside this div there are 2 divs: block1 and block2.Block1 is a floating right div that simulates the page height.Block2 is a floating left div that simulate the space between pages.The effect I've obtained is a long text "broken" into pages. In my code I've used different background colors to have a better view of the various divs.
THE PROBLEM
When I move the cursor at the beginning of a new "page" and I press [return] more times, the new lines are moved at the right side of the above block2 div (the pages sepatator). If I type something, single letters appears in the right side (see screenshot below).
Problem screenshot
In this Fiddle (http://jsfiddle.net/n4d2jtd9/4/) you can see my experiments result.
.pagina {
width: 200px;
background-color: #AAA;
}
div.block1 {
float: right;
width: 100px;
height: 100px;
background-color: #CCC;
}
div.block2 {
float: left;
width: 200px;
height: 100px;
background-color: #FFF;
}
<body>
<div class="pagina">
<div class="block1"></div>
<div class="block2"></div>
<div class="block1"></div>
<div class="block2"></div>
<div contenteditable="true" style="width:90px;background-color:#DDD;word-break:break-all;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero mi, tempus in tincidunt vitae, aliquet nec nibh. Integer egestas leo vel orci
</div>
</div>
</body>
THE QUESTION
Is there a way to prevent that text effect?
CONSIDERATIONS
When you press [enter] inside an editable div, Chrome adds a div tag per paragraph (and a br tag when you press [enter]+[shift]).
The created "empty" div is always <div><br></div>. Having a zero width, the floating div moves this tag to right. I've noticed that if I put a space char inside the div, it works properly. Maybe jQuery can help.
New Code: based on browsers:
working demo: http://jsfiddle.net/n4d2jtd9/9/
HTML
<body>
<div class="pagina">
<div class="block1"></div>
<div class="block2"></div>
<div class="block1"></div>
<div class="block2"></div>
<div id="editable" contenteditable="true" style="width:90px;background-color:#DDD;word-break:break-all;
">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero mi, tempus in tincidunt vitae, aliquet nec nibh. Integer egestas leo vel orci
</div>
</div>
</body>
CSS
#editable{white-space:normal}
}
/* Chrome 29+ */
#media screen and (-webkit-min-device-pixel-ratio:0)
and (min-resolution:.001dpcm) {
#editable{white-space:pre-line;}
}
/* Chrome 22-28 */
#media screen and(-webkit-min-device-pixel-ratio:0) {
.selector {-chrome-:only(;
#editable{white-space:pre-line;}
);}
}

How can I do a module like this? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to do a boxes like below for my website's events but I got stuck.
The problems I can not solve:
Reduce images to the same size
Create modules of the same size
Align the modules in the same line
.background {
width:360px;
height:200px;
}
.image{
width:100%;
height:100%;
}
.text {
width:100%;
height:25%;
color:#ffffff;
background:blue;
z-index: auto;
}
<div class="background">
<div class="image">
<img src="https://zero.eu/content/uploads/2017/01/Ryley_Walker-730x490.jpg" width="360" height="200" class="wp-image-156 hoverZoomLink" alt="Willie Peyote Live">
</div>
<div class="text">
<p>test test test</p>
</div>
</div>
Questions... and answers. Let's go over the issues you have one by one.
Reduce images to the same size
It's best to let CSS take care of this. By setting the background of an element to the image you want and setting the background-size to cover, the browser will scale the image such that the aspect ratio is maintained and the image nicely covers all of the element you put it in.
Now make all elements the same size and voilĂ , this point is done.
Create modules of the same size
This can be achieved in two ways.
Set fixed sizes on your boxes.
Use more advanced CSS, in particular the flexbox layout module.
To keep things simple, I'll use the first approach for now. Read up on flex if you are interested in it!
Align the modules in the same line
This can be achieved in many ways, but the most straightforward one is setting display to inline-block. This will make it so that every block in your module is treated as a, well, a block, meaning that it can have a set width and height. At the same time, it is laid out as if it were text. So, one block after another will simply go on the same line. When that does not fit on screen anymore, blocks will flow to the next line.
Putting this all together. Here is a quick toy example that includes all of the above. It should serve as a good starting point to build from.
.card {
display: inline-block;
vertical-align: top;
width: 150px;
height: 270px;
margin: 10px;
padding: 0;
border: 1px solid #444;
border-radius: 5px;
}
.image {
/* width is 100%, so 150px, by default */
height: 150px;
background-size: cover;
}
.text {
height: 150px;
margin-top: -40px;
}
.text > p {
max-height: 90px;
overflow: hidden;
text-overflow: ellipsis;
}
h1 {
margin: 0;
padding: 10px;
background: rgba(0, 0, 0, 0.7);
color: #eee;
font-size: 20px;
line-height: 20px;
}
p {
margin: 0;
padding: 10px;
font-size: 15px;
line-height: 20px;
}
<div class="card">
<div class="image"
style="background-image: url('http://lorempixel.com/150/150/abstract/');"></div>
<div class="text">
<h1>Foo</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec faucibus auctor odio, sed lobortis odio pellentesque tincidunt. Curabitur et libero maximus, consequat mi non, dignissim turpis.</p>
</div>
</div>
<div class="card">
<div class="image"
style="background-image: url('http://lorempixel.com/150/150/city/');"></div>
<div class="text">
<h1>Bar</h1>
<p>Sed ac lacus vel mi mollis ullamcorper quis ac sapien. Ut quis ornare ligula. Nullam a sapien eget arcu mattis aliquam. Quisque dapibus leo vel lacus rutrum sollicitudin.</p>
</div>
</div>
<div class="card">
<div class="image"
style="background-image: url('http://lorempixel.com/150/150/cats/');"></div>
<div class="text">
<h1>Baz</h1>
<p>Nullam eu urna dictum, gravida augue nec, dignissim enim. Duis sit amet elit quis mauris consectetur rhoncus et a ipsum. Fusce vel sagittis nulla, et imperdiet quam.</p>
</div>
</div>
You need to change your HTML and CSS to make it work properly.
<div class="background">
<div class="image" style="background-image: url('https://zero.eu/content/uploads/2017/01/Ryley_Walker-730x490.jpg');">
</div>
<div class="text">
<p>test test test</p>
</div>
</div>
then your CSS should look like this:
.background {
width: 360px;
height: 200px;
position: relative;
}
.image {
background-size: cover; /* that will keep the image in original ratio */
background-position: center center;
height: inherit;
}
.text {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 25%;
}
That will make an image to fully cover the background space and then the .text will be an overlay on the image. Actually, you could even skip the .image div, add background and the CSS to the .background div and it will work as well.
The example you provided features something different than your code is suggesting. If you want to achieve the look from example, then:
.background {
width: 360px;
height: 200px;
position: relative;
background: #fff;
}
.image {
background-size: cover; /* that will keep the image in original ratio */
background-position: center center;
position: relative;
}
.image:before {
content: "";
display: block;
padding-top: 60%; /* that will make a fixed ratio of you image box, even if you'll scale the background boc /*
}
.text {
/* actually it doesn't need styling in that case */
}
.background's parent {
display: flex; /* to make the blocks even in height without setting that as a fixed value */
}
Your code and the example you provided are doing different things. In order to get the effect of your example, you need more than one "card" (image and text together).
You can use display: flex on the .background div so that all the cards are the same height. Then you can add some margin to the cards so they are separated a little.
.background {
display: flex;
background: cyan;
}
.card {
width: 360px;
background: white;
margin: 10px;
}
.text {
padding: 0 5px;
}
.text p {
width:100%;
overflow: hidden;
}
<div class="background">
<div class="card">
<img src="https://zero.eu/content/uploads/2017/01/Ryley_Walker-730x490.jpg" width="360" height="200" class="wp-image-156 hoverZoomLink" alt="Willie Peyote Live"/>
<div class="text">
<p>test test test</p>
</div>
</div>
<div class="card">
<img src="https://zero.eu/content/uploads/2017/01/Ryley_Walker-730x490.jpg" width="360" height="200" class="wp-image-156 hoverZoomLink" alt="Willie Peyote Live"/>
<div class="text">
<p>another test</p>
</div>
</div>
<div class="card">
<img src="https://zero.eu/content/uploads/2017/01/Ryley_Walker-730x490.jpg" width="360" height="200" class="wp-image-156 hoverZoomLink" alt="Willie Peyote Live"/>
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque hendrerit, massa sed tristique lacinia, mauris lectus ultricies ipsum, vitae lobortis lectus arcu quis nisl. Etiam pulvinar porttitor mi, at aliquet quam mattis non.</p>
</div>
</div>
</div>

Using <p> with left floating divs causes second div to go below first div

https://jsfiddle.net/9nh220q2/1/
Basically, I have something like this:
<div class="container">
<div class="left">
<img src="http://i.imgur.com/bWQUX0O.jpg" class="image" />
<span>0.3 mi</span>
</div>
<div class="right">
<h3>TITLE HERE</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec turpis eu mi nullam sodales.</p>
</div>
</div>
However, these items are inside of a scrolling panel. So, in the jsFiddle I have put these inside of a parent div with width of 600px. As you can see, the <div class="right"> is going below. How can I stop it from doing that?
Calculated width of .right
.right {
width: calc(100% - 120px);
}
.container {
background-color: #fff;
padding: 20px 20px 10px 20px;
overflow: hidden;
border-bottom: 1px solid lightgray;
margin: 0;
}
.left {
width: 100px;
float: left;
margin: 0;
text-align: center;
}
.image {
height: 100px;
width: 100px;
border-radius: 4px;
margin-bottom: 5px;
}
.right {
float: left;
padding-left: 20px;
width: calc(100% - 100px - 20px); /* all width - size of image - padding) */
}
h3 {
margin: 0;
}
<div style="width: 600px">
<div class="container">
<div class="left">
<img src="http://i.imgur.com/bWQUX0O.jpg" class="image" />
<span>0.3 mi</span>
</div>
<div class="right">
<h3>TITLE HERE</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec turpis eu mi nullam sodales.</p>
</div>
</div>
<div class="container">
<div class="left">
<img src="http://i.imgur.com/bWQUX0O.jpg" class="image" />
<span>0.3 mi</span>
</div>
<div class="right">
<h3>TITLE HERE</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec turpis eu mi nullam sodales.</p>
</div>
</div>
<div class="container">
<div class="left">
<img src="http://i.imgur.com/bWQUX0O.jpg" class="image" />
<span>0.3 mi</span>
</div>
<div class="right">
<h3>TITLE HERE</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec turpis eu mi nullam sodales.</p>
</div>
</div>
</div>
You can fix this by removing all float and using flexbox. Flexbox is a powerful modern way to handle this kind of layout. flexboxfroggy is a great way to learn about them.
.container {
display: flex;
justify-content:space-between;
}
Demo
An even better way would be to use standard css grid, but we should wait a bit more.
Edit:
All modern browser support flexbox. For old one, you can use a polyfill if you have to.
You need to set the width of .right to a maximum of 440px. See the working fiddle.
Explanation:
Your container div has a width of 600px. For the elements contained within to line up properly, their widths must add up to a maximum of 600px.
Your img already takes up 100px of that. That means that your div.right can have a maximum width of 500px. (Because 600px - 100px = 500px)
However, if you do set it at 500px, you'll most likely notice that the issue won't be solved. This happens because, by default, most (if not all) browsers render the page using the content-box model which includes the padding and margins of the elements when calculating their widths.
In your case, your containing div has 20px of padding in both sides. In addition, your div.right has 20px of padding on the left. This adds up to 60px which you need to subtract from your available space that we calculated above, 500px. That leaves you with 440px and if you set that as the width of div.right, you'll notice that the elements line up perfectly!
You can also change the default way in which the browser sees the box model by changing the value of box-sizing from content-box to border-box (neither padding nor margins are not calculated in width) or to padding-box (padding is not calculated in width) and then adjust padding, border or width values accordingly.

How do I keep floated elements flopping down without using a fixed width?

I am styling a series of form rows. Each row div has a fixed-width label div, and a content div that can contain any number of float: left elements.
Example markup is:
<div class="Row">
<div class="Label">Label Here</div>
<div class="Content">
<div class="Item">Short Content</div>
</div>
</div>
<div class="Row">
<div class="Label">Label Here</div>
<div class="Content">
<div class="Item">
Long Content ... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris id eros magna. Suspendisse eu diam nunc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eu neque massa.
</div>
</div>
</div>
CSS so far is:
.Row {
clear: left;
padding: 10px;
}
.Label {
float: left;
width: 150px;
}
.Content {
float: left;
}
.Content .Item {
float: left;
}
jsfiddle here: http://jsfiddle.net/vVy5J/2/
This looks correct as long as the contents of the content div are not wider than the remaining width in the row. If they are, the content div 'flops' down beneath the label instead and hugs the left edge of the row div: http://screencast.com/t/Iknv98R9
I need long content divs to wrap, but still be against the top of the row and flush with the right edge of the label.
The traditional solution for this is to give the content div a fixed width. But that won't fly here because the row widths vary based on browser window size, etc. and the content div needs to stretch from the right edge of the label div to the right edge of the containing row div.
Requirements: I can alter the markup only within the row div. Contents need to be elements, so text-indent won't work for me. I need to support IE7+
You could put a position:relative; on the Row, position:absolute; on the Label just to take it out of the document flow, then margin-left:150px on the Content (or however wide it's supposed to be).
It won't be good though if there's any chance of the Label being taller than the Content.
You can use simple positioning trick. #row must be relative and content is absolute with left: 150px.
.Row
{
...
position: relative;
}
.Content
{
...
position: absolute;
left: 150px;
}
jsfiddle