I know this has been asked quite a few times here. But I'm not very experienced with HTML and am stuck following solutions suggested here.
My current implementation is like this. But the problem is if I stretch and adjust the browser window size, the borders of the four equal-sized quadrants follows. What I would like is:
The top area would be reserved for a load button and filter boxes.
The rest of the area would be divided up into four equally-sized quadrants.
When the browser window is adjusted, all five of these areas should not overflow into each other.
If I insert <div>'s inside each quadrant to draw plots, they should gracefully fall into place and will occupy four equally-sized areas regardless of the browser's size change.
What I'm trying to achieve looks something like in the picture below:
Thank you in advance for the help!
You can divide your 4 quadrants into 2 rows.
And give each row 100% width
and each quadrant a width of 50%
also,
make quadrants float left.
.row {
width: 100%;
padding: 0;
margin: 0;
}
.quad {
border: 1px solid black;
border-radius: 8px;
width: 49%;
padding: 0;
margin: 0;
height: 200px;
float: left;
}
<div>
<select><option>A</option></select>
<input type="button" value="Filter" />
</div>
<div class="row">
<div class="quad">
1 of 4
</div>
<div class="quad">
2 of 4
</div>
</div>
<div class="row">
<div class="quad">
3 of 4
</div>
<div class="quad">
4 of 4
</div>
</div>
Note: I have given 49% to quadrants so as to accommodate borders (they have 2 px width [1px each side])
You can also do this using flex CSS if you are targetting newer versions of browsers only.
In that case, you do not have to worry about widths.
Just give your row div : display: flex;
and your quadrants: flex: 1 1 auto;
Read more here about the flex display.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox
.row {
display: flex;
}
.quad {
flex: 1 1 auto;
border: 1px solid black;
border-radius: 8px;
height: 200px;
}
<div>
<select><option>A</option></select>
<input type="button" value="Filter" />
</div>
<div class="row">
<div class="quad">
1 of 4
</div>
<div class="quad">
2 of 4
</div>
</div>
<div class="row">
<div class="quad">
3 of 4
</div>
<div class="quad">
4 of 4
</div>
</div>
Using bootstrap 4 you can easily create such an layout. Bootstrap makes it much easier for developers to create a layout.
If you wanna use bootstrap, you can do following. Bootstrap 4 uses flexbox instead of float which is +1 comparing to bootstrap 3.
.vh-100 {
min-height: 100vh;
}
.choose-plot {
padding-top: 15px;
padding-bottom: 15px;
}
.bordered {
border: 1px solid #ccc;
border-radius: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js" integrity="sha384-u/bQvRA/1bobcXlcEYpsEdFVK/vJs3+T+nXLsBYJthmdBuavHvAW6UsmqO2Gd/F9" crossorigin="anonymous"></script>
<div class="container-fluid d-flex h-100 flex-column vh-100">
<!-- I want this container to stretch to the height of the parent -->
<div class="row">
<div class="col choose-plot">
<strong class="mb-2">Add/remove COUNTRIES (max: 5), ADVERTISES (max 4), YEAR (max 1), and plot location below. Then, click 'load plot'.</strong>
<div class="row">
<div class="col-4">
<select class="custom-select">
<option>Choose plot</option>
</select>
</div>
<div class="col-8">
<button class="btn btn-primary">Load plot</button>
</div>
</div>
</div>
</div>
<div class="row flex-fill d-flex justify-content-start">
<div class="col-6 bordered">1 of 4</div>
<div class="col-6 bordered">2 of 4</div>
<div class="col-6 bordered">3 of 4</div>
<div class="col-6 bordered">4 of 4</div>
</div>
</div>
Dividing into rows too,
I suggest you to use box-sizing: border-box; so that when you set width to 50%, the borders sizes are taken into account.
.col {
width: 50%;
height: 160px;
float: left;
box-sizing: border-box;
border: 2px solid gray;
border-radius: 4px;
padding: 4px;
}
<div>Something here.</div>
<div class="row">
<div class="col">1</div>
<div class="col">2</div>
</div>
<div class="row">
<div class="col">3</div>
<div class="col">4</div>
</div>
Hope it helps.
Related
I have a page with a banner and 3 columns, and I am trying to make it so that when the screen width gets too small, that the first 2 columns change from 1/3rd width to 50% width and the last column width change to 100% so that it's below the first two.
When I do this, the height of the columns does change (they change to 50%, considering the columns will now fit underneath each other inside a 100% row), but the width does not. How could I fix this? Thanks in advance!
Codepen
HTML
<section class="section">
<div class="container-fluid">
<div class="aboutBanner"> </div>
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
</div>
</section>
related CSS
.aboutBanner {
height: 30%;
border: 1px solid blue;
}
.row {
height: 70%;
}
.row .col {
height: 100%;
border: 1px solid red;
}
#media screen and (max-width: 768px){
.row .col:nth-of-type(1),
.row .col:nth-of-type(2) {
height: 50%;
width: 50%;
}
.row .col:nth-of-type(3) {
height: 50%;
width: 100%;
border-style: dashed;
}
}
Use the Bootstrap responsive grid columns...
https://codepen.io/anon/pen/eMzRyb
<section class="section">
<div class="container-fluid">
<div class="aboutBanner">
</div>
<div class="row">
<div class="col-sm-4 col-6">
</div>
<div class="col-sm-4 col-6">
</div>
<div class="col-sm-4 col-12">
</div>
</div>
</div>
</section>
To visualize this in your codepen I changed the CSS...
.row {
height: 70%;
}
.row > div {
border: 1px solid red;
}
Also see:
What is the difference among col-lg-*, col-md-* and col-sm-* in Bootstrap?
Use bootstrap col-[size] class
See documentation
The bootstrap grid is based in 12 columns sizes, that are divided in 5 screen sizes:
Extra small
col-[1 to 12]
Small
col-sm-[1 to 12]
Medium
col-md-[1 to 12]
Large
col-lg-[1 to 12]
Extra large
col-xl-[1 to 12]
Try this:
<section class="section">
<div class="container-fluid">
<div class="aboutBanner"> </div>
<div class="row">
<div class="col-md-4 col-sm-6">
content of first
</div>
<div class="col-md-4 col-sm-6">
content of second
</div>
<div class="col-md-4 col-sm-12">
content of third
</div>
</div>
</div>
</section>
Keep in mind that 12 is 100%, 6 is 50%, 4 is 33%, 3 is 25% and so on...
I am using Flexbox and I am trying to create something like this:
I want the three "parent" boxes to be vertically aligned within the row. Each box have different height.
In the snippet (Codepen is better in this case as there was a character limit in Stack) I am trying to replicate the first box as a start, the boxes float to the top. They are not vertically aligned:
.box, .box-first, .box-large, .box-nested, .box-row {
position: relative;
box-sizing: border-box;
min-height: 1rem;
margin-bottom: 0;
background: #007FFF;
border: 1px solid #FFF;
border-radius: 2px;
overflow: hidden;
text-align: center;
color: #fff;
}
.box-nested {
background: #036;
border-color: #007FFF;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.css" rel="stylesheet"/>
<div class="row"> <div class="col-xs-12"> <div class="box box-container"> <div class="row"> <div class="col-xs-12"> <div class="box-first box-container"> <div class="row"> <div class="col-xs-2"> <div class="box-nested"> <img style="width:30px; height:auto;" src="https://cdn0.iconfinder.com/data/icons/simplicity/512/dollar-256.png"/> </div></div><div class="col-xs-5"> <div class="box-nested"> <div class="col-xs-12"> <div class="box-nested">111 222</div><div class="box-nested">105,306</div></div></div></div><div class="col-xs-5"> <div class="box-nested"> <div class="col-xs-12"> <div class="box-nested"> <div class="col-xs-12"> <div class="box-nested">111</div><div class="box-nested">222</div></div></div><div class="box-nested"> <div class="col-xs-12"> <div class="box-nested">105,306</div></div></div></div></div></div></div></div></div></div></div></div></div>
When I tried adding the for the display: flex; align-items: center; in the CSS it messes up with the nested divs:
I am not that familiar with Flexbox and I have seen many different versions online that don't help.
I've read 5-6 question / answers but can't find what I'm looking for _
Bootstrap 4 columns aren't behaving the way I expect them to. Below about 600px device width the edge overflows instead of continuing to reduce in size
at 618px the columns are still reducing
at 538px the columns are overflowing
HTML:
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-12">
<div class="outerDivBorder" id="photoBox">
<div style="height: 10em;"></div>
</div><!-- /#photoBox -->
</div>
<div class="col-lg-3 col-md-12">
<div class="outerDivBorder" id="dataBox">
<div style="height: 10em;"></div>
</div><!-- /#dataBox -->
</div>
</div>
</div><!-- /.container -->
CSS:
.outerDivBorder {
width: 100%;
border: 1px solid #454343;
padding: 0 1rem;
margin: 1rem;
margin-top: 1.5rem;
margin-bottom: 2rem;
}
Thanks in advance for any guidance offered on this : )
You put margin: 1rem; on .outerDivBorder, and that margin pushes content out on small screens. Use padding on cols instead - it can be done by using utility class for padding, py-3 in this case:
.outerDivBorder {
width: 100%;
border: 1px solid #454343;
padding: 0 1rem;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-12 py-3">
<div class="outerDivBorder" id="photoBox">
<div style="height: 10em;"></div>
</div>
</div>
<div class="col-lg-3 col-md-12 py-3">
<div class="outerDivBorder" id="dataBox">
<div style="height: 10em;"></div>
</div>
</div>
</div>
</div>
Had a similar problem. On mine it was happening because of
* {
box-sizing: inherit;
}
Bootstrap already reset that to border-box and the col's and row's behave according to that.
I'm fairly new to semantic-ui. This is probably a pretty stupid question.
I'm struggling with creating a five column grid layout that is responsive/mobile friendly. Here's a quick image that shows what I am trying to do. Also, sorry for my sick MS Paint skills:
Computer:
Mobile:
Any ideas? :)
The outer container is straightforward I think. For the Segment which has 5 items in it, you can use something like:
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css" rel="stylesheet" />
<div class="ui container">
<div class="ui one column centered grid">
<div class="center aligned column" style="background-color: #B0C4DE;">
Some Row
</div>
<div class="column">
<div class="ui stackable five column grid">
<div class="column" style="background-color: #FFF8DC;">Item 1</div>
<div class="column" style="background-color: #F8F8FF;">Item 2</div>
<div class="column" style="background-color: #FFF8DC;">Item 3</div>
<div class="column" style="background-color: #F8F8FF;">Item 4</div>
<div class="column" style="background-color: #FFF8DC;">Item 5</div>
</div>
</div>
<div class="column" style="background-color: #E0FFFF;">
New Row
</div>
</div>
</div>
The grid is your friend https://semantic-ui.com/collections/grid.html
I think you forgot one of the best part on Semantic UI.
https://semantic-ui.com/views/item.html
Responsive Element
Item views are designed to be responsive with images stacking at mobile resolutions.
You just have to put your item elements on a ui items, and it's will works.
Looks here :
<div class="ui items">
<div class="item">
<div class="item">
<div class="item">
<div class="item">
<div class="item">
</div>
Using grids is cool, but you already have responsive element :)
Peace
I know you want to use semantic-ui but if you don't mind, you create your layout with bootstrap4 too.
Bootstrap4 methodology is mobile first, so create your html structure to adapt mobile and then grow from there.
Bootstrap use a grid system based on rows of 12 columns. You define the space taken for each column using the class col-x for mobile, col-md-x for medium width window, col-lg-x for large. "x" defines the number of columns (x<=12) taken by the div element. Check the Bootstrap4 documentation.
Remember to add the related js libraries and css to your html file.
Check this snippet:
#row-1{
background-color: orange;
}
#row-2{
background-color: yellow;
}
#row-3{
background-color: lightblue;
}
<script src="https://npmcdn.com/tether#1.2.4/dist/js/tether.min.js"></script>
<div class="container">
<div id="row-1" class="row">
<div class="col-12">
Row #1
</div>
</div>
<div id="row-2" class="row">
<div class="col-12 col-md-2">
Item 1
</div>
<div class="col-12 col-md-2">
Item 2
</div>
<div class="col-12 col-md-2">
Item 3
</div>
<div class="col-12 col-md-2">
Item 4
</div>
<div class="col-12 col-md-2">
Item 5
</div>
<div class="col-12 col-md-2">
Item 6
</div>
</div>
<div id="row-3" class="row">
<div class="col-12">
Row #3
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
I have an "index.html" and a "style.css" to accomplish this.
The html looks like this (call it "index.html"):
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<meta name="description" content="grid example for StackOverflow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Grid Example - by Rob Blansett.
</title>
</head>
<body>
<div class="Container">
<p>Container: Content should be horizontally centered.</p>
<div class="Row" id="One">
Row #1
</div>
<div class="Row" id="Two">
Row #2
<div class="Segment">
<div class="SegmentText">
Segment
</div>
<div class="Item" id="Item1">
Item #1
</div>
<div class="Item" id="Item2">
Item #2
</div>
<div class="Item" id="Item3">
Item #3
</div>
<div class="Item" id="Item4">
Item #4
</div>
<div class="Item" id="Item5">
Item #5
</div>
</div>
</div>
<div class="Row" id="etc">
Row ...
</div>
</div>
</body>
</html>
And the "style.css" looks like this:
* {
padding: 0;
margin: 0;
}
div {
display: block;
padding: 1em;
margin: 1em;
border-style: solid;
position: relative;
}
div.Container {
margin-left: 2%;
margin-right: 2%
}
div.Row {
background-color: grey;
}
div.Segment {
background-color: lightgrey;
}
div.SegmentText {
border-style: none;
}
div.Item {
background-color: darkgray;
}
/* If at least 500 pixels width is available then: */
#media (min-width:500px) {
div {
display: grid;
grid-gap: 1em;
padding: 1em;
margin: 0;
border-style: solid;
position: relative;
}
div.Container {
margin-left: 10%;
margin-right: 10%
}
div.Segment {
display: grid;
grid-template-columns: 1Fr 1Fr 1Fr;
}
div.SegmentText {
grid-column: 1 / 4;
border-style: none;
}
}
/* If at least 800 pixels width is available then: */
#media (min-width:800px) {
div {
display: grid;
grid-gap: 1em;
padding: 1em;
margin: 0;
border-style: solid;
position: relative;
}
div.Container {
margin-left: 20%;
margin-right: 20%
}
div.Segment {
display: grid;
grid-template-columns: 1Fr 1Fr 1Fr 1Fr 1Fr;
}
div.SegmentText {
grid-column: 1 / 6;
border-style: none;
}
}
Note that I've included #media queries for the window width. The default style set up is at the top of the CSS, then below that are the query sections that do the GRID stuff if there is a wide-enough window. So, it will be the one column if less than 500 pixels are available, and it will be 5 columns if at least 800 pixels are available. I included an intermediate size with 3 columns - just for fun. Re-size the window and see the adjustment between styles in action.
Here's link to working a copy:
http://technifusion.com/projects/web/grid-example-01.html
This just gives an idea of how it can be done.
Note: This solution does not use semantic-ui (that the original poster asked for) but this solution may still help people who are not using that framework.
I am trying to implement a design from my graphic designer, which whilst looks cool is giving me some headaches as i don't know how to implement in bootstrap.
We have a call to action section, which aligns with the 12 column grid system on its left and right extremes.
It also stretches to the view-port edges:
On the left we have red background stretching all the way to the view-port edge.
On the right we have a grey background image stretching all the way to the view-port edge.
I haven't been able to find a search term for what I am looking to achieve let alone where to start (other than have the cta use the background for the entire width, then overlay a left element over the top).
Any idea on how to code the below graphical layout in bootstrap please?
<section class="cta" style="background: grey; position: relative">
<div class="red" style="position: absolute; left: 0; width: 10%; background: red"></div>
<div class="text-outer">
<div class="container">
<div class="row">
<div class="col-xs-6">left</div>
<div class="col-xs-6">right</div>
</div>
</div>
</div>
</section>
Using <div class="container-fluid"> as a starting point; I am guessing at your page's layout. Let's try this:
See below:
.cntn {
border: 1px red solid; /* you can remove this (not needed) */
}
.red {
background-color: red;
text-align: right;
margin: 0; /* optional */
width: 100px; /* adjust to suit your needs */
float: left;
}
.cta {
margin: 0; /* optional */
float: right;
border: 1px solid green; /* you can remove this (not needed) */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- make container fluid -->
<div class="container-fluid">
<div class="row">
<!-- heading area: hexagon -->
<div class="red">
<img src="http://placehold.it/100/100" />
</div>
<!-- heading area: call-to-action -->
<section class="cta">
Action
</section>
</div>
<div class="row cntn">
<div class="col-xs-6">left</div>
<div class="col-xs-6">right</div>
</div>
</div>
Simply change 'div class="container"' to 'div class="container-fluid"'
Something like this? Where black should be the grey gradient and max-width:400px could be anything.
.cta {
overflow-x: hidden;
position: relative
}
.text-outer .container {
width: 100%;
max-width: 400px;
background: grey;
z-index: 2;
position: relative;
}
.text-outer:before,
.text-outer:after {
content: "";
position: absolute;
width: 50%;
height: 100%;
top: 0;
}
.text-outer:before {
background-color: red;
left: 0;
}
.text-outer:after {
background-color: black;
right: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<section class="cta">
<div class="text-outer">
<div class="container">
<div class="row">
<div class="col-xs-6">left</div>
<div class="col-xs-6">right</div>
</div>
</div>
</div>
</section>
jsFiddleLink
I created with 3 divs as Left Center and Right but if you want to use Left and center then create your own class. Probably following will work
.custom {
width:calc(100% - (50% - 768px/2));
}
.custom {
width:calc(100% - leftCellWidth);
}
You can set height of left as per height of hex image.
Use jumbotron class outside the class container for full-width, as explained here.
HTML:
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="red col-xs-4">
</div>
<div class="grey col-xs-8">
</div>
</div
</div>
</div>
CSS:
.red {
background: url('awesomeredimage.png');
background-size: cover;
}
.grey {
background: url('awesomegreyimage.png');
background-size: cover;
}
All your divs should be wrapped in the container div. And as some others have also suggested: container-fluid helps.
Within container fluid you can add a regular container for the rest of your content. My code below explains this.
You could take the easy route and just use the entire cta image you've posted as a clickable image with .img-responsive in a col-xs-12. In that case my fix takes you about 2 minutes:
<section style="background: grey; position: relative">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<img src="/img/cta.jpg" class="img-responsive">
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="container">
<!-- All you other content here-->
</div>
</div>
</div>
</div>
</section>
But you could also hack the design into cols, as I try to show in the code snippet below. Of course you need to tweak and decide on the exact sizes yourself.
<section style="background: grey; position: relative">
<div class="container-fluid">
<div class="row">
<div class="col-xs-3 red">
<img src="/img/hexagon.png" class="img-responsive pull-right">
<!--and give this img a negative margin to flow over to the grey area-->
</div>
<div class="col-xs-1 grey-image"></div>
<div class="col-xs-3 grey-image">
<h3 class="text-center">Call to action</h3>
<p class="text-center">Discount etcetera</p>
</div>
<div class="col-xs-5 grey-image">
<button class="btn center-block">Request quote</button>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="container">
<!-- All you other content here-->
</div>
</div>
</div>
</div>
</section>
Use class="container-fluid" instead of class="container" and than do this style:
.container-fluid {
margin-right: auto;
margin-left: auto;
padding-left: 0px;
padding-right: 0px;
}