I have an image in which I need to put a button over, the problem is that I don't know how to place the button and automatically re-size and position it when making the browser smaller, right now I have the button in place, but when I re-size the browser to get smaller the button moves, I tried using percentages in the css buy doesn't work, what can I do?
<div id="discover" class="container-fluid">
<div class="row-fluid">
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12 withimg">
<img id="discoveryour" src="img/x.png" class="img-responsive">
</div>
</div>
<div class="row-fluid">
<div id="bttnimg" class="col-lg-12 col-sm-12 col-xs-12 col-md-12">
<form id="start" method="post" action="x.php">
<button class="btn-primary">text</button>
</form>
</div>
</div>
</div>
Css:
.withimg {
width: 100%;
overflow:hidden;
padding: 0px;
margin: 0px;
}
#discover{
position: relative;
}
#bttnimg{
float: left;
position: absolute;
left: 62%;
top: 25%;
max-width: 750px;
}
Ah, the good old "how to overlay stuff on top of a responsive image -- responsively" question.
A little tricky, but not too bad. The tricky bit is how to make the stuff's vertical position responsive when the image size changes.
Fear not, here's one simple way to do this:
HTML:
<div class="img-wrapper">
<img class="img-responsive"
src="http://lorempixel.com/output/people-q-c-1200-400-4.jpg">
<div class="img-overlay">
<button class="btn btn-md btn-success">Button</button>
</div>
</div>
CSS:
.img-wrapper {
position: relative;
}
.img-responsive {
width: 100%;
height: auto;
}
.img-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
}
.img-overlay:before {
content: ' ';
display: block;
/* adjust 'height' to position overlay content vertically */
height: 50%;
}
The img-overlay:before pseudo-class handles the vertical positioning job by pushing the img-overlay div down from the top of the image. In this example, the top of the button will always be 50% down the image (change the height: 50% attribute if you want the button higher or lower).
jsfiddle
To make the button size responsive to window width, you can create a new class for your button. Let's call it btn-responsive (this replaces btn-md in the example above). Then use #media queries to adjust the btn-responsive attributes for different window widths. Something like this:
.btn-responsive {
/* matches 'btn-md' */
padding: 10px 16px;
font-size: 18px;
line-height: 1.3333333;
border-radius: 6px;
}
#media (max-width:760px) {
/* matches 'btn-xs' */
.btn-responsive {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
}
and so forth for other screen widths.
In case you're wondering how to do this with bootstrap 5 (like me), there are new classes that do the trick. For instance, I did this to put a button floating right top over the image (I also use font-awesome but you can use any text/icon you like for the button):
<div class="card">
<img class="card-img-top img-thumbnail" src="someimage.png" alt="alt text">
<div class="card-img-overlay">
<a href="#" class="btn btn-outline-warning btn-sm float-end"
data-bs-toggle="popover" data-bs-content="Edit image" data-bs-trigger="hover focus">
<i class="far fa-edit"></i>
</a>
</div>
<div class="card-body">
<h5 class="card-title">Some title</h5>
<p class="card-text">Some text</p>
</div>
</div>
Check out the official bootstrap documentation for more info.
I have to ask if there's a possibility to replace form tag into another DIV? Then you can just use position: absolute for button. I created fiddle to show how https://jsfiddle.net/1x1pjwk7/
Related
I have issues with my text over my images. The text I have is working when it's in desktop, at least on my computer resolution. But the issue is when I scale it back it doesn't keep up with the images so to say. Any idea how to do so or what is wrong?
HTML:
<div class="col-4 text-center image-capsule mx-auto">
<section class="posters-section">
<a href="/" class="movie-link pop">
<p class="poster-date">Test</p>
<img class="img-fluid poster" data-toggle="popover" src="${app.movie[0].poster}">
</a>
</section>
<h5 class="mt-3">${app.movie[0].title}</h5>
</div>
CSS:
.image-capsule {
width: 33%;
position: relative;
}
.posters-section {
position: relative;
}
.poster {
position: relative;
}
.poster-date {
margin: -5% 26%;
font-weight: bold;
z-index: 100;
background-color: #9c0000;
position: absolute;
width: 51%;
text-align: center;
}
I had an issue similar to this. I fixed this issue by using bootstraps text-center class on the text. This kept them centered in the div holding the picture which kept them together with a picture. Here is an example of what I did.
<div class="margin-intercept shrink-to-necessary-size">
<a href="350_project.html">
<img src="images/IMG_2579.JPG" width="350" height="350">
</a>
<h3 class="picwidth text-center">350 Project</h3>
</div>
This made the text stay centered under the image no matter how the screen shrunk.
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 making a card/grid layout using wells in bootstrap. My problem is that the button needs to always be positioned on the bottom of the well at all times with the well having a fixed height. The button is at the bottom but is also overlapping the text.
body {
background-color: #5C67B6;
}
html,
body {
height: 100%;
padding-top: 70px;
}
.btn-purple {
color: #fff;
background-color: #5C67B6;
border-color: #5C67B6;
position: absolute;
bottom: 30px;
left: 50%;
margin-left: -140px;
}
.btn-purple:hover,
.btn-purple:focus,
.btn-purple:active,
.btn-purple.active,
.open>.dropdown-toggle.btn-purple {
color: #fff;
background-color: #4b5496;
border-color: #4b5496;
}
.customClass {
width: 700px;
max-width: 100%;
margin: 0px auto;
}
.well {
min-height: 280px;
height: auto;
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container content-sm customClass">
<div class="row">
<div class="col-sm-6 col-xs-12">
<div class="well">
<img class="center-block" src="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon#2.png" style="border-radius: 50%;" height="80" width="80">
<h3 style="text-align: center;">Test123</h3> <p>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</p>
<i class="fa fa-sign-in" aria-hidden="true"></i> Join server!
</div>
</div>
</div>
</div>
Make sure to click show full page. The button is overlapping some of the text. What would I need to do to make it so where the text positions itself so where it avoids contact with the button? Changing the height fixes it somewhat, but it needs to stay at this height.
If you wanted each of your well class height to be fixed, You need to move each of your btn-purple class outside of your well class as well. Also, To retain the look of your current layout, Place some of your css property from your well class to your col-sm-12 class (parent container)
Here is a sample jsfiddle to guide you: https://jsfiddle.net/u7ecv316/1/
Note: I've place a col-item class in col-sm-12 then place the btn-purple outside of well class. I've also override the css properties of well class too.
Hope this will guide you well
I have this situation: I want to make a IMG height to be fit with its parent DIV where no height is set. This is the sample code:
.box_NewsList {
width: 100%;
background: #ffa;
overflow: hidden;
display: inline-block;
}
.box_NewsList>img {
height: 100%;
display: inline-block;
}
.box_NewsPreview {
padding: 15px;
width: auto;
}
.box_NewsPreview>.tit_News {
font-size: 1.5rem;
line-height: 1.5rem;
position: relative;
margin: -15px 0 15px;
padding: 15px 0 0;
background: transparent url(../imgs/main_menu_hover.png) no-repeat top left;
}
<div class="box_NewsList">
<img class="pull-left" src="mypicture.jpg">
<div class="box_NewsPreview">
<h1 class="tit_News">MyTitle</h1>
<div class="txt_Abstract">
<p>Long text abstract here</p>
</div>
<button class="btn btn-default btn-rounded pull-right">READ</button>
</div>
<div class="clear"></div>
</div>
How can I make the img height to fit the height of div with box_NewsPreview class?
.box_NewsPreview>.txt_Abstract p{color:#7e7e7e;font-family:Roboto, sans-serif;font-size:1rem;font-weight:300;text-align:justify;}
If I add a height value in box_NewsList like height:300px; it works fine.
If I set height:auto, height:initial, height:inherit or I don't add any height value in that class then I get the IMG in its full size instead of resizing in its parent height.
I think the easiest way to acheive what you want is to use a little jQuery. I dont think it is possible with pure CSS
I have made an example where i set position: relative; on .box_NewsList and position: absolute; on .box_NewsList>img
and the this little script to loop through the images and give padding to the text:
$('.box_NewsList').each(function() {
var imageWidth = $(this).find('img').width();
$(this).find('.box_NewsPreview').css('padding-left', imageWidth + 15);
});
Here is a fiddle
try
<div class="box_NewsList">
<div class="box_NewsPreview">
<img class="pull-left" src="mypicture.jpg" stretch="fill">
<h1 class="tit_News">MyTitle</h1>
<div class="txt_Abstract"><p>Long text abstract here</p></div>
<button class="btn btn-default btn-rounded pull-right">READ</button>
</div>
<div class="clear"></div>
</div>
It looks like <img> was inside news_list not news_preview.
I added stretch to the img, so no matter what it will always stretch to the size of the div :)
I am making a site and using bootstrap 3.3.5. The only problem I am having at the moment is the row/column structure I have is not displaying correctly on mobile.
Here is the link to the project: https://foreverfightermovie.herokuapp.com/#/home
It looks fine so far on a computer browser, but on mobile the ribbons are stacked onto of the middle panel section. Here is the html I am using:
<div class="jumbotron">
<h3 class="text-right" style="margin-right: 100px"> Production status: <b>Pre-Production</b> </h3>
<h1 class="text-center">The official site of <h1>
<div class="container">
<div class="row">
<div class="col-md-3">
<img src="/images/breast-cancer-ribbon.png" width="200" height="400" style="margin-left: 30px"/>
</div>
<div class="col-md-6">
<div class="panel-body text-center px-font" style="background-color: pink">
<br><b><FONT FACE="Lucida Console">FOREVER<br>FIGHTER</FONT></b><br><br>
<h3><i>"In life you can fight forever, but you can't live forever. One is a choice and the other is a guarantee"</i><h3>
</div>
</div>
<div class="col-md-3">
<img src="/images/breast-cancer-ribbon.png" width="200" height="400"/>
</div>
</div>
</div>
<br>
<p class="text-center"><a class="btn btn-primary btn-lg text-center" style="color: #2BDE73">
<img src="/images/kickstarter-logo.png" width="30" height="30"/>
Click for Donation Pledges</a></p>
</div>
Also: Here is the css I am using:
.tab { margin-left: 20px;
margin-right: 20px; }
.imagetab { margin-left: 40px;
margin-right: 40px;}
.para {
text-indent: 40px;
}
.jumbotron {
margin-left: 30px;
margin-right: 30px;
}
html {font-size: 90%;}
div.px-font {
font-size: 110px;
}
Does anyone have any suggestions on how to fix it?
Bootstrap's strength is stacking, but you can override whatever you'd like in your custom CSS. For what you'd like to do I'd use a media query with Bootstrap's built-in breakpoints. Here's a simple example:
#media (max-width: #screen-sm-min) {
/* This is the row containing your main panel and two ribbon divs. */
.main-row {
position: relative;
}
/* Add this to each of your ribbons. The ".left" & ".right" are self-explanatory. */
.ribbon {
position: absolute;
top: 100px;
}
.ribbon.left { left: 0px; }
.ribbon.right { right: 0px; }
/* Resize your images here to fit as you'd like them. */
.ribbon img {
height: 100px;
width: 50px;
}
}
You can find some more info on the queries Bootstrap offers here: http://getbootstrap.com/css/#grid-media-queries