the problem is that my css cards are overlapping, I need the three cards to have space from one another, whilst sitting side by side each other horziontally. I am using bootstrap also and saw a solution online to use float-left float-right to put images side by side, but this has had no effect on my html page when I've refreshed it so far.
.container {
width: 4000px;
margin: auto;
}
.card-white {
background: white;
box-shadow: 0 0 16px rgba(0, 0, 0, 0.1);
border-radius: 50px;
width: 400px;
text-align: center;
padding: 24px;
margin: 20px;
}
.card-white img {
width: 360px;
height: 360px;
object-fit: cover;
border-radius: 4px;
}
<!-- Bootstrap-5 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!-- Body -->
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-3">
<div class="card-white">
<img src="https://via.placeholder.com/200.jpg" class="float-left">
<h3>Film Showreel</h3>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<div class="card-white">
<img src="https://via.placeholder.com/200.jpg" class="float-center">
<h3>Monologue Showreel</h3>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<div class="card-white">
<img src="https://via.placeholder.com/200.jpg" class="float-right">
<h3>Voice reel</h3>
</div>
</div>
</div>
</div>
The error is in your css code.
If you run this without your css it' works perfect.
First of all you don't need to customize the container size in bootstrap like this:
.container {
width: 4000px;
margin: auto;
}
Second, a fixed size can't be responsive like this:
.card-white {
width: 400px;
}
.card-white img {
width: 360px;
}
So try it without fixed-size.
You can manage this without css, only with bootstrap classes in your divs.
<div class="col-xs-12 col-sm-6 col-md-3">
check this, for bootstrap 4:
Toggle floats on any element, across any breakpoint, using our responsive float utilities.
Spacing, Bootstrap includes a wide range of shorthand responsive margin and padding utility classes to modify an element’s appearance.
check this, for bootstrap 5:
Float bootstrap 5
Spacing bootstrap 5
Using flexbox might be a better approach:
https://coder-coder.com/display-divs-side-by-side/
.flex-container {
display: flex;
}
.flex-child {
flex: 1;
border: 2px solid yellow;
}
.flex-child:first-child {
margin-right: 20px;
}
You can refer to: https://getbootstrap.com/docs/4.0/utilities/flex/ for bootstrap.
Related
I searched about bootstrap container class and it seems to me that by default it comes with this grid. But its not giving me all three like shown in this picture its showing me only one when I run this code in browser. I added content inside this.
<div class="container">
<!-- Content here -->
</div>
You need to learn about bootstrap grid system to do this.
Code
.row {
margin-top: 10px;
}
.data-row {
height: 150px;
}
.first, .second-1, .second-2 {
border: solid 1px #6c757d;
border-radius: 5px;
padding: 10px;
text-align: center;
}
.first {
background-color: #daeeff;
}
.second-1 {
background-color: #957bbe;
margin-right: 10px;
}
.second-2 {
background-color: #fae3c4;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col first">
first
</div>
</div>
<div class="row data-row">
<div class="col-10 second-1">
second
</div>
<div class="col second-2">
menu
</div>
</div>
</div>
How can I center a div with 3 .profilebox elements on any screens? and make it responsive?
• Big screens: One row with my 3 elements
• laptop screens: Two rows (2 elements on the first row, 1 element below)
• Tablet and mobile: 3 rows with one element per row vertically align (centered)
You can check what I want here:
HTML:
<div class="container" style="max-width: 1300px;">
<div class="row">
<div class="centerDiv">
<div class="profilebox ">
<div class="profileInfo">
<h3 class="box-shadow">Errore Aethiopia dolorum amni</h3>
</div>
</div>
</div>
</div>
And I have 3 divs .profilebox rendering 3 boxes with my image + title.
CSS :
.centerDiv {
padding-bottom: 200px;
padding-top: 100px;
margin-right: 0 auto;
margin-left: 0 auto;
}
.profilebox {
width: 350;
height: 210;
cursor: pointer;
display: inline-table;
margin-bottom: 100px;
background-image: url("");
background-position: center center;
background-size: cover;
position: relative;
}
.profilebox .profileInfo {
bottom: 0;
height: 50px;
left: 0;
right: 0;
margin: 0 auto;
position: absolute;
width: 88%;
}
With this code, my box is well designed. My img and title are in the right place. The only thing now is to make it centered in any situation.
I am a beginner in web development, some things may not be meaningful in my code right now. thanks a lot for your help.
You can use CSS flexbox
.container{
display:flex;
flex-wrap: wrap;
justify-content: center;
}
.profile-box{
width:500px;
height:300px;
margin:20px;
border:2px solid #000;
}
.profile-box{
position: relative;
}
.profile-box p{
position: absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
margin:0;
}
<div class="container">
<div class="profile-box">
<p>profile box</p>
</div>
<div class="profile-box">
<p>profile box</p>
</div>
<div class="profile-box">
<p>profile box</p>
</div>
</div>
If you would like to use bootstrap, refer the following -
You could simply use the classes col-xl-4 col-lg-6 col-md-6 col-sm-12 as follows -
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-6 col-md-6 col-sm-12">
ProfileBox
</div>
<div class="col-xl-4 col-lg-6 col-md-6 col-sm-12">
ProfileBox
</div>
<div class="col-xl-4 col-lg-6 col-md-6 col-sm-12">
ProfileBox
</div>
</div>
</div>
You will finally get 3 elements on extra large screens, 2 on large & medium screens & 1 on small screens in each row.
To see it live with resizing, check it here.
Note: You don't need to worry about different browsers if you use bootstrap.
I am trying to create a layout that will resize properly, regardless of window size, resolution, etc. Here is what I am trying to do:
html, body {
border: 0px;
margin: 0px;
padding: 0px;
height:100%;
}
.container{
height:100%;
display:table;
width: 80%;
}
.row{
display: table-row;
}
#media (min-width: 992px) {
.row .no-float {
display: table-cell;
float: none;
}
}
.col-md-9 {
background: #A28DFF;
height:100%;
}
.navbar {
margin-bottom: 0;
}
</style>
<div class="container">
<div class ="row " style="border:0px solid red;">
<div class=" no-float" style="border:0px solid green; height:1px;">
<!-- code for my nav bar -->
</div>
</div>
<div class="row">
<div class="col-md-9 no-float" style="padding-top:50px">
<!-- code for my content -->
</div>
</div>
</div>
The problem is, though, that it does not resize properly. If the page becomes too small, the toolbar row and the content row split apart and do not resize with one another and do not stay together. Can anyone help with tips on how to make this layout responsive to resizing?
Here is a jsFiddle: https://jsfiddle.net/4qj7a3bh/13/
So we concluded that you are not very experienced with bootstrap so I made this code for you. Here is the example of how to use bootstrap also you should explore their grid system so you can better understand code. Also you should really avoid targeting bootstrap classes directly unless it's absolutely necessary.
<div class="container mainC">
<div id="toolbar" class="row text-center col-md-10 col-md-offset-1">
<h2>Toolbar section</h2>
</div>
<div id="content" class="row text-center col-md-10 col-md-offset-1">
<h2>Content section</h2>
</div>
</div>
#toolbar {
background: cyan;
}
#content {
background: yellow;
}
Here is codepen so you can see code in action:
https://codepen.io/anon/pen/vWaKxZ
I'm trying to align three background images side by side, ideally with fluidity so that they re-position when my browser window resizes.
I've tried searching for an answer to this problem and thought using CSS properties suited to aligning regular 'img src' elements would work, however they haven't.
Essentially, I have a page with a gallery. Each image has a city name in it's center. Through research, I've decided to assign a background-image property to three separate divs and used the line-height property matching the height of each image so that the city name aligns itself in the center. The background-image technique assists in the alignment of the city name.
Where am I going wrong?
#jumbotron2 {
height: 500px;
width: 100%;
}
#city-container {
width: 100%;
height: 100%;
}
.london-square {
height: 400px;
width: 400px;
background-image: url("tombnb-images/london-400px.jpg")
}
.newyork-square {
height: 400px;
width: 400px;
background-image: url("tombnb-images/newyork-400px.jpg")
}
.sydney-square {
height: 400px;
width: 400px;
background-image: url("tombnb-images/sydney-400px.jpg")
}
.square p {
font-family: 'Slabo 27px', serif;
font-size: 32px;
color: #FFFFFF;
line-height: 400px;
text-align: center;
text-shadow: 0px 0px 10px black;
}
<div id="jumbotron2">
<div id="city-container">
<div class="london-square square">
<p id="text">London</p>
</div>
<div class="newyork-square square">
<p id="text">New York</p>
</div>
<div class="sydney-square square">
<p id="text">Sydney</p>
</div>
</div>
</div>
if you use a percentage width of your divs you have to float them too.
I recommand using this:
#city-container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
flex-warp: wrap;
}
You can use bootstrap. you put your images inside divs.
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-sm-4">
<img class="img-thumbnail" src="http://www.nature.org/cs/groups/webcontent/#web/#giftplanning/documents/media/sample-cga-rates-splash-1.jpg">
</div>
<div class="col-sm-4">
<img class="img-thumbnail" src="http://sharedforfree.com/wp-content/uploads/2013/07/cropped-harrimanToday.jpg">
</div>
<div class="col-sm-4">
<img class="img-thumbnail" src="http://pre02.deviantart.net/f34e/th/pre/f/2015/182/4/f/croatia_nature_pack___sample__2___proref_org_by_proref-d8zgrc2.jpg">
</div>
</div>
Check out this fiddle:
jsfiddle example
<header class="row">
<div class="logo-box col-sm-6 col-xs-12">
<img class="header-logo img-responsive" src="https://s3-us-west-1.amazonaws.com/udacity-content/rebrand/svg/logo.min.svg" alt="udacity logo" />
</div>
<div class="nametag col-sm-6 col-xs-12">
<h1>SIYU WU</h1>
<p class="personal-title">
FRONT-END WEB DEVELOPER
</p>
</div>
</header>
The related style are shown below:
header {
display: flex;
}
.logo-box {
padding-top: 40px;
height: 120px;
}
.header-logo {
width: 300px;
height: 53px;
}
.nametag {
padding-top: 20px;
height: 120px;
}
I'm using bootstrap's framework but it seems not working. The two div each take 50% width no matter the screen size. But if I remove the second div the 1st one will take 100% width at xs size screen.
The bootstrap columns system depends on the display of the .row being block.
By changing it to flex, you've broken it. The children of flex elements have different rules for wrapping.