how to center my div vertically - html

I've looked around and tried many different solutions, yet none of them worked for me. Basically I am just trying to have my <center> tag aligned vertically, so the margin on the top is always equal to the bottom when resizing. What kind of CSS can I apply to do this?
.modalText {
font-weight: 100;
font-size: 2.5em;
}
.paypalCenterModal {
margin: auto 0;
}
.modalText {
margin: auto 0;
}
.img-responsiveModal {
margin: 30px 0px 30px 0px;
display: block;
width: 100%;
height: auto;
box-shadow: 10px 10px 8px #888888;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 modal3ImgPrev">
<img class="img-responsiveModal" id="myImg3" src='/CMS_Static/Uploads/313864614C6F6F/DJI_0019-Recovered.jpg' />
</div>
<center class="paypalCenterModal">
<h3 class="modalText">Select Options</h3>
<form class="paypalForm" <p>Form Content In Here</p>
</form>
</center>
</div>
</div>

You can easily get this by using Flexbox.
If you are thinking to upgrade your bootstrap to version4 you will get this easily.
And as I see you are not using bootstrap grid col-* and row classes according to doc.
Read Bootstrap3 Grid
Stack Snippet
.v-align-section .row {
display: flex;
align-items: center;
}
.modalText {
margin-top: 0;
}
#media (max-width:767px) {
.v-align-section .row {
flex-direction: column;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="v-align-section">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 modal3ImgPrev">
<img class="img-responsiveModal img-responsive" id="myImg3" src='http://via.placeholder.com/250x350' />
</div>
<div class="col-sm-6">
<form class="paypalForm">
<h3 class="modalText">Select Options</h3>
<p>Form Content In Here</p>
</form>
</div>
</div>
</div>
</div>

You can adjust the bottom values in the class it self. Try the following snippet. Further more you can adjust values with using rem rather than pixel to improve the responsiveness.
.divThatNeedsToBeCenteredVertically {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0px;
margin: auto;
width: 100px;
height: 100px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 modal3ImgPrev">
<img class="img-responsiveModal" id="myImg3" src='/CMS_Static/Uploads/313864614C6F6F/DJI_0019-Recovered.jpg' />
</div>
<center class="divThatNeedsToBeCenteredVertically">
<h3 class="modalText">Select Options</h3>
<form class="col-sm-6 paypalForm">
<p>Form Content In Here</p>
</form>
</center>
</div>
</div>

Why did you use "centre" tag? It has been obsoleted. (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center)
Below is the solution, make sure that the position of the parent div, with class name "row", is not "static" (by default, the position of div is static, you can change it to "relative" or whatever).
.row {
position: relative;
height: 100vh;
}
.divThatNeedsToBeCenteredVertically {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: gray;
}
For more details look at the URL: https://jsfiddle.net/sanqian/y9ftobma/
Here is another example, I recommend you to having a look at it.
https://jsfiddle.net/sanqian/La9m2u8L/

Try adding this CSS Snippet
form{
position : absolute;
transform: translate(-50%,-50%);
top : 50%;
left : 50%;
margin: auto;
}
We are setting the top and left to middle of the form screen

Try this..!
.modalText {
font-weight: 100;
font-size: 2.5em;
margin: auto 0;
}
.img-responsiveModal {
max-width: 100%;
height: auto;
box-shadow: 10px 10px 8px #888888;
}
.row{
display:-ms-flexbox;
-ms-flex-pack:center;
-ms-flex-align:center;
/* Firefox */
display:-moz-box;
-moz-box-pack:center;
-moz-box-align:center;
/* Safari, Opera, and Chrome */
display:-webkit-box;
-webkit-box-pack:center;
-webkit-box-align:center;
/* W3C */
display:box;
box-pack:center;
box-align:center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 modal3ImgPrev">
<img class="img-responsiveModal" id="myImg3" src="https://images-na.ssl-images-amazon.com/images/M/MV5BMjM2ODEzMDUzMF5BMl5BanBnXkFtZTcwNDQ2NzU3OQ##._V1_UY317_CR20,0,214,317_AL__QL50.jpg"/>
</div>
<div class="col-xs-6 paypalCenterModal">
<h3 class="modalText">Select Options</h3>
<form class="paypalForm"><p>Form Content In Here</p></form>
</div>
</div>
</div>
</div>

Related

How to make a split screen with Bootstrap?

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>

Position div to foot of container

I have the following HTML page: https://jsfiddle.net/fk42dw85/
I'd like to position the orange block to the foot of the div container instead of the top. How do I achieve this?
.container {
margin-top: 20px;
margin-bottom: 20px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
<div style="background:url('https://dynaimage.cdn.cnn.com/cnn/q_auto,w_826,c_fill/http%3A%2F%2Fcdn.cnn.com%2Fcnnnext%2Fdam%2Fassets%2F131126191411-strahov-abbey-library.jpg');height:200px;">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-6" style="background:orange">
test
</div>
</div>
</div>
</div>
</div>
</div>
You can see this code https://jsfiddle.net/fk42dw85/97/
You can achieve that with:
position: relative;
bottom: -175px;
.container {
margin-top: 20px;
margin-bottom: 20px;
position: absolute;
bottom: 0;
left: calc(50% - 270px);
}
.parentContainer {
position: relative;
}
Assuming you want an image with a footer related to it. I would suggest you to take the following approach, which is much simpler, let me know if that works for you.
<div class="container">
<div class="image"></div>
<div class="image-footer">
This is the footer of the image
</div>
</div>
.image {
background: url('https://dynaimage.cdn.cnn.com/cnn/q_auto,w_826,c_fill/http%3A%2F%2Fcdn.cnn.com%2Fcnnnext%2Fdam%2Fassets%2F131126191411-strahov-abbey-library.jpg');
height:200px;
}
.container {
margin-top: 20px;
margin-bottom: 20px;
}
.image-footer {
background: orange;
opacity: 0.8;
}
Here is the jsfiddle modified with those changes: https://jsfiddle.net/rdarioduarte/fk42dw85/91/
You could try this solution as well, which avoids the use of absolute positioning
.container {
position: relative;
top: 95%;
transform: translateY(-50%);
}
Adjust the value of the top attribute as you wish to get the desired effect.

HTML adjust four images in CSS box

Good Day, I am trying to align three images in one css box. My goal is to place the logo and button in the right (top and bottom) and two pictures to the left but they are overlapping each other. Also, the reason that I won't compile all of them into one image is that I am planning to use bootstrap to make this intro page responsive. CSS such as position and align does not seem to make it work, any help would be truly appreciated.
div.intro_box {
width: 1000px;
height: 650px;
border: 8px;
border-style: solid;
border-color: #00008B;
background-color: #9e9e9e;
padding: 25px;
margin: auto;
position:relative;
}
.intro_box img {
position: absolute;
}
.adjust_center {
text-align: center;
}
<html>
<head>
<title>Pokemon TCG Western Visayas PH</title>
<link rel="stylesheet" href="intro_page.css">
</head>
<body>
<div class="intro_box">
<div>
<img src="images/l_tcg.png" alt="Empoleon"/>
</div>
<div>
<img src="images/button_enter.png" alt="Empoleon"/>
</div>
<div id="pkmn">
<img src="images/p_empoleon.png" alt="Empoleon"/>
<img src="images/p_gardevoir.png" alt="Gardevoir"/>
</div>
</div>
</body>
</html>
]2
Use css grid. For more detail, I usually look at this page.
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
width: 100%;
min-height: 300px;
}
.leftTop {
grid-column: 1 / 2;
grid-row: 1 / 2;
background: red;
}
.leftBottom {
grid-column: 1 / 2;
grid-row: 2 / 3;
background: green;
}
.right {
grid-column: 2 / 3;
grid-row: 1 / 3;
background: purple;
}
<div class="grid">
<div class="leftTop">
</div>
<div class="leftBottom">
</div>
<div class="right">
</div>
</div>
If you use bootstrap grid (since you said you were already going to use bootstrap for a responsive design). You could do something like this. The code snippet is best viewed full screen mode .
Padding and column widths will need to be adjusted to make it appear exactly the way you want and to make it look better on mobile devices, but this gives it the basic structure.
For more info about bootstrap grids have a look at the Bootstrap Documentation (grid systems)
<html>
<head>
<title>Pokemon TCG Western Visayas PH</title>
<link rel="stylesheet" href="intro_page.css">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6 text-center">
<div class="row">
<div class="col-md-12">
<!-- Logo Image -->
<img src="http://via.placeholder.com/350x150" alt="Empoleon" />
</div>
</div>
<div class="row">
<div class="col-md-12">
<!-- Button Image -->
<img src="http://via.placeholder.com/350x150" alt="Empoleon" />
</div>
</div>
</div>
<div class="col-md-6 text-center">
<div class="row">
<div class="col-md-6">
<!-- Main Image 1 -->
<img src="http://via.placeholder.com/150x350" alt="Empoleon" />
</div>
<div class="col-md-6">
<!-- Main Image 2 -->
<img src="http://via.placeholder.com/150x350" alt="Gardevoir" />
</div>
</div>
</div>
</div>
</div>
</body>
</html>
You say that position and align don't work, but your example doesn't show an attempt to use them. You should be able to style your display elements with position and place them as you wish (for the button and logo which are in divisions of their own, do that on the 'div' elements, as in the example here, not on 'img').
NOTE1: I reduced the container 'div' to make the example displayable here in StackOverflow.
NOTE2: my sample simply scatters the elements to the places you say you want them to be, it doesn't take into account their sizes, so they may still overlap. You will need to play with the sizes and use conditional styling to make your design respond correctly to window size changes (and work both on desktop and mobile).
div.intro_box {
width: 500px;
height: 325px;
border: 8px;
border-style: solid;
border-color: #00008B;
background-color: #9e9e9e;
padding: 25px;
margin: auto;
position:relative;
}
.adjust_center {
text-align: center;
}
#pkmn { position: absolute ; left: 0 ; top : 0 ; }
#button { position: absolute; right: 0 ; top : 0 ; }
#logo { position: absolute; right: 0 ; bottom: 0 ; }
/* you will need additional styles either here or inline to place
the two images within the #pkmn div element, I'm not adding this here */
}
<html>
<head>
<title>Pokemon TCG Western Visayas PH</title>
<link rel="stylesheet" href="intro_page.css">
</head>
<body>
<div class="intro_box">
<div id="logo">
<img src="images/l_tcg.png" alt="Logo"/>
</div>
<div id="button">
<img src="images/button_enter.png" alt="Button"/>
</div>
<div id="pkmn">
<img src="images/p_empoleon.png" alt="Empoleon"/>
<img src="images/p_gardevoir.png" alt="Gardevoir"/>
</div>
</div>
</body>
</html>
You can achieve this without grid system..
<!doctype html>
<html lang="en">
<head>
<style>
body{
margin:0px;
padding:0px;
}
.wrapper{
border:2px solid green;
width:99%;
height:500px;
position:relative;
display:flex;
}
.wrapper .leftWrapper{
width:50%;
display:inline-block;
}
.wrapper .leftWrapper .img1{
position:relative;
top:20px;
}
.wrapper .leftWrapper .img1 img{
width:60%;
}
.wrapper .leftWrapper .img2{
position:absolute;
top:50px;
left:30px;
}
.wrapper .leftWrapper .img2 img{
width:40%;
}
.wrapper .rightWrapper{
width:20%;
display:inline-block;
}
.wrapper .rightWrapper .logo{
position:absolute;
top:0;
right:0;
text-align:right;
}
.wrapper .rightWrapper .logo a img{
width:20%;
height:50px;
border:1px solid #000;
}
.wrapper .rightWrapper .btn{
position:absolute;
bottom:0;
right:0;
text-align:right;
}
.wrapper .rightWrapper .btn a img{
width:20%;
min-width:100px;
height:100px;
border:1px solid #000;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="leftWrapper">
<div class="img1"><img src="images/abstract.jpg" title="img1" alt="img1"/></div>
<div class="img2"><img src="images/ball.png" title="img2" alt="img2"/></div>
</div>
<div class="rightWrapper">
<div class="logo">
<img src="images/defaultlogo.jpg" title="logo" alt="logo"/>
</div>
<div class="btn">
<img src="images/btn.jpg" title="btn" alt="btn"/>
</div>
</div>
</div>
</body>
</html>

Full width background inside Bootstrap container on Safari

I found a post here where the same question was asked before. I implemented the solution suggested there and it works fine with Chrome and Firefox. But when I tested it on Safari and Opera, I ended up with a long horizontal scrollbar. I'm not sure how to fix it since I've already added using overflow-x: hidden to the body. You can see it in action here.
HTML
<div class="container">
<div class="level"></div>
<div class="level purple"></div>
<div class="level"></div>
</div>
CSS
html, body {
overflow-x: hidden;
}
.container {
width:960px;
margin: 0 auto;
border:1px solid black;
}
.level {
height:100px;
background: #bada55;
}
.purple {
position: relative;
background: #663399;
}
.purple:before,
.purple:after {
content: "";
position: absolute;
background: #663399; /* Match the background */
top: 0;
bottom: 0;
width: 9999px; /* some huge width */
}
.purple:before {
right: 100%;
}
.purple:after {
left: 100%;
}
I checked in the link(www.kampuster.com) you shared and found the problem with your code.
Problem:
In file all/themes/bootstrap_kampuster/css/style.css, you have provided width: 9999px; for classes .homeBanner:before, .homeBanner:after and .countUpSection:before, .countUpSection:after which is causing the whole problem and is not the right way to do it.
Suggestion:
Below is the approach I would suggest you to go with.
Here is a pen to better illustrate the suggestion.
.section-first, .section-third {
background-image: url('http://www.kampuster.com/sites/default/files/bannerlogo_babson.jpeg');
background-attachment: fixed;
background-size: cover;
}
.section-first-inner {
background-color: rgba(83, 192, 183, 0.3);
}
.section-first, .section-second, .section-third {
/* this is just to add height inplace of content */
height: 600px;
color: #ffffff;
overflow: hidden;
}
.section-first-inner, .section-second-inner, .section-third-inner {
padding: 20px 20px;
font-size: 18px;
height: 100%;
}
.section-second {
color: #000;
}
<link href="http://cdn.jsdelivr.net/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML</title>
</head>
<body>
<div class="main-container">
<header id="page-header"></header>
<div class="section-first">
<div class="section-first-inner">
<div class="container">
<div class="row">
<div class="col-sm-12">
Your content for section first goes here
</div>
</div>
</div>
</div>
</div>
<div class="section-second">
<div class="section-second-inner">
<div class="container">
<div class="row">
<div class="col-sm-12">
Your content for section second goes here
</div>
</div>
</div>
</div>
</div>
<div class="section-third">
<div class="section-third-inner">
<div class="container">
<div class="row">
<div class="col-sm-12">Your content for section third goes here</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Instead of setting width:960px; on the container try setting view width: width: 100vw;
So the container css will be:
.container {
width: 100vw;
margin: 0 auto;
border:1px solid black;
}
just use .container-fluid class.
<div class="container-fluid" style="background-image:url('xample.jpg')">
<div class="row">
<div class="col-sm-12">
<div class="container">
<div class="row">
<div class="col-sm-12">
your content here
</div>
</div>
</div>
</div>
</div>
Full width background inside Bootstrap container!!
If this is what you want (Example Demo)
Then simply use Relative Lengths :
vw Relative to 1% of the width of the viewport*
vh Relative to 1% of the height of the viewport*
I have only replaced 2 values in your code:
.container {
width:100vw;
}
.purple:after {
width: 100vw; /* some huge width */
}
Code:
<!-- Latest compiled and minified CSS -->
<
link rel = "stylesheet"
href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<!-- jQuery library -->
<
script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" > < /script>
<!-- Latest compiled JavaScript -->
<
script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" > < /script>
html,
body {
overflow-x: hidden;
}
.container {
width: 100vw;
margin: 0 auto;
border: 1px solid black;
}
.level {
height: 100vh;
background: #bada55;
}
.purple {
position: relative;
background: #663399;
}
.purple:before,
.purple:after {
content: "";
position: absolute;
background: #663399;
/* Match the background */
top: 0;
bottom: 0;
width: 100vw;
/* some huge width */
}
.purple:before {
right: 100%;
}
.purple:after {
left: 100%;
}
<div class="container">
<div class="level"></div>
<div class="level purple"></div>
<div class="level"></div>
</div>
Please try this, this is working for me.
add the below css, if doesn't work try adding important to them. And to get full width of container, add container-fluid class to particular container.
html, body {
width: -webkit-fill-available;
overflow-x: hidden;
}

Aligning two content causes content to shrink right away

I am trying to align two content next to each other in a way when the broswer minimizes, the content will not move/shrink/ until the screen touchees the content. I tried to replicated aligning two content close to each other but failed. Whenever the browser shrinks, the image shrinks right away instead of shrinking when the window touches the content. Below is the code I am using,
<div class="prod_section">
<div class="border col-md-6">
<img src="img/land_prod_one.jpg" class="word">
<h2>content1</h2>
</div>
<div class="border col-md-6">
<img src="img/land_prod_two.jpg" class="word">
<h2>content2</h2>
</div>
</div>
.prod_section{
margin: auto;
width: 60%;
padding: 10px;
padding-top:220px;
}
.word{
max-width:100%;
}
Below is an image displaying how I am trying to make the content look. This is in the website called Obey Clothing. If anyone can help out, it would greatly be appreciated. Thank you for your time.
1st, the width of the container is set to 60%, which cause your content to shrink sometime (depend on the size of the img)
2nd, you might want to add clearfix to your container check the two example below in full-page to see the difference.
.prod_section {
margin: auto;
width: 60%;
padding: 10px;
padding-top: 220px;
background: green;
}
.word {
max-width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="prod_section">
<div class="border col-md-6">
<img src="http://via.placeholder.com/150x350" class="word">
<h2>content1</h2>
</div>
<div class="border col-md-6">
<img src="http://via.placeholder.com/150x350" class="word">
<h2>content2</h2>
</div>
</div>
Solution:
.prod_section {
margin: auto;
width: 60%;
padding: 10px;
padding-top: 220px;
background: green;
}
.word {
max-width: 100%;
}
.clearfix:after {
content: " ";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="prod_section clearfix">
<div class="border col-md-6">
<img src="http://via.placeholder.com/150x350" class="word">
<h2>content1</h2>
</div>
<div class="border col-md-6">
<img src="http://via.placeholder.com/150x350" class="word">
<h2>content2</h2>
</div>
</div>