I am making a website with bootstrap. In my jumbotron, I have some text to the left, and an image to the right. On mobile, the image appears on the top instead.
How it looks on desktop:
How it looks on mobile:
The problem is, on mobile, it would be nicer if the image was centered, instead of floated to the right. Is that possible?
HTML:
<div class="jumbotron">
<div class="container" id="main">
<div class="img"
<p id="pic"><img id="pic" src="http://cube.crider.co.uk/visualcube.php?fmt=png&size=800&bg=t&alg=F2%20D2%20L2%20F2%20L2%20F%20U2%20R2%20L%20U%27%20B%20D%27%20F%27%20U2%20L%20D2%20L2%20F2" width="300px" height="300px"></p>
</div>
<h1>Example </h1>
<p>Example Example Example Example Example Example Example</p>
<p>Example Example Example Example Example Example Example</p>
<p>Example Example Example Example Example Example Example</p>
</div>
</div>
CSS:
.img{
float: right;
margin-right: 40px;
margin-bottom: 20px;
display: inline;
}
Example website
The first is to set your image to 'display: inline-block' and then wrap it with an outer div where you set the 'text-align' property to center. The other solution is to make sure your img is a block element (display: block) and then set the margin-right and margin-left to auto.
As the simplest solution. That is: Create a relative div that is placed in the flow of the page; place the base image first as relative so that the div knows how big it should be; place the overlays as absolutes relative to the upper left of the first image. The trick is to get the relatives and absolutes correct.
Try this below code in to your css:
.img{
float: right;
margin-right: 40px;
margin-bottom: 20px;
display: inline;
}
@media (min-width: 320px) and (max-width: 767px) {
.img{
float:none;
display:table;
margin: 0 auto;
}
}
or
@media (max-width: 767px) and (min-width: 320px)
.img {
/* float: none; */
/* display: table; */
margin: 0;
width: 100%;
TEXT-ALIGN: CENTER;
}
first enclose your text in <div>
:
<div id="textwithimg">
<h1>Example </h1>
<p>Example Example Example Example Example Example Example</p>
<p>Example Example Example Example Example Example Example</p>
<p>Example Example Example Example Example Example Example</p>
</div>
then use media queries :
//for mobile
@media (min-width: 400px) and (max-width: 500px) {
.img{
margin-left: auto;
margin-right: auto;
width: 70%;
background-color: #b0e0e6;
}
}
//normal css for any size
.img{
float: right;
margin-right: 40px;
margin-bottom: 20px;
display: inline;
}
#textwithimg{
desplay:inline;
float:left;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With