I'm trying out Bootstrap 5 with a simple webpage where I have one row with two columns. The left column is fine but the right one is acting funny. The webpage is supposed to be full screen with no scroll. But whenever I put margin in an element inside the right column then the whole column increases in height and goes beyond 100vh/100%. I want content-right-inner class to have margin of 50px all around. If I delete min-height then all item moves to the top. I want it to be full screen size with margin. How can I do that?
Here's the code:
*,
*:before,
*:after {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
line-height: 1.7;
font-size: 1.6rem;
background-color: #fff;
color: #000;
}
h1, h2, h3, h4, h5, h6, p {
margin: 0px;
}
button,
input {
overflow: visible;
}
button,
input,
optgroup,
select,
textarea {
margin: 0;
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
.row>* {
padding-right: 0;
padding-left: 0;
}
.main {
background-color: green;
max-height: 100vh;
}
.content-left{
height: 100vh;
padding: 0;
color: #fff;
background-color: red;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
.content-right{
background: blue;
}
.content-right-inner{
margin: 50px;
position: relative;
min-height: 100vh;
}
.logo p{
font-family: Lato-Light;
font-size: 1.5rem;
color: #F7A14C;
font-weight: 600;
}
.main-content{
position: absolute;
left: 0;
top: 50%;
bottom: auto;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.social-box{
margin: 0 10px 0px 15px;
float: left;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css" rel="stylesheet"/>
<section class="main">
<div class="container-fluid position-relative h-auto p-0 overflow-hidden">
<div class="row">
<section class="content-left col-xs-12 col-lg-6">
<div class="inner-container">
<p>Boom Boom</p>
</div>
</section>
<section class="content-right col-xs-12 col-lg-6">
<div class="content-right-inner">
<div class="logo text-center">
<p>test</p>
</div>
<div class="main-content">
<h1>Lorem Ipsum!</h1>
<p>Lorem Ipsum Lorem Ipsum Lorem Ipsum.</p>
<p>Lorem Ipsumsdfafafafafa!</p>
<button>Lorem Ip</button>
</div>
<div class="social-icons">
<div class="social-box">
<i class="fab fa-facebook-f"></i>
</div>
<div class="social-box">
<i class="fab fa-twitter"></i>
</div>
<div class="social-box">
<i class="fab fa-linkedin-in"></i>
</div>
<div class="social-box">
<i class="fab fa-instagram"></i>
</div>
</div>
</div>
</section>
</div>
</div>
</section>
Found a fix for the issue. Putting margin all around and especially at the bottom made the container exceed it's height of 100vh. To fix it I just used calc() in .content-right-inner.
Here's the code:
.content-right-inner{
position: relative;
margin: 50px;
height: 95vh;
height: calc(100vh - 100px);
}
I guess that just deducts the extra height which came from a margin of 50px.
Related
I'm trying to create some layout, but been stuck with overlapping div - 'featured works' is like going under row with 3 icons and honestly can't figure out solution for this one. Just need to put overlapping div under three icons section. There will also be a few more under, so any advices appreciated.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
/* columns */
.col-1 {
width: 8.33%;
}
... typical grid 1-12
/* offset */
.col-offset-1 {
margin-left: 8.33%;
}
... same as above
/* clearfix */
row::before,
row::after {
content: "";
display: table;
clear: both;
}
[class*="col-"] {
float: left;
min-height: 1px;
height: 150px;
padding: 10px;
}
/* === */
header nav {
background-color: #544B46;
overflow: hidden;
}
header nav ul {
float: right;
margin: 0;
padding: 0;
list-style-type: none;
}
header nav ul li {
display: inline-block;
}
header nav ul li a {
line-height: 50px;
display: block;
color: #fff;
padding: 0 20px;
text-decoration: none;
text-transform: uppercase;
}
.hero img {
width: 100%;
margin: 0 auto;
padding: 0;
}
.icons {
margin: 50px auto;
text-align: center;
}
.icons i {
height: 75px;
width: 75px;
color: #544B46;
border-radius: 10%;
background-color: #fff;
font-size: 40px;
margin: 0 auto;
cursor: pointer;
border: 2px #544B46 solid;
display: inline-block;
padding: 15px 15px;
}
.icons h1,
.icons p {
padding: 15px;
}
<body>
<header>
<nav class="container">
<div class="row">
<ul>
<li><a href=”#”>About us</a></li>
<li><a href=”#”>Mission</a></li>
<li><a href=”#”>Contact</a></li>
</ul>
</div>
</nav>
</header>
<section class="hero">
<div class="container">
<div class="row">
<img src="http://naturalnie.media.pl/test/train-long.jpg">
</div>
</div>
</section>
<section class="icons">
<div class="container">
<div class="row">
<div class="col-4">
<i class="fab fa-researchgate"></i>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum.</p>
</div>
<div class="col-4">
<i class="fas fa-laptop-code"></i>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum.</p>
</div>
<div class="col-4">
<i class="fas fa-cogs"></i>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum.</p>
</div>
</div>
</div>
</section>
<section class="featured">
<div class="container">
<div class="row">
<div class="col-12">
<h1>FEATURED WORKS</h1>
</div>
</div>
</div>
</section>
</body>
Sorry for indents, new here.
Your issue is that you set your css class [class*="col-"] with height: 150px;. Get rid of the height requirement, and it goes back into place.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
/* columns */
.col-1 {width: 8.33%;}... typical grid 1-12
/* offset */
.col-offset-1 {margin-left: 8.33%;}... same as above
/* clearfix */
row::before,
row::after {
content: "";
display: table;
clear: both;
}
[class*="col-"] {
float: left;
min-height: 1px;
/*height: 150px;*/
padding: 10px;
}
/* === */
header nav {
background-color: #544B46;
overflow: hidden;
}
header nav ul {
float: right;
margin: 0;
padding: 0;
list-style-type: none;
}
header nav ul li {
display:inline-block;
}
header nav ul li a {
line-height: 50px;
display: block;
color: #fff;
padding: 0 20px;
text-decoration: none;
text-transform: uppercase;
}
.hero img {
width: 100%;
margin: 0 auto;
padding: 0;
}
.icons {
margin: 50px auto;
text-align: center;
}
.icons i {
height: 75px;
width: 75px;
color: #544B46;
border-radius: 10%;
background-color:#fff;
font-size: 40px;
margin: 0 auto;
cursor: pointer;
border: 2px #544B46 solid;
display: inline-block;
padding: 15px 15px;
}
.icons h1,
.icons p {
padding: 15px;
}
<body>
<header>
<nav class="container">
<div class="row">
<ul>
<li><a href=”#”>About us</a></li>
<li><a href=”#”>Mission</a></li>
<li><a href=”#”>Contact</a></li>
</ul>
</div>
</nav>
</header>
<section class="hero">
<div class="container">
<div class="row">
<img src="http://naturalnie.media.pl/test/train-long.jpg">
</div>
</div>
</section>
<section class="icons">
<div class="container">
<div class="row">
<div class="col-4">
<i class="fab fa-researchgate"></i>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum.</p>
</div>
<div class="col-4">
<i class="fas fa-laptop-code"></i>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum.</p>
</div>
<div class="col-4">
<i class="fas fa-cogs"></i>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum.</p>
</div>
</div>
</div>
</section>
<section class="featured">
<div class="container">
<div class="row">
<div class="col-12">
<h1>FEATURED WORKS</h1>
</div>
</div>
</div>
</section>
</body>
I've tried to mimic the "icon left - text right" boxes from https://fontawesome.com/ by taking over the style sheets. everything works fine until I apply fa-spin to an icon (see the sample). The icon is then misplaced and not centered.
I was just able to fix the issue by creating a clone of .g-im-icon -> .g-im-icon-for-spin and playing around with the top, left and transform styles.
however I was wondering if there would be a generic solution that would work for both spinning and non spinning icons?
.g-im-item {
border-radius: .25rem;
box-shadow: 0 0.25rem 0.125rem 0 rgba(33, 37, 41, .05);
margin-bottom: 1.5rem;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
.g-im-icon-c {
width: 25%;
font-size: 1.95312rem;
position: relative;
}
.g-im-text-c {
padding: 1.5rem;
width: 75%;
}
.g-im-title {
font-family: fa5-proxima-nova, Helvetica Neue, Helvetica, Arial, sans-serif;
margin-top: 0;
margin-bottom: .5rem;
font-weight: 600;
}
.g-im-message {
margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
}
.g-im-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<link href="https://use.fontawesome.com/releases/v5.0.4/css/all.css" rel="stylesheet" />
<div class="g-im-item k-info-colored">
<div class="g-im-icon-c">
<i class="g-im-icon fas fa-tachometer-alt fa-2x"></i>
</div>
<div class="g-im-text-c">
<h3 class="g-im-title">Title goes here</h3>
<p class="g-im-message">Test goes here</p>
</div>
</div>
<div class="g-im-item k-info-colored">
<div class="g-im-icon-c">
<i class="g-im-icon fas fa-tachometer-alt fa-spin fa-2x"></i>
</div>
<div class="g-im-text-c">
<h3 class="g-im-title">Title goes here</h3>
<p class="g-im-message">Test goes here</p>
</div>
</div>
In your .g-im-icon-c class you could implement flexbox in order to center its items instead of using position absolute, this is happening because the transform property get overwritten by your animation.. that is why your animation isn't centered...
.g-im-item {
border-radius: .25rem;
box-shadow: 0 0.25rem 0.125rem 0 rgba(33, 37, 41, .05);
margin-bottom: 1.5rem;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
.g-im-icon-c {
width: 25%;
font-size: 1.95312rem;
display: flex;
justify-content: center;
align-items: center;
}
.g-im-text-c {
padding: 1.5rem;
width: 75%;
}
.g-im-title {
font-family: fa5-proxima-nova, Helvetica Neue, Helvetica, Arial, sans-serif;
margin-top: 0;
margin-bottom: .5rem;
font-weight: 600;
}
.g-im-message {
margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
}
.g-im-icon {
/*position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);*/
}
<link href="https://use.fontawesome.com/releases/v5.0.4/css/all.css" rel="stylesheet" />
<div class="g-im-item k-info-colored">
<div class="g-im-icon-c">
<i class="g-im-icon fas fa-tachometer-alt fa-2x"></i>
</div>
<div class="g-im-text-c">
<h3 class="g-im-title">Title goes here</h3>
<p class="g-im-message">Test goes here</p>
</div>
</div>
<div class="g-im-item k-info-colored">
<div class="g-im-icon-c">
<i class="g-im-icon fas fa-tachometer-alt fa-spin fa-2x"></i>
</div>
<div class="g-im-text-c">
<h3 class="g-im-title">Title goes here</h3>
<p class="g-im-message">Test goes here</p>
</div>
</div>
As an option, you can try applying negative margin to all spinning icons .fa-spin:
.fa-spin {
margin-left: -25%;
margin-top: -25%;
}
My question is how to position these cards on my website?
https://imgur.com/a/Ompfh
It would be easy if there isn't this half circles above them.
I have tried to create parent class="cards" and class="card" for each of 3 cards.
In css:
.cards { display: flex }
.card { width: 33.33% }
And set relative position to my background and absolute position to my half-circles but I want to do it without absolute and relative positions if it's possible.
.cards {
display: flex;
}
.card {
width: 33.33%;
color: #fff;
text-align: center;
}
.card p {
min-height: 80px;
padding: 0 39px 0 39px;
}
.strategy--logo {
position: absolute;
top: 383px;
left: 607px;
width: 96px;
height: 48px;
background-color: #5a471b;
border-top-right-radius: 48px;
border-top-left-radius: 48px;
}
.strategy {
margin-top: 135px;
background-color: #5a471b;
}
.crop--marketing {
margin-top: 135px;
background-color: #9fa374;
}
.risk--mgmt {
margin-top: 135px;
background-color: #666;
}
<div class="cards">
<div class="card">
<div class="strategy">
<div class="strategy--logo">
<img src="css/images/strategy-logo.png" alt="" />
</div>
<!-- /.strategy-/-logo -->
<h2>
</h2>
<p>
</p>
</div>
<!-- /.crop-/-marketing -->
</div>
<!-- /.card -->
<div class="card">
<div class="crop--marketing">
<img src="css/images/crop-logo.png" alt="" />
<h2>
</h2>
<p>
</p>
</div>
<!-- /.crop-/-marketing -->
</div>
<!-- /.card -->
<div class="card">
<div class="risk--mgmt">
<img src="css/images/arrow-logo.png" alt="" />
<h2>
</h2>
<p>
</p>
</div>
<!-- /.risk-/-mgmt -->
</div>
<!-- /.card -->
</div>
<!-- /.cards -->
Now I'm using absolute and relative but is there another way? Because when I resize my web browser the circles go away random ...
Are you trying to achieve this?
.card {
displaY: block;
float: left;
width: 33.33%;
text-align: center;
color: white;
font-family: 'Calibri';
}
.icon {
width: 50px;
height: 25px;
/*half of width*/
margin: auto;
display: block;
border-radius: 50px 50px 0 0;
}
.fa {
margin-top: 10px;
}
.text {
padding: 25px;
}
.strategy .text,
.strategy .icon {
background-color: #5c471c;
}
.crop .text,
.crop .icon {
background-color: #a0a175;
}
.risk .text,
.risk .icon {
background-color: #666666;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<div class="card strategy">
<div class="icon">
<i class="fa fa-area-chart" aria-hidden="true"></i>
</div>
<div class="text">
Our Strategy
</div>
</div>
<div class="card crop">
<div class="icon">
<i class="fa fa-pagelines" aria-hidden="true"></i>
</div>
<div class="text">
Crop Marketing
</div>
</div>
<div class="card risk">
<div class="icon">
<i class="fa fa-arrow-down" aria-hidden="true"></i>
<i class="fa fa-arrow-up" aria-hidden="true"></i>
</div>
<div class="text">
Commodity Risk Management
</div>
</div>
Is the main problem that when you use position your layout changes its position elsewhere?
If so, to use position property is ok if you make a few changes:
CSS
.strategy--logo {
position: absolute;
/* Remove this top parameter, use transform instead */
/* top:383px; */
/* Instead your value of a left use value of 50% and transform left
and right properties like it is changed below */
/* left: 607px; */
left: 50%;
transform: translate(-50%, -100%);
width: 96px; height: 48px;
background-color: #5a471b;
border-top-right-radius: 48px;
border-top-left-radius: 48px;
}
.strategy {
/* add position relative to a parent of strategy-logo */
position: relative;
margin-top: 135px;
background-color: #5a471b;
}
Then your code will stay in the same position even if you resize the screen.
I would like the layout to look as so, but also be responsive (so that the heading + paragraph both stay positioned to the left of the icon).
CSS:
.feature {
position: relative;
border: 1px solid #000;
}
.circle {
height: 2.5rem;
width: 2.5rem;
background-color: #64beeb;
border-radius: 50%;
float: right;
}
.icon {
font-size: 1.75rem;
color: #fff;
}
HTML:
<div class="feature">
<div class="text text-right">
<p class="h2">Diversity of Content</p>
<p class="descrip">Dive deep and share themed content across various topics based on your audience</p>
</div>
<div class="circle text-center">
<i class="icon ion-android-bulb"></i>
</div>
</div>
CODEPEN DEMO
add this to .circle and remove float:right; Then it will be absolutely positioned from the parent relative container.
position: absolute;
top: 10px;
right: 10px;
.feature {
position: relative;
border: 1px solid #000;
}
.circle {
position: absolute;
top: 10px;
right: 10px;
height: 2.5rem;
width: 2.5rem;
background-color: #64beeb;
border-radius: 50%;
}
.icon {
font-size: 1.75rem;
color: #fff;
}
<div class="feature">
<div class="text text-right">
<p class="h2">Diversity of Content</p>
<p class="descrip">Dive deep and share themed content across various topics based on your audience</p>
</div>
<div class="circle text-center">
<i class="icon ion-android-bulb"></i>
</div>
</div>
And you could add padding-right: 50px; to .feature so the icon (blueih circle) will not be over text. See here https://jsfiddle.net/ymzofeph/
One option is to use flexbox. You can add display: flex to the container (.feature). Add flex: 1 to the text. To create some space around the icon you can use a margin value you find suitable.
.feature {
position: relative;
border: 1px solid #000;
/* for demo */
text-align: right;
display: flex;
}
.text {
flex: 1;
}
.circle {
height: 2.5rem;
width: 2.5rem;
background-color: #64beeb;
border-radius: 50%;
margin: 1rem;
}
.icon {
font-size: 1.75rem;
color: #fff;
}
<div class="feature">
<div class="text text-right">
<p class="h2">Diversity of Content</p>
<p class="descrip">Dive deep and share themed content across various topics based on your audience</p>
</div>
<div class="circle text-center">
<i class="icon ion-android-bulb"></i>
</div>
</div>
<div class="feature">
<div class="circle text-center">
<i class="icon ion-android-bulb"></i>
</div>
<div class="text text-right">
<p class="h2">Diversity of Content</p>
<p class="descrip">Dive deep and share themed content across various topics based on your audience</p>
</div>
</div>
<style>
.circle{
float:right;
width:40px;
height:40px;
margin:0 0 0 20px;
}
.text{
overflow:hidden;
}
</style>
Put the float:right div before the .text-right div. Then add padding-right:2.5rem; to the .text-right div.
Example
As the title suggests I'm trying to align my text in my footer to be horizontally center and aligned to the bottom.
Having read other's solutions, I've tried to set the parent div to relative, the p element to absolute, and then bottom: 0;/vertical-align: bottom; But doesn't work.
What happens is that the text moves up into the above div and is no longer horizontally centered.
/*Section3*/
#section3 {
height: 50%;
background: #6ed3cf;
text-align: center;
padding: 0 0 0.5em;
height: 20em;
}
#section3 h2 {
font-size: 2em;
font-weight: 200;
}
#section3 i {
padding: 0.5em;
color: black;
}
/*Footer*/
#footer {
background:#fff;
color: black;
height: 10%;
font-family: 'Open Sans', sans-serif;
position: relative;
display: table;
}
#footer p {
font-size: 0.7em;
text-align: center;
position: absolute;
bottom: 0;
vertical-align: bottom;
}
<div id="section3" style="display:flex;justify-content:center;align-items:center;">
<div>
<h2>header</h2>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<p>blablablablablablablablablablablablablablablablablablablablabla</p>
<i class="fa fa-envelope fa-2x" aria-hidden="true"></i>
<i class="fa fa-linkedin-square fa-2x" aria-hidden="true"></i >
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<div id="footer">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<p>text</p>
</div>
</div>
</div>
</div>
I'm a bit confused about certain properties on your components, but here's what I would do:
Remove position: absolute on your <p> element, and remove the display: table from your <footer>.
Like so:
html {
height: 100%;
box-sizing: border-box;
}
body {
position: relative;
margin: 0;
min-height: 100%;
}
/*Section3*/
#section3 {
height: 50%;
background: #6ed3cf;
text-align: center;
padding: 0 0 0.5em;
height: 20em;
}
#section3 h2 {
font-size: 2em;
font-weight: 200;
}
#section3 i {
padding: 0.5em;
color: black;
}
/*Footer*/
#footer {
background: #fff;
color: black;
height: 10%;
font-family: 'Open Sans', sans-serif;
position: absolute;
width: 100%;
bottom: 0;
}
#footer div {
height: 100%;
}
#footer .row > div {
width: 100%;
display: table;
}
#footer p {
display: table-cell;
font-size: 0.7em;
text-align: center;
bottom: 0;
vertical-align: bottom;
}
<div id="section3" style="display:flex;justify-content:center;align-items:center;">
<div>
<h2>header</h2>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<p>blablablablablablablablablablablablablablablablablablablablabla</p>
<i class="fa fa-envelope fa-2x" aria-hidden="true"></i>
<i class="fa fa-linkedin-square fa-2x" aria-hidden="true"></i >
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<div id="footer">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<p>text</p>
</div>
</div>
</div>
</div>
It worked for me when i gave width:100%; to my footer property. if you do that then the text aligns itself to middle. PS, my reputation doesnt allow me to add a comment...
Please add width style for P element of #footer as following :
#footer p {
font-size: 0.7em;
text-align: center;
position: absolute;
bottom: 0;
vertical-align: bottom;
width:100%; /* added new style */
}
If you have any issue please let me know.
Thanks...
You just try this.
#footer {
background:#fff;
color: black;
height: 10%;
font-family: 'Open Sans', sans-serif;
position: relative;
display: table;
width: 100%;
text-align: center;
}
This is worked for me.
See if this solve your purpose
#section3 {
height: 50%;
background: #6ed3cf;
text-align: center;
padding: 0 0 0.5em;
height: 20em;
}
#section3 h2 {
font-size: 2em;
font-weight: 200;
}
#section3 i {
padding: 0.5em;
color: black;
}
/*Footer*/
#footer {
/* background: #fff; */
/* color: black; */
/* height: 10%; */
/* font-family: 'Open Sans', sans-serif; */
/* position: relative; */
/* display: table; */
background: #6ed3cf;
}
#footer p {
font-size: 0.7em;
text-align: center;
/* position: absolute; */
/* bottom: 0; */
/* vertical-align: bottom; */
margin-top: 0px;
}
<div id="section3" style="display:flex;justify-content:center;align-items:center;">
<div>
<h2>header</h2>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<p>blablablablablablablablablablablablablablablablablablablablabla</p>
<i class="fa fa-envelope fa-2x" aria-hidden="true"></i>
<i class="fa fa-linkedin-square fa-2x" aria-hidden="true"></i >
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<div id="footer">
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<p>text</p>
</div>
</div>
</div>
</div>