Vertical line div disappears if containing element is auto sized - html

I'm using bootstrap, with the following html:
<div class="container-fluid h-100">
<div class="row align-items-center h-100">
<div class="col-md" align="center">
<h2>Login</h2>
<form>
<table>
<tbody>
</tbody>
</table>
<button type="submit">Login</button>
</form>
</div>
<div class="col-md-auto h-100 d-none d-md-flex">
<div class="vertical_divider"></div>
</div>
<div class="col-md" align="center">
<div class="signup_button"><p>Signup</p></div>
</div>
</div>
</div>
With the following relevant css:
.page_content {
border: 3px solid orange;
border-radius: 20px;
padding: 30px;
height: 75vh; #Changing this to 'auto' makes the vertical divider disappear
max-height: 75vh;
overflow-y: scroll;
}
.vertical_divider {
position: relative;
height: 100%;
width: 0;
border: none;
border-right: 3px solid $bordercolour;
}
Fiddle: https://jsfiddle.net/aq9Laaew/176561/
This makes a div that is always 75% of the viewport height, regardless of its content. This works perfectly.
I want to modify it so that the div is only as big as its contents, up to a maximum of 75vh. If the content is bigger than that, the overflow should scroll within the div. I've done this by changing the height attribute of the page_content class to auto. This works, except that it makes the central orange line disappear (this happens in the fiddle too, if you change the setting).
Why does this happen? h-100 should make the column containing the vertical divider 100% of the row, and yet it doesn't. I've tried making various styles !important, but that didn't make any difference.

Why does this happen?
Because a percentage height only works when the parent element has a set height, with the exception of the html tag. When you set .page_content height to auto, there is no longer a set height on the parent element of the divider, and thus a percentage height does nothing.
To make it work you either need to ensure that the parent element chain all the way until html has a set height (i.e. not auto). Or as an alternative solution, if your middle column has no other purpose than the divider line, the whole column is kind of pointless since you can just create the line as a CSS border of one of the two other columns.

Related

Bootstrap first container override second container

I created a simple webpage with bootstrap that include two containers :
First container :
A white column taking 7/12 of the first row
A black column taking 5/12 of the second row
Second container (under the first one)
A grey page
The first container takes all the page and if you scroll down to the second container, it also takes all the page height
HTML :
<div class="container-fluid h-100 nopadding">
<div class="row h-100 nopadding">
<div class="col-md-7 left nopadding">
left
</div>
<div class="col-md-5 right nopadding">
right
</div>
</div>
</div>
<div class="container-fluid h-100 padding">
<div class="row h-100">
<div class="col details nopadding">details</div>
</div>
</div>
CSS :
html,
body {
height: 100%;
}
.nopadding {
margin: 0 !important;
padding: 0 !important;
}
.left {
background: white;
color: black;
height: 100%;
}
.right {
background: black;
color: white;
height: 100%;
}
.details {
background: grey;
color: white;
height: 100%;
}
Here are screenshots of the page (when the page has place to display the black column, everything works. But when I resize the window, it goes under the grey container [I saw that using z-index]) :
I would like the black column to be right under the white one when I resize and the grey column to be under the black column when I resize.
Thanks!
First, you are overrating the power of h-100, then you mixed h-100 with css incorrectly, basically you set on container and row height with h-100 and then in css you defined .left and .right with height of 100% so... Since your containers cannot be higher then 100% and contents (.left and .right) are 100% your “.right” is hidden out of bounds of your row because .left already took all available space...
For a starter I’ve would recommend to use weather bootstrap classes or css, it’s pretty easy to have all that without defining your own css in bootstrap...

Wrapping Elements when item is at a certain width

I am trying to implement a CSS "card template" that a 2 item flexbox that needs wrap the last item when the first item is at a certain width. To complicate matters the width of the last item can be variable. This makes more sense when you view the JFiddle below. The green box is the first item, and the red box is the last item. The red box needs to wrap to the next line when the user changes the windows size to where the green box reaches a width of 300px. I've tried to use the flex-wrap combined with min-width, but this doesn't do the trick. Any help is appreciated.
https://jsfiddle.net/burtonrhodes/tu4wgc3m/41/
And below is an example of the card template
<div class="afs-card">
<div class="afs-card-checkbox">
<input type="checkbox" />
</div>
<div class="afs-card-icon">
X
</div>
<!-- this div should expand to fill the space -->
<div class="afs-card-info">
<!-- this item should exapnd to fill the space -->
<div class="afs-card-content">
<div class="afs-card-description">
This is the content for the card. When adjusting the screen, if this box is
<=3 00px;, then the red box should wrap to the next line. </div>
<div class="afs-card-sub-description">
This is a sub text for the card
</div>
</div>
<!-- this div will be a certain width based off child width properties
and should go to next line if afs-content's width is <= 300px -->
<div class="afs-card-details">
<!-- no wrapping of these items should occur -->
<div style="width: 80px">
10/15/2005
</div>
<div style="width: 20px">
X
</div>
<div style="width: 70px">
More
</div>
</div>
</div>
<div class="afs-card-menu">
...
</div>
<div class="afs-card-drag-handle">
==
</div>
</div>
You can achieve this using flex-basis and flex-grow. Update your css with this:
// Your wrapper
.afs-card-info {
display: flex;
width: 100%;
border: 1px solid;
flex-wrap: wrap;
}
// Your left container
.afs-card-content {
padding: 1px 10px;
border: green 2px solid;
flex-basis: 300px;
flex-grow: 1;
}
you can do it like this without media queries:
.afs-card-info {
display: flex;
flex-wrap: wrap;
width: 100%;
border: 1px solid;
.afs-card-content {
flex-grow: 1;
min-width: 300px;
flex-basis: calc(100% - 176px);
set the container to wrap
set the content to fill available space
set content minimum width to ensure it will force the wrap eventually
flex-basis sets the elements width prior to any flex space distribution, so setting it to the rows space less the second element width prevents it from always wrapping the second element
fiddle: https://jsfiddle.net/z91j04rh/4/
place this line of code above the css that you want to apply the 300px min-width to
#media only screen and (min-width: 300px) {
#elementid {
--css here--
}
}

Bootstrap 4 - How to make a div without a fixed height scroll within another div whose height is set to 100%

So I'm using Bootstrap 4 with two columns. The two columns currently match each other in height, but I will have so much content in the left column that I'll need a scrolling div whose height spans the rest of the container. The issue I'm running into is that it's currently within a column div whose height is set to 100% (which makes it match the other column).
As a sidenote, this class only has a max-height set in the fiddle so that it doesn't stretch the left column, which already matches the height of the right:
.recent-articles-list {
max-height: 30rem;
}
Any help would be much appreciated, thank you! I have a feeling it might be something simple, but I haven't been fruitful in my research. (I've tried solutions using absolute positioning, setting height to 0/1px...)
JSFiddle: http://jsfiddle.net/3zeh7af4/
(Do note that the viewport has to be above 1200px to see what I'm talking about.)
Added image for desired effect:
What I understand from your problem depiction is that you want left column to be exactly same as right even if right column height is varying, and off course for left column to have scroll you need to fix it's height so you have done.
.recent-articles-list {
max-height: 30rem;
}.
if that's the case, the good solution for this situation is the code below
.recent-articles {
background-color: #fff;
padding: 1rem;
height: 100%;
position: relative;
}
.recent-articles-list {
padding-right: 1rem;
position: absolute;
top: 50px;
left: 0;
right: 0;
bottom: 0;
overflow-y: auto;
}
What you seem to be asking for is to shrink the height of the left column, to match the height of the right, and then scroll any overflow in the left column which is this: https://www.codeply.com/go/UTOSeASfnt
.recent-articles {
flex: 1 1 0;
overflow-y: auto;
}
.recent-articles-list {
overflow-y: auto;
}
However, IMO, that layout doesn't work well 😞 since the user must scroll the body of the entire page in order to see all content in the left column (when the content on right is taller than the viewport). The question doesn't explain what you expect to happen when the content on the right is taller than the viewport.
A better solution is to create a full-height layout, and then have the 2 sides scroll independently. You can do this by making the left side fixed or sticky as shown here...
Sticky left column:
.mvh-100 {
height: 100vh;
}
.recent-articles {
overflow-y: auto;
position: sticky;
top: 1rem;
}
.recent-articles-list {
overflow-y: auto;
}
<div class="container-fluid body-container">
<div class="row">
<div class="col-xl-5 py-3">
<div class="shadow recent-articles bg-white mvh-100 p-3">
<h5>Recent Articles</h5>
<div class="recent-articles-list">
...
...
</div>
</div>
</div>
<div class="col-xl-7 py-3">
<div class="row">
<div class="col-xl-12 shadow">
...
</div>
<div class="col-xl-12 shadow">
...
</div>
<div class="col-xl-12 shadow">
...
</div>
</div>
</div>
</div>
</div>
https://www.codeply.com/go/cNfS3EOQdV
Fixed left side:
Another option is to make the left side position:fixed, but it's more complex as it requires calc to adjust for spacing.
https://www.codeply.com/go/AqFxOD8gst
Related: Fixed and scrollable column in Bootstrap 4 flexbox

Setting a fixed height for 3 div's

Im having an issue with the header of my code. The header is split into 3 different column's two of which are currently populated with text and an image. (center is yet to be filled).
I notice that when i reduce the size of my browser (zoom in,out) two of the header column's start to break away from the content. The right column stays fixed to the content below because it is populated with text however the center column and the left column being less populated start to break away.
Is it possible to force my 3 column header to stay attached to the content below? Im worried that if someone views the site on a large screen or perhaps a retina display it is going to break away.
<div class="col span_1_of_3 a">
<div class="col span_1_of_3 b">
<div class="col span_1_of_3 c">
CSS is as follows:
.span_3_of_3 {
width: 100%;
}
/* line 28, ../sass/test.scss */
.span_2_of_3 {
width: 66.1%;
height:100%;
}
/* line 32, ../sass/test.scss */
.span_1_of_3 {
width: 33.32%%;
height:100%;
}
Wrap the divs in a parent div. Then float the children and give them a relative width.
<div class="header">
<div class="col span_1_of_3 a">
<div class="col span_1_of_3 b">
<div class="col span_1_of_3 c">
</div>
css:
.header { width:100%; overflow:auto; }
.col { float:left; width:30% }
You can use display: table-cell on each .col and display: table on parent (*). That will force your "cells" to have the same height and stay on the same row.
Though I wonder how you managed your witdths? Is it in percentage or em? You didn't include any CSS so it's impossible to figure.
(*) Add table-layout: fixed on this same parent if you want precise widths to be applied, otherwise the browser will also adapt to the content of each "cell".
Image re sizing will be out of control unless you set the Width/Height to percentage or relative values.
if you don't want to do this, simply set the min-width and min-height CSS Properties.
i prefer the relative sizing (ex. width: 30%; text-align: left;)

Display-inline block and image

I am new in designing and so have some problems...
I need 3 block to be inline and centered, so I tried:
#main .block{
display: inline-block;
border: 1px solid #ECEDE8;
margin: 10px 10px;
overflow: hidden;
height: 265px;
width: 265px;
}
But, when i add an image in to the block, all others goes down.
P.S.
As I see, this problem is in safari, in Firefox all ok.
P.S.S
<div id="main">
<div class="block">main
<img src="style/images/try.png">
</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
<div class="block">main</div>
</div>
P.S.S.S
As I could figure it out thought Google, all problem is in display: inline-block, in safari works display: inline-table. What solution could be?
You need to set the vertical align property. In this case best option would probably be:
vertical-align: top
So your css should be:
#main .block{
display: inline-block;
border: 1px solid #ECEDE8;
margin: 10px 10px;
overflow: hidden;
height: 265px;
width: 265px;
vertical-align: top;
}
If your blocks are fixed width, why not float them instead and put them in a parent container with a total width and centered using margin: 0 auto
The div element is a block element. The img element is an inline-block element; it has the main features of a inline element (except that it has the block element features of height and width). Therefore, I see two main problems with your code. Firstly, your image is somehow meant to replace the same unit of space as where you as simultaneously displaying the word "main" which can cause a conflict with spacing/display. [I recommend deleting the word "main" from your HTML.] Secondly, you don't specify the height and/or width of the image, which is not really a problem since you have overflow value set to hidden, but still generally you should have a height and/or width value assigned (make them less than the parent container's height and width) as it will make the browsers rendering/displaying more universal/compatible cross-browsers. Implementing a combination of those two things [or of changing your display value to inline-table (which it kind of seems more like what you want since your display seems "tablular")] SHOULD fix your problem. If it doesn't, I would recommend changing your margin value to 0 auto (which will have the effect of centering your image in the middle of your div/parent container), because I have a lingering suspicion that your margin values may also be at play (but only if the other two suggestions don't work). Good luck!
PS: Remember that just because you have overflow: hidden doesn't mean that the browser doesn't "see" the element(s) that are overflowing. Remember the Box Model.
Try this -
<div class="main" id="main">
<div class="block">main
<img src="style/images/try.png">
</div>
</div>
<div id="main">
<div class="block">main</div>
</div>
<div id="main">
<div class="block">main</div>
</div>
<div id="main">
<div class="block">main</div>
</div>
<div id="main">
<div class="block">main</div>
</div>
And instead of #main .block{ just .main {