Okay, this is my 3rd question and hopefully the last one. I get some problems with my page layout that looked like this before:
[navbar]
[1][2][3]
I wanted to achieve this effect when resizing:
[navbar]
[2][3]
[1]
(1st div under the 3rd one)
However, when I use (in the main container that holds all the 3 divs) class container mt-3 I get this layout:
[navbar]
[1][2]
[3]
Now, when I change the margin-left of the 3rd div it doesn't go up to the top row but just moves to the left - something happens like it would be in another row class.
When I use parent-container container mt-3
[navbar]
[1][2] [3]
And they are really small and I can't change the width no matter what I do. I even tried changing the bootstrap's "container" class with both px and %.
container-fluid does the job a bit because all the divs are bigger (and on 100% width of the page) but I would want to have it just like 90%, but still, the [3] div is on the right side mile from the [2]. When I resize the window, the [2] div goes in this white space between [1] and [3] under the [3]. So it looks similar to this:
[navbar]
[2] [3]
[1]
CSS CODE:
.main{
background-color: red;
box-shadow: 3px 3px 20px #000000;
border-radius: 20px;
}
.left{
background-color: green;
max-width: 200px;
border-radius: 20px;
}
.right{
background-color: blue;
max-width: 200px;
border-radius: 20px;
}
.parent-container {
display: flex;
}
.right-content{
width: 100%;
text-align: center;
float: center;
margin-top: 10px;
}
HTML
<div class="parent-container container mt-3">
<div class="row">
<div class="left col-4 col-lg-3 order-last order-lg-first offset-8 offset-lg-0">
<div class="col-12 text-center" style="margin-bottom: 15px">
<h3>TITLE LEFT</h3>
</div>
</div>
<div class=" col-8 col-lg-6">
<div class="container card">
<div class="card-body">
<div class="row">
<div class="col-12 text-center">
<h2>TITLE CENTER</h2>
</div>
</div>
<div class="row">
<div class="col-12 text-center">
<h3>heading 3</h3>
<h6>heading 6</h6>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 mx-auto">
<a href="#" class="article-link">
<h3>Heading 3</h3>
<p>Text</p>
</a>
</div>
</div>
<hr>
</div>
</div>
<div class="right col-4 col-lg-3">
<div class="right-content">
<h2>TITLE RIGHT</h2>
</div>
</div>
</div>
You had improper nesting for the columns. Here's the right way to do it (all main columns must sit within the main row):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.left{
background-color: green;
max-width: 200px;
border-radius: 20px;
}
.right{
background-color: blue;
max-width: 200px;
border-radius: 20px;
}
</style>
<div class="parent-container container mt-3">
<div class="row">
<div class="left col-4 col-lg-3 order-last order-lg-first offset-8 offset-lg-0">
<h3>TITLE LEFT</h3>
</div>
<div class=" col-8 col-lg-6">
<div class="container2 card">
<div class="card-body">
<div class="row">
<div class="col-12 text-center">
<h2>TITLE CENTER</h2>
</div>
</div>
<div class="row">
<div class="col-12 text-center">
<h3>heading 3</h3>
<h6>heading 6</h6>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 mx-auto">
<a href="#" class="article-link">
<h3>Heading 3</h3>
<p>Text</p>
</a>
</div>
</div>
<hr>
</div>
<div class="right col-4 col-lg-3">
<div class="right-content">
<h2>TITLE RIGHT</h2>
</div>
</div>
</div>
</div>
Note: Right now the columns aren't stacking on the smallest screens. That's because they aren't specified to do so. To make them stack, the responsive column classes for the smallest screens (col-*) all need to be changed to col-12.
You'd also need to adjust the offset classes because right now the offset-8 class kicks in for all screens that are smaller than lg. The offset-8 class is what causes the offset of 8 units (on the left) on all screens that are smaller than lg.
Related
Looking under the hood of Bootstrap gutters led me to realize that the space between columns is added using padding, not a margin.
This is problematic because if you want to use Bootstrap 5's default flexbox to get your columns of equal height, you have to apply things like box shading or background to the column itself. This means that a gutter using padding gives you an awkward white gap within your column, rather than space between the columns.
Here's a fiddle that demonstrates my issue:
.red {
background-color: red;
color: white;
}
.blue {
background-color: blue;
color: white;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css">
<h2>
No Gutters
</h2>
<div class="container px-5">
<div class="row ">
<div class="col-6 red">
<p>Column content</p>
<p>is different</p>
<p>heights.</p>
</div>
<div class="col-6 blue">
<p>See? Shorter.</p>
</div>
</div>
</div>
<h2>
Gutters via Padding
</h2>
<div class="container px-5">
<div class="row gx-4">
<div class="col-6 red">
<p>Column content</p>
<p>is different</p>
<p>heights.</p>
</div>
<div class="col-6 blue">
<p>See? Shorter.</p>
</div>
</div>
</div>
<h2>
Gutters fine but BG Wonky
</h2>
<div class="container px-5">
<div class="row gx-4">
<div class="col-6">
<div class="red">
<p>Column content</p>
<p>is different</p>
<p>heights.</p>
</div>
</div>
<div class="col-6">
<div class="blue">
<p>See? Shorter.</p>
</div>
</div>
</div>
</div>
Is there any way to get space between columns that acts as a margin not padding? If you add a straight-up margin it pushes the whole grid layout out of whack.
Im wondering why do i have space between second text which is from first row and first text which is on second row? I find it annoying, why does it happen? Is there any way to fix it?
[IMG]http://i67.tinypic.com/2zhe0xg.jpg[/IMG]
This is how it looks on desktop:
[IMG]http://i65.tinypic.com/2eby5bs.png[/IMG]
HTML:
<div class="container-fluid">
<div class="row mt-5 mb-5 ml-3 mr-3">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4text">
<div class="b">
<p>Somethin ggoes here maybe</p>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Something goes here maybe</p>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-5 mb-5 ml-3 mr-3">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Somethin ggoes here maybe</p>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Something goes here maybe</p>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.row > .text > .b {
display: -webkit-box;
height: 70%;
line-height: 1.3;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
I tried multiple solutions but couldnt get it to work
There are some styles you should definitely include in future questions so we can diagnose conflicts. For future reference, include any styles for classes you have assigned.
As far as what I can tell just from your code and screenshots, though, I'd say setting margin: 0; on your 2 divs in a media query for the affected breakpoint would work, but I'd also like to add a suggestion that will be a bit less messy for you using flexbox.
/* Make your container a flexbox */
.container {
display: flex;
}
/* Give flex grow value of 1 to keep all inner containers equal size */
.article {
flex: 1;
margin: 5px;
}
/* Sizing the image */
.article>img {
max-width: 400px;
}
.article>h1 {
font-size: 12px;
}
/* You could also just set the flex-direction to column, but displaying as block at the breakpoint will achieve the layout you're looking for on mobile. 500px is a trivial guess, use inspector to find the sweet spot */
#media (max-width:500px) {
.container {
display: block;
}
}
<div class="container">
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
</div>
<div class="container">
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
</div>
You can read up a bit more on flexbox in this CSS-Tricks article as well. If you're confused on anything here, feel free to comment and I'll try and answer the best I can. I've composed a fiddle here too so you can see how it responds when resizing.
I am trying to make a responsive web-layout like :
Upon resizing I would want the skills to be next to one another underneath the intro:
The problem is mainly at the intro and skill boxes, I can't seem to get them to adjust the way I want: https://jsfiddle.net/aq9Laaew/20858/
HTML:
<div class="container">
<div class="row">
<div class="col text-center">HEAD</div>
</div>
<div class="row">
<div class="col">
INTRO
</div>
<div class="col p-0">
<div class="col m-0">SKILLS</div>
<div class="col m-0">SKILLS</div>
<div class="col m-0">SKILLS</div>
</div>
</div>
<div class="row">
<div class="col">
EDUCATION
</div>
<div class="col">
EXPERIENCE
</div>
</div>
<div class="row">
<div class="col">OTHER</div>
</div>
</div>
CSS:
.row {
background: #f8f9fa;
margin:10px;
}
.col {
border: solid 1px #6c757d;
margin: 10px;
}
.row, .col {
min-width: 120px;
}
They keep setting underneath each other which i only want when the screen is extra small. this is simple but i just cant figure it out...
I tried adding col-4 for intro (since intro should expand wider than skill) and messed with the columns more on the skill box to no luck..
There are a few issues that are preventing you from getting the desired layout:
cols must be the immediate child of a row ... the skills need to be wrapped in another row.
Use col-sm to allow columns to stack vertically on the smaller layout.
Don't adjust margins on the rows or cols as it will break the way the grid works.
Working demo: https://www.codeply.com/go/0g48AjUW4E
<div class="container">
<div class="row">
<div class="col p-0 text-center">HEAD</div>
</div>
<div class="row">
<div class="col-sm p-0">
INTRO
</div>
<div class="col-md-auto p-0">
<div class="row no-gutters">
<div class="col col-sm col-md-12">SKILLS</div>
<div class="col col-sm col-md-12">SKILLS</div>
<div class="col col-sm col-md-12">SKILLS</div>
</div>
</div>
</div>
<div class="row">
<div class="col p-0">
ED
</div>
<div class="col p-0">
EXPERIENCE
</div>
</div>
<div class="row">
<div class="col p-0">OTHER</div>
</div>
</div>
CSS:
.row {
background: #f8f9fa;
}
.col,.col-sm {
border: solid 1px #6c757d;
}
First, when you separate into multiple cols you should wrap them inside a row ( so you have display:flex )
Second, you need to add classes to your columns to set how you want them to appear on different screen sizes. Note that as of bootstrap4 col-xs does not exist. Use col simple instead and overwrite it on larger screens.
In the example below i have used:
col-lg-8 and col-12 on the INTRO section.
col-lg-4 and col-12 on the Skills column wrapper.
col-lg-12 and col-4 on the Skills columns.
Also added a row to wrap the Skills columns
See below or jsFIddle
.row {
background: #f8f9fa;
margin: 10px;
}
[class*="col-"] {
border: solid 1px #6c757d;
}
.row,
[class*="col-"] {
min-width: 120px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container">
<div class="row">
<div class="col text-center">HEAD</div>
</div>
<div class="row">
<div class="col-lg-8 col-12">
INTRO
</div>
<div class="col-lg-4 col-12 p-0">
<div class="row mx-0">
<div class="col-lg-12 col-4 m-0">SKILLS</div>
<div class="col-lg-12 col-4 m-0">SKILLS</div>
<div class="col-lg-12 col-4 m-0">SKILLS</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
EDUCATION
</div>
<div class="col">
EXPERIENCE
</div>
</div>
<div class="row">
<div class="col">OTHER</div>
</div>
</div>
You need to wrap skill boxes in a div and give it classes d-flex
flex-wrap
By doing this, you will get the result without giving negative margin
col-md-8 col-sm-12 classes in intro div will make it 100% for
smaller device
No need to make any css changes
.row {
background: #f8f9fa;
margin:10px;
}
.col {
border: solid 1px #6c757d;
margin: 10px;
}
.row, .col {
min-width: 120px;
}
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col text-center">HEAD</div>
</div>
<!-- Changes here -->
<div class="row">
<div class="col-md-8 col-sm-12">
INTRO
</div>
<div class="col p-0">
<div class="d-flex flex-wrap">
<div class="col-4 col-md-12 m-0">SKILLS</div>
<div class="col-4 col-md-12 m-0">SKILLS</div>
<div class="col-4 col-md-12 m-0">SKILLS</div>
</div>
</div>
</div>
<!-- Changes Ends here -->
<div class="row">
<div class="col">
EDUCATION
</div>
<div class="col">
EXPERIENCE
</div>
</div>
<div class="row">
<div class="col">OTHER</div>
</div>
</div>
I would use a media query for this.
https://www.w3schools.com/css/css3_mediaqueries.asp
That is, keep your layout how you want it now as it is, then in the media query, just rearrange the layout to what you want it become on screen re-size.
Bootstrap 4 - Safari Version 10.1.2 display:table; and display:table-cell; vertical-align:center; not working on a 100% height div.
<div class="test-slider">
<div class="slide">
<div class="row no-gutters">
<div class="col-12 col-xs-12 col-sm-12 col-md-7 col-lg-7">
<img src=""/>
</div>
<div class="col-12 col-xs-12 col-sm-12 col-md-5 col-lg-5">
<div style="display:table; height:100%;">
<div style="display:table-cell; vertical-align: middle;">
<h2>Test center</h2>
<p>Should be centered</p>
</div>
</div>
</div>
</div>
</div>
</div>
If I render in chrome the height is inherited from the .test-slider class that has a fixed height whilst in safari it takes the contents height rather than filling the height of the div. Any ideas? I am using slick slider.
Well, currently I have Safari 11.0.1, but if I set the below stlye, it does center the text vertically to me.
.test-slider .row {
height: 500px;
}
Setting the height only to .test-slider is not enough, since the children do not know that they should fill in that height. The 100% height set on the "table" is calculated from the height of it's parent, the .col-md-5 div. Which, in your case does not know about the height of the .test-slider.
Other than that, please note that col-12 col-xs-12 col-sm-12 col-md-7 col-lg-7 is totally equivalent to simply writing col-md-7. The same stands for col-md-5 of course.
Also, instead of using tables, I would recommend to use the flexbox utility classes already available in Bootstrap. That makes the markup lighter. This is an example:
.test-slider .row {
height: 300px;
}
.test {
background-color: lightgray;
}
<div class="test-slider">
<div class="slide">
<div class="row no-gutters">
<div class="col-md-7">
<img src=""/>
</div>
<div class="test col-md-5 d-flex align-items-center">
<div>
<h2 class="mb-0">Test center</h2>
<p class="mb-0">Should be centered</p>
</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
I have a responsive web layout based on bootstrap. I have Glyphs, titles and text. These are my two layouts:
[1A] [1B] [1C]
[2A] [2B] [2C]
[3A] [3B] [3C]
This is the layout for small screens.
[1A] [2A]
[3A]
[1B] [2B]
[3B]
[1C] [2C]
[3C]
This code makes the first layout, but how do I achieve the second responsively?
EDIT:
I have this:
From this code:
CSS:
.green-box {
background: #3DBEAF;
border: 5px solid #e7e7e7;
border-radius: 20px;
margin-top: 10%;
margin-bottom: 10%;
padding-top: 10px;
padding-bottom: 15px;
margin-left: 2.77778%
}
#media (max-width: 769px) {
.mob-hide{
display: none;
}
.green-box{
margin-left: 20px;
margin-right: 20px;
vertical-align: middle;
}
}
HTML:
<div class="container text-center">
<div class="col-xs-12 col-sm-3 green-box eqheight1">
<div class="glyphicon-ring"> <span class="glyphicon glyphicon-bullhorn glyphicon-bordered" /></div>
<div class="col-xs-9 col-sm-12">
<h3>Revolutionary</h3>
</div>
<div class="col-xs-9 col-sm-12">
<p class>Knowing when to change a gas bottle isn't always easy so many people buy a back-up or risk running out unexpectedly is a real pain - it might leave you cold or with hungry in-laws, either way it will spoil your day. Meet Gas-Sense!</p>
</div>
</div>
<div class="col-sm-1 margin mob-hide"></div>
<!-- Other two boxes -->
</div
How do I get the glyph on the left, and centered in the middle vertically of the title text block?
Just going off your diagram:
<div class="container">
<div class="col-sm-12 col-md-4">
<div class="col-sm-3 col-md-12">The X icon in the diagram</div>
<div class="col-sm-9 col-md-12">
The article text
</div>
</div>
</div>
You need group each icon, text and heading together, then add some classes for col-xs-*:
http://codepen.io/anon/pen/RreRrN
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="col-xs-3 col-sm-12">
<div class="glyphicon-ring"> <span class="glyphicon glyphicon-bullhorn"/></div>
</div>
<div class="col-xs-9 col-sm-12">
<h2>Title 1</h2>
<p>Text 1</p>
</div>
</div>
<div class="col-sm-4">
<div class="col-xs-3 col-sm-12">
<div class="glyphicon-ring"> <span class="glyphicon glyphicon-ok"/></div>
</div>
<div class="col-xs-9 col-sm-12">
<h2>Title 2</h2>
<p>Text 2</p>
</div>
</div>
<div class="col-sm-4">
<div class="col-xs-3 col-sm-12">
<div class="glyphicon-ring"> <span class="glyphicon glyphicon-phone"/></div>
</div>
<div class="col-xs-9 col-sm-12">
<h2>Title 3</h2>
<p>Text 3</p>
</div>
</div>
</div>
</div>