I'm using Bootstrap and am using the class col-md-6. On the left column I have an image and on the right column I have two paragraphs of text. When I shrink the web browser (or use mobile), I want the div to expand, instead of using a scroll bar. What ends up happening now is the image shows up fine but I have to use the scroll bar to see the paragraphs of text.
Sorry I'm kind of new to web programming and have spent a considerable amount of time trying to figure out what I'm doing wrong. Not sure if it's relevant but I'm also including the next chunk of code after the issue.
I want it to scroll from pg4 to pg5, but i don't want an additional scrollbar to have to see all the content in pg4.
EDIT: Also feel like I should note that I've seen similar questions posted here and have tried numerous of the answers to these issues and nothing has worked yet.
<div id="pg4">
<div class="container">
<h1 class="text-center text-uppercase">About Me</h1><hr/>
<div class="row">
<div class="col-md-6">
<img src="IMAGE" class="center-block img-responsive" id="picture" alt="Picture" />
</div>
<div class="col-md-6">
<p>PARAGRAPH 1</p>
<p>PARAGRAPH 2</p>
</div>
</div>
</div>
</div>
<div id="pg5">
</div>
/* PG 4 */
#pg4 {
background-color: #282E34;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
width: 100%;
height: 100%;
position: absolute;
display: block;
top: 250%;
overflow: auto;
}
#pg4 p {
color: white;
text-align: left;
font-size: 20px;
margin-left: 3%;
margin-right: 5%;
margin-bottom: 10%;
color: #6c6d6e;
}
#p1 {
margin-top: 15%;
}
#picture {
width: 45%;
margin-top: 15%;
}
/* PG 5 */
#pg5 {
background-image: url("IMAGE");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
height: 100%;
width: 100%;
position: absolute;
top: 350%;
overflow: auto;
}
Try to add additional classes to your divs
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6 col-lg-6">
<img src="IMAGE" class="center-block img-responsive" id="picture" alt="Picture" />
</div>
<div class="col-md-6 col-sm-6 col-xs-6 col-lg-6">
<p>PARAGRAPH 1</p>
<p>PARAGRAPH 2</p>
</div>
</div>
Something like this.
If you do not specify col-xs-? by default bootstrap stacked your divs and it behaves like col-xs-12. Same for large displays. So you need to specify a width for extra small and large displays
And from that part:
#picture {
width: 45%;
margin-top: 15%;
}
remove width: 45% you already defined img-responsive
When you set height and overflow: auto for an element, It means you want this element to be scrollable. If you don't want this, instead of height: 100% set height: auto;
Related
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 build an image-focussed page, where all images resize flexibly within fixed-sized containers. The containers are set up in two rows; the first are three 4-spaced columns each with an image (following bootstrap), and the second row is a 12-spaced column, filled with one image.
Ideally, I want them to show this behavior:
- If they are wider than the container, I want the image to be resized and centered, until the image border meets the container either heightwise or widthwise. Any corresponding spillover will be cut-off.
Overflow already cuts them off; align-self should center them; object-fit covers the image; but I don't know how to make it behave the way as I described above.
Thanks very much for having read this far, and thank you even more if you are willing to help me out ^^
The website
Code:
.img-responsive {
width: auto;
margin-left: auto;
margin-right: auto;
display: block;
position: relative;
align-self: center;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
object-fit: cover;
}
.col-4 {
min-height: 20px;
max-height: 300px;
padding: 0;
overflow: hidden;
}
.col-12 {
min-height: 150px;
max-height: 300px;
padding: 0;
overflow: hidden;
}
<section>
<div class="container-fluid">
<div class="row">
<div class="col-4 hoveropacity">
<img class="img-responsive" src="https://vietnamtravel.guide/wp-content/uploads/2015/04/Banh-Mi-Vietnam.jpg" );>
</div>
<div class="col-4 hoveropacity">
<img class="img-responsive" src="https://s.iha.com/00125194526/Hanoi-municipality-Street-market-in-hanoi.jpeg" );>
</div>
<div class="col-4 hoveropacity">
<img class="img-responsive" src="https://i.pinimg.com/736x/da/86/35/da863581a7524e3260b6ba75a8b08cdb--vietnamese-iced-coffee-coffee-latte.jpg" );>
</div>
</div>
</div>
</section>
<section>
<div class="container-fluid">
<div class="row">
<div class="col-12 hoveropacity">
<img class="img-responsive" src="https://www.vietnamtravelblog.info/wp-content/uploads/2011/05/Vietnam.jpg" );>
</div>
</div>
</div>
</section>
NB: I did look around for answers already given, but I couldn't quite find an answer that worked for me. Please forgive any oversight on my part.
Solved! Thanks to #Kangouroops
Added
object-fit: contain;
width: 100%;
height: 100%;
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'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.