I have begun trying to use bootstrap 5, and I am thoroughly lost. Below, is a layout I have created (i.e. the blue elements, the sidebar has been taken from this source) and I am trying to replicate the following layout.
I am basically trying to add a neat margin between the blue elements and and making L1, L2, L5 and L6 the same height, and L3 and L4 half of that height, and center the blue elements in the white space.
From a jsfiddle I have did, the css3 code I have added for the individual styling of the blue elements is as follows:
.col{
padding: 5rem;
background-color: #33b5e5;
border: 2px solid #fff456;
border-radius: 10px;
color: #fff;
}
To reduce the size of elements, I have tried reducing the padding but the elements are positioned more towards the top of the page. Adding any margin causes the elements to overflow onto new lines.
Any help would be appreciated to get it close to the desired result. Thank you
try to give margin to .col and remove p-5 from col-10
.col {
padding: 1rem;
background-color: #33b5e5;
border: 2px solid #fff456;
border-radius: 10px;
color: #fff;
margin: 0.2rem;
}
At a first look, don't use padding to play with the height of the elements, use height itself.
Also, don't apply css directly to the col class, it'll get harder to maintain. Use a different class name, and differentiate your cols based on them. Let's say L1, L2, L5 and L6 could be class big-card, and L3, L4 could be small-card. Apply a fixed height to these both. And remove all padding initially from the col.
.small-card {
height: 200px;
}
.big-card {
height: 400px;
}
Of course, adjust the height as per necessary. Then add padding according to the content that you put within the cards.
Then for the space between cards, use the gap class of bootstrap. Append this class along with row. Like: row gap-3 will add a space of 16px between each card. (Of course, you'll need to have the padding of the cards removed first as I said, otherwise the layout will break because the width of the cards will be more than you are allowing).
Related
I have a page with a row of 100px and 4 columns of 25px each. I seem to get at odd behavior. Please take a look at this fiddle http://jsfiddle.net/GmU2k/
My question is should all of the columns be on the same line?
Fiddle
Better use box-sizing: border-box by adding below css on column-3: That happens because of your 1px border.
box-sizing:border-box;
-moz-box-sizing:border-box; /* Firefox */
Check this fiddel
http://jsfiddle.net/GmU2k/2/
.column-3 {
width: 24%;
border: 1px solid red;
float: left;
}
You gave the width as 25% and a border of 1px. So 4 divs width = 100% + border width
Thats why 4 divs are not shown in one line. Because there is not enough space.
Once you decrease the width of inner divs then there will be enough space. Or you can remove the border, so that inner divs will have enough space to be shown in a single line.
Note: The simple concept is there should be enough space for the divs to be shown in single line. If there is not enough space then they will flow to the next line.
Change the column-3 width to 24%.
I have block in my site and i want to do something like that:
http://s13.postimg.org/6ue9a8bfr/Untitled_3.png
but what happens to me is this:
http://s15.postimg.org/derz2m8h7/image.png
this is my div csS:
background-color: #ffffff;
width: 37.2%;
border-top: 4px solid black;
margin: 14px 0.4% 14px 0.4%;
float: left;
-webkit-border-radius: 2px;
border-radius: 2px;
How i can do this?
Thanks!
Old way:
Use a table with 1 row (tr) and 3 cells (td), put your DIVs in those cells, make sure the cells are valign=top.
People that shun table layout way:
Use 3 container DIVs that will represent your columns, relatively position them side by side (float:).
Modern way:
Use flexbox positioning https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes or use the CSS column-* properties http://playground.html5rocks.com/#columns
Use three separate container divs to represent the three columns. Within each column, which has been set the appropriate width, make the divs inside the containers and set them at 100% each, thus filling up the entire width of the column container forcing the other div elements underneath. Then add appropriate margins.
I have a page which contains a table.
The <tr>'s have a border-bottom: 1px dotted black;, but as you can see from the image below, they are rendering quite strangely. Does anyone know why this might be?
Relevant CSS
.basket-item{
border-bottom: 1px dotted black;
border-top: 1px dotted black;
padding: 10px 0;
}
.basket-item td:nth-of-type(2){ //included this as it seems to be the second td in every row
padding: 25px;
vertical-align: top;
text-align: left;
}
HTML structure is a standard table, <tr>'s have a class of .basket-item
Thanks in advance for any help
Extending from comment:
This problem seems to only/mainly affects Chrome (or WebKit), and after some unsuccessful trial, I finally come up with this:
add
h4 {
margin-bottom: 1.5em; /* or whatever length that ends in an integer pixel */
}
The reason for this, is that you have specified
font-size: 14px;
And Chrome has an internal CSS that looks like:
h4 {
-webkit-margin-before: 1.33em; /* works like margin-top */
-webkit-margin-after: 1.33em; /* works like margin-bottom */
}
That makes a floating point number pixel (14 * 1.33 = 18.62), and (probably with other elements below, especially float: left elements), Chrome seems to have the need to "calculate" the remaining space height for "placeholder", and finally ends up with a floating point number that is "very close to 200px".
Observation:
In my Chrome, the <td> should be 250px height (including padding). That <td> has padding: 25px, so the "inner height" should be 200px, but with default style, in developer tool, Chrome shows that the <td> is actually 199.609375px height. Overwriting the margin-bottom of h4 to an integer "normalized" the inner height back to 200px.
It's obviously the table display ; if you change your td or your tr to another display (like inline-block), it disappear, but your layout is broken.
It also seems to depend on the zoom level of the viewport : if you scale up, you can make the weird border disappear (both top and bottom border) : the height of tr and td switch from 250px to 251px sometimes.
With so few information, I can't deduce another parameter to change.
Without any actual solution, consider changing your display type, for either tror td, and adapt your layout to fit you requirement.
My application should look good on small screens. When it is normal size, everything looks good. But when the screen is too small my buttons starting to mess up.
Red square represents an image, yellow represents some text and blue represents buttons.
Normally, the top version is displayed (the correct one)
When the screen is small, the second situation happens, when the bottom button jump to a new line.
Ideally, both buttons should stay one above the other. This is my css code:
{
background-color: #6b89ac;
border: 1px solid #89a9d0;
border-bottom-color: #1d4474;
color: white;
font-weight: bold;
text-decoration: none;
padding: 2px 5px 2px 5px;
margin-bottom: 3px;
text-align: center;
display: inline-block;
width: 100px;
}
It happens on small screens because the button is being pushed far enough down to slide under the picture. Try wrapping the text and buttons together in a div. The buttons would then be bound by the left edge of that new div.
Depending on your code that new div might also need overflow: hidden.
In the 1st situation, the 2nd blue box being held to the right only because the red box is tall enough to prevent it from clearing.
To ensure the blue boxes stay to the right right, float them right {float:right}
You should then wrap each set in a div so that the 2nd red box doesn't run up into the middle of the 1st group. And you'd probably need to apply a cleafix solution to that div to ensure its height grows approprirately with the addition of floats.
clearfix references:
1. What methods of ‘clearfix’ can I use?
2. The New Clearfix Method
(I prefer #2)
You can give the body a fixed width. Then, your layout doesn't change when the window width is reduced. You can use the overflow-x property to control the scrollbar behaviour
How do you horizontally distribute 3 divs with the least amount of code?
I have 3 divs that have the same class, and I need to distribute them horizontally, with 19 pixels of space between each div.
My solution currently is to give the first 2 divs a right margin of 19 pixels, and assign a separate class to the 3rd div that gives it a left margin of 19 pixels.
This gets the job done, but I feel like there may be a better way of doing it. Ideally, all 3 divs would still have the same class.
See: http://jsfiddle.net/thirtydot/q6Hj8/
.yourDivClass + .yourDivClass {
margin-left: 19px
}
That uses the adjacent sibling combinator to apply margin-left to every .yourDivClass which is preceded by a .yourDivClass - in other words, all except the first.
You only need two columns with a right margin; the third column needs no additional margin. Border added so you can see it in a fiddle.
div.hasMargin
{
margin-right: 19px;
}
div.column
{
border-color: black;
border-style: solid;
border-width: 1px;
float: left;
}
Here is a fiddle