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.
Related
I am coding my first website. I am attempting to create a vertical timeline using Bootstrap 4, where the bar of the timeline is in between two columns. Currently, I cannot place text in the first column and an image directly to the right in the second column. The image is always pushed down to the next row. When I examine the element, I notice a large margin (orange area). How do I remove this?
This is my first post on Stack Overflow. I apologize if this is a bit long.
Thanks!
Relevant Code
<div class="row mt-3 no-gutters">
<div class="col-md-12">
<div class="timeline">
<div class="timeline-item-left">
<div class="col-md-6 text-right p-3 mr-0">
<h3>December 2017</h3>
<h5>Big Basin Redwoods State Park </h5>
Berry Creek Falls Loop | 10 Miles
</div>
<div class="offset-md-6 col-md-6 text-left">
<a href="adventure_images/big_basin.jpg">
<img src="adventure_images/big_basin.jpg" class="img-thumbnail" alt="Big Basin" width="150">
</a>
</div>
</div>
CSS
.timeline {
position: relative;
max-width: 800px;
margin: 0 auto;
}
/* Containers around content */
.timeline-item-left {
padding: 10px 30px;
position: relative;
/* background-image: <img src="adventure_images/spiration_light.png">;
background-repeat: repeat-x; */
background-color: white;
width: 100%;
}
.timeline-item-right {
padding: 10px 30px;
position: relative;
/* background-image: <img src"adventure_images/spiration_light.png">;
background-repeat: repeat-x;*/
background-color: white;
width: 100%;
}
Inspection of Element Screenshot
Website Link (for more detailed inspection)
You can use below css in your style.
.timeline-item-left,.timeline-item-left {display: flex}
and remove class offset-md-6.
Try below
.timeline-item-left {
padding: 10px 30px;
position: relative;
background-color: white;
width: 100%;
display: flex;
}
remove offset-md-6
<div class="offset-md-6 col-md-6 text-left">
I am trying my first Responsive design and have implemented Twitter Boostrap 3. I have got a side where I want to show an article with images and information.
I have created a Panel and inside the Panel I have on the left side a Main Image and Thumbnails below it with a Mouse Over Effect to replace the Main Image and on the right side an information box. Below 768 the two boxes will move below each other. Images can be uploaded, which means they can have different sizes.
I want a fixed height for the Main Image Box (#main-image-container), otherwise I would have a constant jumping, when I use the Mouse Over effect. Of course I also want to keep the ratio of width to height. And the maximum width of the Main Image Box should be the max column width of the left columns and not overlap the Info Box on the right and the Thumbnail Box (#thumb-container) max-width should be the same as the #main-image-container.
It looks like that I have pretty much managed to get it working for <1200 and up around 530 on a landscape image. Above 1199, my picture width overlaps the Info Box and below the 530, the image width is not getting smaller anymore. I am trying to fix this now for a week, but can not find the solution. What do I do wrong here? I hope everybody understands my question and that my Sourcecode below helps.
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">title</h3>
</div>
<div class="panel-body">
<!-- Left Column of Advert -->
<div class="col-md-7 col-sm-7 item_gallery" id="gallery">
<div id="main-image-container" class="text-center">
<div class="main-img-box">
<img src="/uploads/tmp/mainimage.jpg" class="img-responsive" id="main-img" width="400">
</div>
</div>
<div id="thumb-container">
<div class="col-md-3 col-sm-3 col-xs-3 thumb-img-box">
<img src="/uploads/tmp/thumb/thumbimage1.jpg" class="thumbnails">
</div>
<div class="col-md-3 col-sm-3 col-xs-3 thumb-img-box">
<img src="/uploads/tmp/thumb/thumbimage2.jpg" class="thumbnails">
</div>
<div class="col-md-3 col-sm-3 col-xs-3 thumb-img-box">
<img src="/uploads/tmp/thumb/thumbimage3.jpg" class="thumbnails">
</div>
<div class="col-md-3 col-sm-3 col-xs-3 thumb-img-box">
<img src="/uploads/tmp/thumb/thumbimage4.jpg" class="thumbnails">
</div>
</div>
</div>
<!-- Right Column -->
<div class="col-md-5 col-sm-5">
Here is a Bookmark Link
<div class="panel panel-info">
<div class="panel-heading"><strong><span style="font-size:16px;"">
Some Information
</div>
<div class="panel-body">
<ul class="list-group">
<li>lots of infos</li>
<li>more infos</li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4>Description</h4>
</div>
</div>
</div>
</div>
CSS
#main-image-container{
border: 1px solid #ccc;
width: 90%;
max-width: 90%;
height: 452px;
margin-bottom: 35px;
margin-top: 40px;
display: table;
}
.main-img-box{
display: table-cell;
vertical-align: middle;
float: none;
width: 90%;
max-width: 90%;
height: 452px;
}
// below is new
#main-img{
max-height: 450px;
}
#thumb-container{
max-width: 100%;
border: 1px solid #ccc;
margin-bottom: 30px;
display: table;
}
.thumb-img-box{
display: table-cell;
vertical-align: middle;
float: none;
padding: 0 10px 0 10px;
}
#media (max-width: 1199px) {
#main-image-container{
width: 100%;
height: 452px;
}
.main-img-box{
max-width: 100%;
height: 452px;
}
#main-img{
max-height: 452px;
max-width: 100%;
}
#thumb-container{
height:100px;
}
.thumbnails {
margin:0;
padding:0;
}
img {
width: 100%;
}
}
#media (max-width: 767px) {
#main-image-container{
width: 100%;
height: 352px;
}
.main-img-box{
width: auto;
max-width: 100%;
height: 352px;
}
#main-img{
max-height: 352px;
width: auto;
max-width: 100%;
}
#thumb-container{
max-height:100px;
width: 100%;
}
img{
width: 100%;
}
Hi in bootstrap you need to give display as inline-block then only images will be responsive.
img
{
display:inline-block;
width:100%;
}
I am trying to setup my layout on the mobile-first way. In the orange area here I have a link with class="logo". But for some reason the logo does not appear at all.
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 bg bg-blue"></div>
</div>
<div class="row">
<div class="col-xs-12 bg bg-orange">
test
</div>
</div>
<div class="row">
<div class="col-xs-12 bg bg-white"></div>
</div>
<div class="row">
<div class="col-xs-12 bg efrat"></div>
</div>
</div>
And some relevant CSS
.bg-orange {
position: absolute;
top: 3%;
background-color: #f7942e;
height: 25%;
}
.bg-orange a.logo {
background: url(//placehold.it/480X91) no-repeat center;
text-indent: -9999px;
display: inline-block;
max-width: 100%;
}
For the full example please see: here
How can I achieve this?
Thanks
You need to show us some of YOUR's code... But for that. also you must display a as block or something similar for background:url work.
Use this
.bg-orange a.logo {
background: url("http://placehold.it/480X91") no-repeat center;
text-indent: -9999px;
display: inline-block;
width:480px;
height:91px;
margin: 0 auto;
}
I just started using Foundation and I like it a lot. I have a question. I have a design that requires the logo to be horizontally centered, on-top and in between two full divs (see attached picture).
The code below is what I have which seems to work fine but doesn't re-size on screen changes and I was wondering if there was a better way to accomplish this when working with Foundation.
Is there a possible improvement that I could do to better integrate the logo into Foundation? In other words is there a way to integrate the logo in a way that It re-sizes when the screen changes or this is my best option and I would need to re-size it manually for multiple screens?
HTML
<div class="row fullWidth">
<div class="large-12 columns box">
<img src="logo.png" class="logo">
</div>
</div>
<div class="row fullWidth">
<div class="large-12 columns box"> </div>
</div>
CSS
.fullWidth {
width: 100%;
margin-left: auto;
margin-right: auto;
max-width: initial;
position: relative;
}
.logo{
position:absolute;
left: 50%;
top: 20px;
margin-left: -100px;// half-width of logo
z-index: 20;
}
.box{
background-color: #333;
height: 120px;
margin-bottom: 10px;
}
If you know the height of the logo, you can use negative margin-top as well, but you'll probably have to wrap the 2 outer divs with a new div.
HTML:
<div class="outer">
<div class="row fullWidth">
<div class="large-12 columns box">
<img src="logo.png" class="logo">
</div>
</div>
<div class="row fullWidth">
<div class="large-12 columns box"> </div>
</div>
</div>
CSS:
.outer {
width: 100%;
position:relative;
}
.fullWidth {
width: 100%;
margin-left: auto;
margin-right: auto;
max-width: initial;
// position: relative; // REMOVED
}
.logo{
position:absolute;
left: 50%;
top: 50%;
margin-left: -100px;// half-width of logo
margin-top: -100px;// half-height of logo
z-index: 20;
}
You can do the following to make it center
<div class="row fullWidth">
<div class="large-12 columns box">
<img src="logo.png" class="logo">
</div>
<div class="row fullWidth">
<div class="large-12 columns box"> </div>
</div>
</div>
DEMO
Is it the logo that doesn't resize? If so, try this:
.logo{
position:absolute;
left: 50%;
top: 20%;
margin-left: -100px;//half-width of logo
z-index: 20;
}
The logo should be able to resize now.
I'm trying to have a two-column centered layout with Bootstrap 3.1.
I've read this: How do I center a Bootstrap div with a 'spanX' class?, but the content is stil aligned to the left. Here is my HTML:
<div class="row">
<div class="center">
<div class="col-lg-3 gauche">
Left div
</div>
<div class="col-lg-5 corps">
Right div
</div>
</div>
</div>
And my CSS:
body
{
padding: 0;
margin: 0;
}
.corps
{
background-color: white;
}
.contenu
{
margin-top: 5em;
margin-bottom: 1em;
background-color: white;
padding: 1.2em;
padding-left: 1.5em;
}
.center
{
float: none;
margin-left: auto;
margin-right: auto;
}
.gauche
{
background-color: #e6e6e6;
min-height: 200px;
}
Result is here: http://i.imgur.com/5nhZ2WS.png
You would want to use a column offset class. If you are using a stock build of Bootstrap all of the column classes need to add up to 12. Your col-lg-3 and col-lg-5 only add up to 8 so adding a col-lg-offset-2 should fix you up to center. Also, bootstrap has a built in centering class container i personally would use that. See below code:
<div class="container">
<div class="row">
<div class="col-lg-3 col-lg-offset-2 gauche">
Left div
</div>
<div class="col-lg-5 corps">
Right div
</div>
</div>
</div>
Add a container, remove the center div and add two blank col-lg-2 on either side so it adds up to 12 columns:
<div class="container">
<div class="row">
<div class="col-lg-2">
</div>
<div class="col-lg-3 gauche">
Left div
</div>
<div class="col-lg-5 corps">
Right div
</div>
<div class="col-lg-2">
</div>
</div>
</div>
For a scalable solution I recommend:
HTML:
<div class="row">
<div class="center">
<div class="col-lg-3 gauche">Left div</div>
<div class="col-lg-5 corps">Right div</div>
</div>
</div>
SCSS:
.center {
display: flex;
flex-direction: row;
justify-content: center;
.col-* {
display: inline-block;
margin-left: -2px; /* Adjust the value of marging work best with your context */
float: none;
}
}
Now it won't matter how many columns (or types of columns) you put in <div class="center"></div>
Try
.row {
margin:0px auto;
}