I'm working with bootstrap 4. I have one row with 3 columns. However, I currently have the center column set to col-7, but I need it to be a flexible column that takes up all of the remaining horizontal space in the row. I have tried flex-col, but it just seems to break everything. If you look at the jsfiddle, you'll see that the right arrow column isn't all the way at the end, which is where I'd like it to be. I also plan on adding a 4th column between the right arrow and the lore ipsum quote. When the viewport size changes to a smaller resolution, all of the elements and content should still be visible. I've found solutions where this is not the case, but that doesn't work for me. Users need to be able to click on the arrows regardless of the screen size. Any insight into this for those of you with bootstrap XP?
https://jsfiddle.net/fce1ojsp/
Code sample required when linking to jsfiddle:
<div class="container touchpointContainer">
<div class="row tall">
<div class="col-1 centerVertically">
<a onclick="advanceReview(-1)">
<img class="prev" src="leftArrow.png"/>
</a>
</div>
<div class="col-7 centerVertically mainText">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore"
</div>
<div class="col-1 centerVertically">
<a onclick="advanceReview(1)">
<img class="next" src="rightArrow.png"/>
</a>
</div>
</div>
</div>
You can use flexbox for that. The key is flex grow 1 on the center element.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex flex-row">
<div class="p-2 border">Flex item 1</div>
<div class="p-2 border flex-grow-1">Flex item 2</div>
<div class="p-2 border">Flex item 3</div>
</div>
Related
I am super new to coding and web development and I am not sure how to solve my issue:
I am trying to add an image to the column that I created using bootstrap 4 grid system. However, as soon as I add the image, a horizontal scrollbar appears on the screen and I'm not sure why.
Here is a screenshot of what happens: https://gyazo.com/c383ecb9180181349363e0636047867c
<div class="container">
<div class="row">
<div class="col-6">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
<div class="col-6">
<img src="https://images.unsplash.com/photo-1585600270404-543d0eac85e1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3042&q=80">
</div>
</div>
My second issue is that although the horizontal scrollbar gets removed when I use the "img-fluid" class for my image, however when I change the container to container-fluid so that it covers the entire width of the screen and then use the class "px-0" for my container to remove the extra padding, I once again get horizontal scrollbars appearing on my screen.
<div class="container-fluid px-0">
<div class="row">
<div class="col-6">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
<div class="col-6">
<img class="img-fluid" src="https://images.unsplash.com/photo-1585600270404-543d0eac85e1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3042&q=80">
</div>
</div>
The root cause of the problem is due to no restriction on 'width' being applied to the image.
The image is very big and hence, it is causing the horizontal scroll bar to appear.
Bootstrap provides a class called 'img-fluid' to resolve this common issue.
The horizontal scroll bar can be avoided by specifying the image class of 'img-fluid', as shown below.
The second problem with the use of container-fluid px-0 can be fixed by specifying the px-lg-5 class instead of px-0.
(px-lg-5 works well for wide sections / outer-most divs)
Working example with 'img-fluid' and container-fluid px-lg-5 classes:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<title>Bootstrap - responsive image</title>
</head>
<body>
<div class="container-fluid px-lg-5">
<div class="row">
<div class="col-6">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
<div class="col-6">
<img class="img-fluid"
src="https://images.unsplash.com/photo-1585600270404-543d0eac85e1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3042&q=80">
</div>
</div>
</body>
</html>
Output:
More information:
https://getbootstrap.com/docs/4.0/content/images/
Either you can set overflow : hidden to the second column container if you want your page to not scroll, or you can set height and width of the image to avoid scrolling and to make the whole image visible.
<div class="col-6">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
<div class="col-6" style="overflow: hidden">
<img height="100px" width="100px" src="https://images.unsplash.com/photo-1585600270404-543d0eac85e1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3042&q=80" />
</div>
Learn more about overflow property at https://www.w3schools.com/css/css_overflow.asp and image attributes at https://www.w3schools.com/html/html_images.asp
To solve your second problem, just add the margin:0 to the <div class="row">
What I want to achieve is to make the the columns with number 1 and 2 independent from the height size of the column with text, so if added later on another div it will be directly placed under the first 2 columns without skipping any empty gaps because of the third column long height,
like this:
Columns with gap
Columns without gap
I tried this but it didn't work.
<div class="row text-center ">
<div class="col-9 ">
<div class="row border">
<div class="col-9 border">1</div>
<div class="col-3 border">2</div>
</div>
</div>
<div class="col-3 border">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit
</div>
</div>
Thanks for any help.
I think you can use align-items Property in CSS Flexbox Layout!!
Using Twitter-Bootstrap, I have a section of a page that includes a sidebar (which does not take up the whole page, just spans down to the bottom of this section). I have several sections to the right of the sidebar, each of which contain an image on one side, some text on the other, and require a bottom-border.
I'm having trouble with the bottom-border. Since each section is contained in a div, and everything's floated using Bootstrap columns, the divs are 0 height and the borders all float to the top.
EDITED for clarification: I need two distinct columns in this section - a left-hand one (spanning 3 columns) that contains only the sidebar (and takes up the 3 columns all the way to the bottom, leaving blank space after the list), and one (spanning the remaining 9 columns) that contains the story-sections but that stays on the right-hand side of the page.
EDITED to include image (grey lines are included for reference and will not show up on the page, black lines are the borders I'm trying to apply)
Attempted solutions:
Bottom-border on individual elements: I need one solid line across the bottom of each section, so I can't apply bottom-border to both the image and the text.
Clearfix: Since I have this sidebar, I can't use a clearfix, because it pushes everything down past the sidebar.
Overflow: Using overflow causes the images to shrink (which I don't quite understand, but it doesn't help with the border either).
How can I create bottom borders for each of these sections?
<section class="stories">
<div class="container">
<h2>Section header</h2>
<div class="col-sm-3 sidebar">
<h6>list of stories</h6>
<ul>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
</ul>
</div>
<section class="story-section">
<div class="col-sm-3">
<img src="http://placehold.it/330x220">
</div>
<div class="col-sm-6">
<h6>keyword</h6>
<h3>Header of section</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eleifend dictum neque sed laoreet ...</p>
</div>
</section>
// (there are three more sections with the same class of "story-sections", plus other code on the page, but I've tried to simplify it as much as possible here.)
</div>
</section>
css:
html, body {
height: 100vh;
}
.stories {
.sidebar {
height: 100vh;
}
.story-section {
border-bottom: 1px solid $grey;
}
}
I'm still fairly new with Bootstrap, so there may be a very simple solution, but I haven't been able to track it down. Any help is very welcome!
if you want to have a sidebar with 3 columns + a left section with the remaining 9 columns, then you need to set col-*-9 in your story-section
Note: in bootstrap, you need to have .row right below .container or between nested col-*
html,
body {
height: 100vh;
}
.sidebar {
height: 100vh;
background: lightblue
}
.story-section {
border-bottom: 1px solid grey;
}
img {
margin-top: 10px
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<section class="stories">
<div class="container">
<div class="row">
<h2>Section header</h2>
<div class="col-xs-3 col-sm-3 sidebar">
<h6>list of stories</h6>
<ul>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
<li>list-item</li>
</ul>
</div>
<section class="story-section col-xs-9 col-sm-9">
<div class="row">
<div class="col-xs-6 col-sm-6">
<img class="img-responsive" src="http://placehold.it/330x220">
</div>
<div class="col-xs-6 col-sm-6">
<h6>keyword</h6>
<h3>Header of section</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eleifend dictum neque sed laoreet ...</p>
</div>
</div>
</section>
<section class="story-section col-xs-9 col-sm-9">
<div class="row">
<div class="col-xs-6 col-sm-6">
<img class="img-responsive" src="http://placehold.it/330x220">
</div>
<div class="col-xs-6 col-sm-6">
<h6>keyword</h6>
<h3>Header of section</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eleifend dictum neque sed laoreet ...</p>
</div>
</div>
</section>
</div>
</div>
</section>
Right now I have two divs using "one-half columns" class.
As you can see here, the bottom card on the left side is still aligned with the one on the bottom right.
I want Pinterest kind of style like this, but I do not know how because they are in different rows.
here is my html code.
<div class="container">
<div class="row">
<div id="cards" class="one-half column" style="margin-top: 25%">
<img class="card-image" src="img/sample.png">
<div class="title">
<h4>Stealth Rats</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus suscipit eu nibh vitae maximus.</p>
</div>
</div>
<div id="cards" class="one-half column" style="margin-top: 25%">
<img class="card-image" src="img/sample.png">
<div class="title">
<h4>Basic Page</h4>
<p>This index.html page is a placeholder with the CSS, font and favicon. It's just waiting for you to add some content! If you need some help hit up the Skeleton documentation.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus suscipit eu nibh vitae maximus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc a mollis arcu.</p>
</div>
</div>
</div>
<div class="row">
<div id="cards" class="one-half column" style="margin-top: 5%">
<img class="card-image" src="img/sample.png">
<h4>Basic Page</h4>
<p>This index.html page is a placeholder with the CSS, font and favicon. It's just waiting for you to add some content! If you need some help hit up the Skeleton documentation.</p>
</div>
<div id="cards" class="one-half column" style="margin-top: 5%">
<img class="card-image" src="img/sample.png">
<h4>Basic Page</h4>
<p>This index.html page is a placeholder with the CSS, font and favicon. It's just waiting for you to add some content! If you need some help hit up the Skeleton documentation.</p>
</div>
Thanks in advance!
You can't do it in plain css unless you work with columns instead of rows (and that breaks content importance).
What you want is Masonry or another javascript alternative.
Also, your html has errors, you cannot use the same id more than once. Change it to class='cards' and if you want to use masonry you have to put every card inside the same div, so in this case, inside the same row.
Then you can call it
$('.row').masonry({
itemSelector: '.cards',
columnWidth: 200 //this is an example.
});
Since masonry is responsive, you can forget about skeleton for this part.
I'm trying to get an image to stick to the bottom of one div AND overlap the div above it.
fiddle is here: http://jsfiddle.net/5U34m/1/
There are 2 divs side by side the image in the right side
- if the content of the left is shorter than the right, the image should overlap the row above it
- if the content of the left is longer than the height of the image then the image should stick to the bottom of the right div.
- the image should also be centered in the div
here is the HTML:
<div class="container clearfix">
<div class="wrap header">
<div class="grid_6 logo">
<img src="http://cba.thelibertylab.com/wp-content/uploads/cba-logo-placeholder.png" />
</div>
<div class="grid_6 phone">
<!-- <p>p. 905-579-5302</p> -->
</div>
</div>
<div class="wrap upper-content">
<div class="grid_6">
<p>Nunc id porttitor lectus, et auctor ante. Morbi ullamcorper quam in leo auctor tempor. </p>
<p> Morbi a enim nibh. Vestibulum molestie augue libero, vitae fringilla massa eleifend quis. </p>
</div>
<div class="grid_6 headshot"><div class="img-container"><img src="http://www.manncontractors.com.au/media/pics/site/imagecache/1/1/1176381DF49D6256D968FFB72490208C.jpg" height="400" width="300"/></div></div>
</div>
<div class="wrap lower-content">
<div class="grid_6">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</div>
<div class="grid_6">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</div>
</div>
</div>
The CSS on the fiddle does not work correctly - I'm not sure what to try from here.
Your problem is multiple-fold.
You actually want the text to push down the image when it is longer, so your image should be UNDER your text in the HTML, not adjacent to it. Your structure should be like this:
<div> <!-- First row contains the text -->
<div class="grid_6 txt>YOUR TEXT</div>
<div class="grid_6></div>
</div>
<div class="grid_12"></div><!-- This one to prevent the float from stacking -->
<div> <!-- Second row contains the image and has height = 0 -->
<div class="grid_6></div>
<div class="grid_6 headshot">
<div class="img-container">
<img src="yourimg.jpg">
</div>
</div>
</div>
The CSS
First of all clear the styling height:100%; from .container. This styling rule inhibits the element from expanding and makes it impossible for children to inherit height. (Check for yourself in the console)
If you want the image to truly stick to the bottom, you will have to set .grid6.headshot { line-height: 0; } The line-height property actually inserts unwanted space in elements where you don't want it.
Replace .img-container property top: 70px; with margin-top: -450px; (your image height)
Set a min-height on the grid_6 div which has text in it, equal to your image height (450px) - your header height (94px) + some padding (10px) => 346px; If you don't do this your image will overlap your navigation
For #media only screen and (max-width: 767px), set .img-container { margin-top: 0; } else the image will overlap the text on mobile.
I've updated your fiddle here: http://jsfiddle.net/5U34m/4/
Note:
Consider using id's to target specific divs. The classes here are quite a mess.
Consider using responsive CSS frameworks (% and ems) instead of fixed-width ones.
You'll need to use position: absolute for the styling of your image. Then use the Left, Right, Top, Bottom attributes to position it as you like.
To adjust what element goes on top of each other, use the z-index attribute!