I have a container with multiple rows and columns inside of it built with Bootstrap. The problem I am experiencing is when the page is resized vertically the elements inside the container overflow on the bottom. Code snippets below:
HTML
<section class='container'>
<!-- Title -->
<section class='row'>
<section class='col-md-12 text-center'>
<img id='logo' src='assets/images/logo.png' alt="Futurama Logo">
<h1 id='game-title' class='page-header text-center'>Hangman</h1>
</section>
</section>
<!-- Game screen -->
<section id='game-screen' class='row'>
<section id='game-left' class='col-md-6'>
<section id='image-area'></section>
</section>
<section id='game-right' class='col-md-6 text-center'>
<section id='top-row' class='row'>
<section id='right-top' class='col-md-12 text-center'>
<h2 class='text-primary'>Press any key to get started!</h2><br><br>
<h4 id='wins'>Wins: <span id='winCount'></span></h4><br><br>
<h2>Current Word</h2>
<h3 id='word'></h3>
</section>
</section>
<section id='bottom-row' class='row'>
<section id='guesses' class='col-md-12'>
<h3>Number of guesses remaining: <span id='guessCount'></span></h3>
</section>
<section id='right-bottom' class='col-md-12'>
<h4>Letters Guessed</h4>
<section id='letters'></section>
<p class='' id='outcome'></p>
<audio id='audio' src='' autoplay="true"></audio>
</section>
</section>
</section>
</section>
CSS
html, body{
height: 100%;
}
body{
background-image: url('../images/city.jpg');
}
.container{
position: relative;
top: 20px;
height: 90%;
background-color: white;
}
#logo{
min-width:50%;
}
#game-title{
font-size: 50px;
letter-spacing: 10px;
transition: letter-spacing 2s;
}
#game-title:hover{
letter-spacing: 50px;
}
.page-header{
margin-top: 0px;
}
#game-screen{
height: 75%;
}
#game-left, #game-right{
height:100%;
}
#image-area{
background-image: url('../images/futurama.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height:85%;
}
#top-row{
border-bottom: 2px solid black;
}
#top-row, #bottom-row{
height: 50%;
}
#word{
letter-spacing: 10px;
}
#guesses{
height:25%;
}
#right-bottom{
height:75%;
}
#letter{
display: inline;
margin: 10px;
font-size: 20px;
}
#outcome{
position: relative;
top: 30px;
font-size: 30px;
}
I have launched this as a Heroku app, if it is easier to discover the issue in Dev tools please use this link:
https://hangman-michael-ryan.herokuapp.com/
try putting overflow:hidden to your section container and it will cope all the element inside of it. hope it helps!
one last thing, you should be using div instead of section when creating elements inside of the section tag. section tag is just for grouping elements and make your code organize.
section.container{
overflow: hidden;
}
Related
I have been trying very hard to make a split screen using Bootstrap. Here's what it looks like when I managed to do it with CSS:
But I need to make it responsive to mobile users so I'm remaking it with Bootstrap. However the image and textbox don't resize for some reason.
By responsive I mean that it should become single row with 2 columns and vice versa depending wether you're on a desktop or mobile.
Edit: Sorry for this sudden change, but I'm now using Bootstap ver5.
#promotion-textbox {
top: 115px;
display: inline-block;
margin-right: 5vw;
left: 55%;
background-color: white;
object-fit: fill;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
#promotion-title {
padding: 10px;
position: static;
color: #23272a;
font-size: 3vw;
overflow: hidden;
display: inline-block;
}
#promotion-button {
width: 40vw;
opacity: 0.8;
left: 75%;
transform: translate(-50%, -75%);
margin-left: auto;
margin-right: auto;
top: 620px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<div class="row">
<!-- First Half -->
<div class="col-md-6">
<img class="img" src="https://via.placeholder.com/100">
</div>
<!-- Second Half -->
<div class="col-md-6">
<div id="promotion-textbox">
<div id="promotion-title">
Duck Zone is the best game of all time, I mean just look at these awesome reviews:<br /><br /> TheP0mp21 Says:<br />- Game is pretty good but it needs a your mum duck that is extremely fat and spawns other ducks.
</div>
</div>
</div>
</div>
A few things, if you are using a library then take advantage of it, use its utility classes, and learn its grid system:
Add vh-100 utility class to your row
Add w-100 h-100 in img tag HTML and in CSS add object-fit: cover
Because you've updated your question from bootstrap-4 to ootstrap-5, to remove the spacing in order to hide the horizontal scrollbar you need to replace no-gutters to g-0
Note: You have a lot of styles that doesn't make sense, such left/top without position
I also I've improved your code
#promotion-textbox {
background-color: white;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
margin-bottom: 20px;
}
#promotion-title {
padding: 10px;
color: #23272a;
font-size: 3vw;
}
#promotion-button {
opacity: 0.8;
border: 2px solid #fff;
color: #fff;
padding: 10px 20px;
background: transparent;
}
img {
object-fit: cover
}
.col-6:last-child {
background: darkgray
}
.promotion-column {
display: flex;
flex-direction: column;
padding: 20px;
align-items: center;
justify-content: center;
height: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="row g-0 vh-100">
<!-- First Half -->
<div class="col-md-6">
<img class="img w-100 h-100" src="https://picsum.photos/300/200">
</div>
<!-- Second Half -->
<div class="col-md-6">
<div class="promotion-column">
<div id="promotion-textbox">
<div id="promotion-title">
Duck Zone is the best game of all time, I mean just look at these awesome reviews:<br /><br /> TheP0mp21 Says:<br />- Game is pretty good but it needs a your mum duck that is extremely fat and spawns other ducks.
</div>
</div>
<button type="button" id="promotion-button">All Projects</button>
</div>
</div>
</div>
You must use responsive image if you want it to be responsive. I also removed gutters from the row.
EDIT: made some improvment, height:100vh is really helpful. Takes exactly the height of the window.
.half {
border: 1px solid red;
height: 100vh;
position: relative;
}
.my-image {
width: 100%;
height: 100%;
}
#promotion-textbox {
top: 115px;
display: inline-block;
background-color: white;
object-fit: fill;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
#promotion-title {
padding: 10px;
position: static;
color: #23272a;
font-size: 3vw;
overflow: hidden;
display: inline-block;
}
#promotion-button {
width: 40vw;
opacity: 0.8;
left: 75%;
transform: translate(-50%, -75%);
margin-left: auto;
margin-right: auto;
top: 620px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="row no-gutters">
<!-- First Half -->
<div class="half col-sm-6">
<img class="img my-image" src="https://picsum.photos/536/354">
</div>
<!-- Second Half -->
<div class="half col-sm-6">
<div id="promotion-textbox">
<div id="promotion-title">
Duck Zone is the best game of all time, I mean just look at these awesome reviews:<br /><br /> TheP0mp21 Says:<br />- Game is pretty good but it needs a your mum duck that is extremely fat and spawns other ducks.
</div>
</div>
</div>
</div>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
To make a split screen (two columns) use .row as parent and .col-md-6 for children. "md" part means that columns will expand to full screen width on medium and smaller screens( you can choose: xxl, xl, lg, md, sm, xs). TO make it fit the screen vertically add min-height: 100vh; for both columns and media query for the break point with min-height: 50vh;
source: https://getbootstrap.com/docs/4.6/layout/grid/
Bootstrap 4 example (works in bootstrap 5 and 4):
CSS:
.img-col{
background: url(https://via.placeholder.com/100) center center no-repeat;
background-size: cover;
}
.min-h-50{
min-height:100vh;
}
#media only screen and (max-width: 767px) {
.min-h-50{
min-height:50vh;
}
}
HTML:
<div class="row">
<div class="col-md-6 img-col min-h-50">
</div>
<div class="col-md-6 bg-dark min-h-50">
<div class="row justify-content-center h-100">
<div class="col-10 align-self-center">
<div class="bg-white p-3">rff</div>
<div class="mt-3 text-center"><button class="btn btn-primary">xxx</button></div>
</div>
</div>
</div>
</div>
I am trying to style the gif by giving it border-radius. However ther gif is smaller than the column itself so border-radius is aplied only to the right side of the gif. Could anyone help me out in applying it to the left side aswell? I dont want to change the background-size: contain!important; because then I will loose the proportions of the gif.
PS. Snippet breakes the row and the gif is in another row but it doesn't matter in this example.
.half-half-image-text {
padding: 70px 0px;
}
.half-half-image-text h1 {
color: #800000;
}
.half-half-image-text .content {
height: 100%;
display: flex;
align-items: center;
padding: 35px 0px;
}
.half-half-image-text .content p {
font-size: 22px;
}
.half-half-image-text .img {
min-height: 320px;
height: 100%;
border-radius: 10px;
}
<!-- begin snippet: js hide: false console: true babel: false -->
<div class="half-half-image-text">
<div class="container" >
<div class="row">
<div class="col-7 col-lg-7" style="padding-right:0">
<div class="content">
<p>At Fluid Automotive, our purpose is to make automotive parts easily accessible for everyone. Working with our partner brands, we aim to retail the highest quality parts, whilst maintaining a high level of customer satisfaction.</p>
</div>
</div>
<div class="col-5 col-lg-5" style="padding-right:0">
<a href="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif" data-gallery="portfolioGallery" class="portfolio-lightbox">
<div class="img customzoom s2" style="background-size: contain!important;box-shadow: none;
background: url('https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif')no-repeat center right;background-size:cover;" alt="Plan rozwoju" title="Plan rozwoju"></div>
</a>
</div>
</div>
</div>
</div>
You could add this style to portfolio-lightbox :
width: 240px;
display: block;
and change min-height:320px; to min-height:240px will solve your problem. Like below :
half-half-image-text {
padding: 70px 0px;
}
.half-half-image-text h1 {
color: #800000;
}
.half-half-image-text .content {
height: 100%;
display: flex;
align-items: center;
padding: 35px 0px;
}
.half-half-image-text .content p {
font-size: 22px;
}
.half-half-image-text .img {
min-height: 240px;
height: 100%;
border-radius: 10px;
}
.portfolio-lightbox {
width: 240px;
display: block;
}
<div class="half-half-image-text">
<div class="container" >
<div class="row">
<div class="col-7 col-lg-7" style="padding-right:0">
<div class="content">
<p>At Fluid Automotive, our purpose is to make automotive parts easily accessible for everyone. Working with our partner brands, we aim to retail the highest quality parts, whilst maintaining a high level of customer satisfaction.</p>
</div>
</div>
<div class="col-5 col-lg-5" style="padding-right:0">
<a href="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif" data-gallery="portfolioGallery" class="portfolio-lightbox">
<div class="img customzoom s2" style="background-size: contain!important;box-shadow: none;
background: url('https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif')no-repeat center right;background-size:cover;" alt="Plan rozwoju" title="Plan rozwoju"></div>
</a>
</div>
</div>
</div>
</div>
Simply use an image tag.
.imgradius {
border-radius: 10px
}
<img class="imgradius" src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/240px-Rotating_earth_%28large%29.gif"></img>
Hello I am just making a base template to help me make a website a lot better, I have just recently started using bootstrap and have noticed that when I resize my browser (for example to a mobile size) it is overlapping on my footer?
Does anyone know why this is happening?
Here are some images of when I add more text or resize:
Like I say I am fairly new to bootstrap and am most likely doing something really stupid which is easy to fix :)
Here is my css:
html, body { height:100% }
nav {
margin: 0;
padding: 0;
}
div {
display: block;
}
.col-centered {
float: none;
margin: 0 auto;
}
.center {
margin-left:auto;
margin-right:auto;
margin: 0 auto;
}
.left {
float: left;
}
.right {
float: right;
}
.container {
width: 100%;
margin: 0;
padding: 0;
height:100%;
background:red;
}
.content {
padding: 5rem 1.5rem;
text-align: left;
height:90%;
width:75%;
margin:0 auto;
background: green;
}
footer {
background: grey;
height:10%;
width:75%;
margin:0 auto;
}
Here is my main HTML:
<div class="container">
<div class="content">
<div class="row">
<div class="col-md-auto col-centered">
<h1>Base Template Title</h1>
<p>Text would go here...</p>
</div>
</div>
</div>
<?php include "footer.php" ?>
EDIT: I forgot to include the footer, if you think that I need to add this for you then please let me know.
Thank you very much for even looking at this post!
EDIT 2:
Here is the code for my footer:
<footer>
<div class="row">
<div class="col-md-auto">
<p class="float-right">Back to top</p>
<p>© 2017 Company, Inc. · Privacy · Terms</p>
</div>
</div>
</footer>
Here is the link to the website:
http://81.131.193.35/
Remove the height of .content
.content {
padding: 5rem 1.5rem;
text-align: left;
width: 75%;
margin: 0 auto;
background: green;
}
and also remove the height of .container
.container {
width: 100%;
margin: 0;
padding: 0;
background: red;
}
I would wrap the footer.php in a pair of divs and apply a row and col-md-auto class to it. It looks like the footer is maybe styled with an absolute or even a static display. This is making the footer not play along with the other divs
<div class="container">
<div class="content">
<div class="row">
<div class="col-md-auto col-centered">
<h1>Base Template Title</h1>
<p>Text would go here...</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-auto">
<?php include "footer.php" ?>
</div>
</div>
</div>
I'm having a tough time keeping my content centered within a certain width on my personal website. I have tried many methods such as setting body to a fix width and my wrapper container to a percentage of that. I have attached a picture of my website here and highlighted where I want my content to be contained in the picture shown
.
I want my content of my website centered within that highlighted area, while at the same time keeping the background to be the full size of the screen.
I realize this may be a simple question for many, but I have spent all day looking for and trying out different methods to do this with no avail.
body {
background-color: #F0f0f0;
text-align: center;
margin-right: 0px;
margin-left: 0px;
}
.wrapper {
text-align: center;
}
.topSection {
height: 300px;
border: solid 5px;
}
.mainAbout {
padding-left: 50px;
padding-right: 50px;
vertical-align: middle;
}
.mainAbout h1 {
font-size: 60px;
font-family: arvo, sans-serif;
margin-bottom: 5px;
}
#leftBrace {
vertical-align: middle;
}
#rightBrace {
vertical-align: middle;
}
.projects {
height: 864px;
border: solid 5px;
margin-top: 2px;
background: #0F1217;
}
.projects h2 {
color: #e6e6e6;
font-family: arvo, sans-serif;
font-size: 50px;
}
<link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet">
<div class="wrapper">
<!---- Wrapper Starts Here --->
<div class="topSection" style="display:block" ;>
<!---- Name Section Starts Here --->
<div id="leftBrace" style="display: inline-block" ;>
<img src="leftbrace.png">
</div>
<div class="mainAbout" style="display: inline-block" ;>
<!--- Main Name and About me Section ---->
<h1> Benjamin Yan </h1>
<p> I am a Senior Year Computer Science student at Sacramento State <br> University, California. I strive to become a professional Web Developer. </p>
</div>
<!--- End mainAbout --->
<div id="rightBrace" style="display: inline-block" ;>
<img src="rightbrace.png">
</div>
</div>
<!--- Wrapper Ends Here --->
<div class="projects">
<h2> Projects </h2>
</div>
<div class="contact">
</div>
</div>
<!--- Wrapper Ends Here --->
<footer>
</footer>
Instead of using background you could style curly-braces using pseudo selector :before and :after, thus it works like font styling, you could use transform:translate to center your intro text container, check below codes.
#box {
width: 100%;
height: 300px;
overflow: hidden;
background: #ccc;
}
#box > .cnt {
width:50%;
text-align: center;
top: 50%;
left: 50%;
position: relative;
transform: translate(-50%, -50%);
}
#box:before {
content:"{";
font-size: 250px;
position: absolute;
top: 0;
left:10%;
}
#box:after {
content: "}";
font-size: 250px;
position: absolute;
top: 0;
right:10%;
}
<div id="box">
<div class="cnt">
<h1> Benjamin Yan </h1>
<p> I am a Senior Year Computer Science student at Sacramento State <br> University, California. I strive to become a professional Web Developer. </p>
</div>
</div>
Apply margin: 0 auto; to your content class. This will work.
You need to make sure add an inner class inside each wrapper and define your desired width. And need to apply margin: 0 auto to the inner. I added demo snippet.If u want specific wrapper full width just remove innerclass that's enough you will get full width. I hope it will help you.
.wrapper {
height: 300px;
width: 100%;
background: orange;
margin-bottom: 20px;
}
.inner {
width: 70%;
margin: 0 auto;
background: pink;
height: 100%;
}
<div class="wrapper">
<div class="inner"></div>
</div>
<div class="wrapper">
<div class="inner"></div>
</div>
<div class="wrapper">
<div class="inner"></div>
</div>
<div class="wrapper">
<div class="inner"></div>
</div>
I have a specific layout that is causing me HUGE headaches. Here is an image:
My goal is to have the "Side panel" ALWAYS equal the height of the container. The "Enrollment Application" section is at 100% height already.
Current Markup
<body>
<div id="container" class="pure-g">
<div class="pure-u-md-1-4 pure-u-1 panel" id="left-panel">
<div class="panel-row">
<div class="panel p">
<div class="inner-panel">
<div class="panel-logo">
"Logo here text"
</div>
</div>
</div>
</div>
<div class="panel-row">
<div class="panel p">
<div class="inner-panel">
<nav class="panel">
</nav>
</div>
</div>
</div>
</div>
<div id="right-panel" class="pure-u-md-3-4 pure-u-1 panel p">
<div class="inner-panel">
<header class="pure-g">
<div class="pure-u-md-1-4 pure-u-1 header-logo">
LOGO Would go here, of course.
</div>
<div class="pure-u-md-3-4 pure-u-1 header-title">
<h1>Consumers Energy</h1>
<h1><strong>CARE 3.0 Program</strong></h1>
<h1>Enrollment Application</h1>
</div>
</header>
<div id="content">
"Enrollment application text..."
</div>
</div>
</div>
</div>
</body>
Current CSS
.panel {
box-sizing: border-box;
height: 100%;
display: table-cell;
}
.panel.p {
padding: 3px;
}
.panel .panel-row {
display: table-row;
}
.panel .inner-panel {
border-radius: 5px;
padding: 10px;
width: 100%;
box-sizing: border-box;
background-color: red;
}
Here is an alternative fiddle to play with: http://jsfiddle.net/3c3tqo3e/ but I really don't want to use a table...
Q How can we stack two divs and make their heights = 100% of parent? The "Logo here.." section will be an auto height.
NOTE I would really prefer an answer that is responsive-friendly. I am using PureCSS for the sections. (This means that absolute positioning is not preferred) Also, strongly prefer just css/html. Thanks!
I have created a demo for you, but it will work on all modern browsers only. and you might have to read flexbox and its demos in details to make your work more meaningful in terms of performance and maintenance.
Also read on calc() here
HTML:
<main>
<aside>
<div class="logo">Logo</div>
<div class="aside-content">Other Content</div>
</aside>
<section>Section</section>
</main>
CSS:
html, body{ height: 100%; }
main{
height: 100%; background: teal; padding: 2em; box-sizing: border-box;
display: flex; flex-direction: row;
}
aside{
height: inherit; margin: 0 1em 0 0; width: 200px;
}
aside .logo{
background: #fff; height: 140px;
}
aside .aside-content{
background: #fff; height: calc(100% - 150px); margin: 10px 0 0 0;
}
main section{
height: inherit; background: #fff; flex-grow: 2;
}
Demo Fiddle: http://jsfiddle.net/vpqqyo9L/1/
Edit:
Here's one for IE9: http://jsfiddle.net/vpqqyo9L/3/