This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 3 years ago.
I want to display three images in a single so i have written css for that to display images in a single row and center of the block but the problem is one of the image is going slight up.If i write css for that to display at same height it is moving all the three divs.Here is the code for that.
.member1 {
width:250px;
height:200px;
display:inline-block;
margin-right:30px;
}
.member1 + .member1{
width:250px;
height:200px;
display:inline-block;
margin-right:30px;
}
.member2{
width:250px;
height:200px;
display:inline-block;
margin-right:30px;
}
.member-details {
width: 100%;
text-align: center;
}
<div class="member-details">
<div class="member2 clearfix ">
<figure> <img src="http://server.com/bar/image01.png" class="member-image" width="222" height="222"> </figure>
<div class="overlay4">
<div class="overlay3">
<h5>Sr. Advocate </h5>
<p>fgh</p>
</div>
</div>
</div>
<div class="member1 ">
<figure> <img src="http://server.com/bar/image03.png" class="member-image" alt="" width="222" height="222"> </figure>
<div class="overlay4">
<div class="overlay3">
<h5>Advocate </h5>
<p>abc</p>
</div>
</div>
</div>
<div class="member1 ">
<figure> <img src="http://server.com/bar/image02.png" class="member-image" alt="" width="222" height="222"> </figure>
<div class="overlay4">
<div class="overlay3">
<h5>Advocate Member</h5>
<p>XYZ</p>
</div>
</div>
</div>
</div>
Okay, Use bootstrap, and you will able to do design, without any problem,
So i write following code, which may help you have a look.
and this is link of jsfiddle:https://jsfiddle.net/dupinderdhiman/7b5dzp9o/9/
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="container-fluid">
<div class="row">
<div class="col-4"><img src="https://www.gstatic.com/images/branding/product/2x/photos_96dp.png"></div>
<div class="col-4"><img src="https://www.gstatic.com/images/branding/product/2x/photos_96dp.png"></div>
<div class="col-4"><img src="https://www.gstatic.com/images/branding/product/2x/photos_96dp.png"></div>
</div>
</div>
</div>
</body>
</html>
We can't see the images (links are broken) and so the problem. But if you are only trying to display images in a row and centered together, i suggest you to check [CSS Flexbox].(https://www.w3schools.com/css/css3_flexbox.asp)
Related
I'm trying to nest containers with Twitter Bootstrap to achieve the following in this screen shot. In the PSD the bubble image height is 404px. I need this to look good across all devices, so responsiveness is a must and should scale accordingly without overwhelming the screen.Could somebody please point me in the right direction to nail the CSS down for this?
I have added what I've done so far in Bootstrap to make this happen but it is off and need to get the containers right. I've read that containers in bootstrap shouldn't be nested but "can be".
I have nested containers but can't seem to achieve what is in the screen shots with Bootstrap.
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<title>Page Title</title>
</head>
<body>
<div class=".container-fluid">
<div class="row">
<div class="col-lg-12 top">
TOP TRENDING STORY FOR AUGUST 21, 2019
</div>
</div>
<div class="row">
<div class="col-lg-12 bg-top">
<div class="container">
<div class="row">
<div class="col-md-6">
test 1
</div>
<div class="col-md-6">
Test 2
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
CSS
.top{
background-color: #d42222;
color:#FFFFFF;
font-size:23px;
text-align: center;
}
.bg-top{
background:transparent url('../images/background-top.png') no-repeat center center /cover;
}
This needs some styling to get what you want; You can take a look at the left and right margins which are inserted by Bootstrap .container and may want to override them; to get closer to the image you shared, I added some top and bottom margins myself;
Complete working snippet below:
.redBanner {
background: red;
}
.redBanner p {
margin-bottom: 0;
}
.myExternalContainer {
background-image: url("https://www.akberiqbal.com/Jumbo.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-color: lightblue;
padding-bottom: 5%;
}
.myInternalContainer {
margin-top: 10%;
margin-bottom: 10%;
}
.innerMostContainer {
margin: 10%;
}
.innerMostContainer button {
width: 100%;
}
.container {
background: #fff
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container-fluid myExternalContainer">
<div class="row">
<div class="col-lg-12 top redBanner">
<p class="text-center">TOP TRENDING STORY FOR AUGUST 21, 2019</p>
</div>
</div>
<div class="container myInternalContainer">
<h3 class="text-center"> medicare</h3>
<div class="row">
<div class="innerMostContainer">
<div class="row">
<div class="col-lg-12 bg-top">
<img src='https://www.akberiqbal.com/src/images/LinkedIn4.png' class='img-fluid' />
<div class="row">
<div class="col-6">
Author Name
<br/> Published date
</div>
<div class="col-6">
<button type="button" class='btn btn-primary'>Read time</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I am centering an image using bootstrap's center-block class.
<section class="container">
<a href="www.apple.com">
<img class="center-block" src="https://www.apple.com/ac/structured-data/images/open_graph_logo.png?201605191653" width="150px;" height="100px;"/>
</a>
</section>
The only problem is that the links spans the width of the container. How do I restrict the URL to the image?
Working JSFIDDLE
You have to add a container for your image and link to sit inside besides just a section tag. In This way you don't have to modify the container class and you introduce a div to organize and style as you wish. Here is the working code:
<section class="container">
<div style="width:150px;margin-left:auto;margin-right:auto;">
<a class="center-block"href="www.apple.com">
<img class="center-block" src="https://www.apple.com/ac/structured-data/images/open_graph_logo.png?201605191653" width="150px;" height="100px;"/>
</a>
</div>
</section>
Try wrapping another element around your <a> and <img> tags and explicitly centering it via text-align: center; or Bootstrap's text-center class :
<section class="container">
<!-- You can use Bootstrap's text-center class a style="text-align: center;" here -->
<div class='center-block text-center'>
<a href="www.apple.com">
<img src="https://www.apple.com/ac/structured-data/images/open_graph_logo.png?201605191653" width="150px;" height="100px;"/>
</a>
</div>
</section>
Example
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Centered Apple Logo</title>
</head>
<body>
<section class="container">
<div class='center-block text-center'>
<a href="www.apple.com">
<img src="https://www.apple.com/ac/structured-data/images/open_graph_logo.png?201605191653" width="150px;" height="100px;" />
</a>
</div>
</section>
</body>
</html>
The link is an inline element so just use text-center on the container instead..
<section class="container text-center">
<a href="//www.apple.com">
<img class="center-block" src="https://www.apple.com/ac/structured-data/images/open_graph_logo.png?201605191653" width="150px;" height="100px;"/>
</a>
</section>
http://codeply.com/go/bLOmNY1pQZ
If you're referring to the link, as in hovering over any section of the .container will activate the link, rather than just the image, here's the solution:
.container {
text-align: center;
}
.container a {
display: inline-block;
}
This basically gives the link its own dimensions, so it doesn't stretch to fill the parent.
Now, this is a new project, so I need some help.
I have the following code. Please press full screen.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<!DOCTYPE html>
<head>
<title>Stack Overflow Question</title>
<link rel="stylesheet" type="text/css" href="bootstrap.css">
<link rel="stylesheet" type="text/css" href="style/home.css">
<!-- Reference to main CSS Style File-->
<style>
ul {
margin:0 auto;
border-top:2px solid #000;
border-bottom: 2px solid #000;
padding:10px;
text-align: center;
font-family:"montserratlight";
text-transform: uppercase;
}
</style>
</head>
<body>
<div class="container">
<div id = "navigation">
<p>
<ul class="col-md-12">
<!-- MAIN NENU BAR -->
<li><b>Home</b></li>
<li>Why Does This</li>
<li>Not</li>
<li>Work</li>
</ul>
<!-- Unordered lists.-->
</p>
</div>
<div class = "row">
<!-- Declaration of First Row -->
<div class="imageHolder col-md-12 hvr-underline-from-center">
<!-- Image Container as DIV -->
<div class = "imageInside" >
<img id = "imageHomeJPG" src="http://s30.postimg.org/8wav359r5/NYC.jpg" style="width:100%" />
</div>
<!-- Image Link -->
</div>
</div>
<div class="row">
<div class="col-md-6">
<a href="about.html">
<img src = "http://s30.postimg.org/mehrfflwh/Place1.jpg" style="margin-bottom:10px; margin-top:10px; width:100%;"/>
</a>
</div>
<div class="col-md-6">
<a href="about.html">
<img src = "http://s30.postimg.org/iw5rj1l0h/Place2.jpg" style="margin-bottom:10px; margin-top:10px; width:100%;"/>
</a>
</div>
</div>
</body>
</html>
Now, when expanded, this is what the website shows.
However, there is a small gap between both column 6 photos.
<div class="row" style="padding-right:0">
<div class="col-md-6">
IMAGE TAG
</div>
<div class="col-md-6" style="padding-left:0">
IMAGE TAG
</div>
This produced the following -
You can see that the image on the left is bigger on the right and therefore it is not correct.
My question is, how can I make the gap between the two columns smaller (to around 10px) without needing to change the padding? I want to make the images bigger in order to decrease the size of the gap, but I can't seem to find a way!
Thanks.
Make a class :
no-space {
Width: 100% !important;
Margin: 0px !important;
}
Then put this class in next to where col-md-6 is seep rated by a space like this :
Class="col-md-6 no-space"
And there should be no spaces between the photos now.
To actually solve this question too, what I can also do is go to the Bootstrap CSS file and edit the padding-left and padding-right values to equal amounts. Originally, both values are set at
padding-left:15px;
padding-right:15px;
but looking at other examples such as airBnb, their padding is both set at 12.5 so this is also another solution.
I haven't done much html and css lately and I can't figure out why my H1 disappears out of sight when I re-size the browser...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript src="Jquery1_10_2.js"> </script>
<link rel="stylesheet" type="text/css" href="bootstrap.css" media="screen" />
<link rel="stylesheet" type="text/css" href="LogIn_Page.css" media="screen" />
<!-- <script type="text/javascript src="LogIn_Page.js"> </script> -->
</head>
<body>
<div style="margin-top: 15px;text-align: center;" class="navbar navbar-inverse navbar-fixed-top container">
<img src="Logo.png" alt="somesite" style="width:225px; height:100px; text-align:center; margin-right:5px">
<img src="somesite_logo.png" alt="somesite" style="width:225px; height:100px; text-align:center;margin-right:5px; margin-left:5px;">
<img src="somesite.png" alt="somesite" style="width:225px; height:100px; text-align:center; margin-left:5px;">
</div>
<div class="container body-content" style="margin-top: 125px;">
<div class="row">
<div class="col-md-12">
<H1 style="margin-bottom: 50px;">Welcome to the Crops web application</H1>
<P>Please login:</P>
<button onclick="window.location.href="/auth"" >Login link</button>
</div>
</div>
</div>
<div id="footer">
<footer>
<script>window.onload = function() {
var d = new Date();
var n = d.getFullYear();
document.getElementById("date").innerHTML = "© " + n + " My company";}</script>
<p id="date"></p>
</footer>
</div>
</body>
</html>
The three images stack on top of each other like they are supposed to, but its just the H1 tag that dispersal totally. I haven't even used any custom css, except for the default bootstrap package.
Could someone point me out to the right solution?
I tried putting inside the H1 tag the following styles: position, float, height, width, min-height, min-width, but none of those seem to work out for me it just keeps disappearing when I size down the browser to the max. Its there when the browser is full screen of course....
You can add position: relative to your navbar.
.navbar.navbar-inverse {
position: relative;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div style="margin-top: 15px;text-align: center;" class="navbar navbar-inverse navbar-fixed-top container">
<a href="http://somesite.com/" title="Web Site">
<img src="Logo.png" alt="somesite" style="width:225px; height:100px; text-align:center; margin-right:5px">
</a>
<a href="http://www.somesite2.org/" title="Web Site">
<img src="somesite_logo.png" alt="somesite" style="width:225px; height:100px; text-align:center;margin-right:5px; margin-left:5px;">
</a>
<a href="http://somesite3.com/" title="somesite Web Site">
<img src="somesite.png" alt="somesite" style="width:225px; height:100px; text-align:center; margin-left:5px;">
</a>
</div>
<div class="container body-content">
<div class="row">
<div class="col-md-12">
<h1 style="margin-bottom: 50px;">Welcome to the Crops web application</h1>
<p>Please login:</p>
<button onclick="window.location.href="/auth"">Login link</button>
</div>
</div>
</div>
It's not disappearing, it just goes off the screen cause of it's huge size.
Try using #media (max-width: _px) in CSS to change the position and text size of theh1` accordingly:
#media (max-width:300px){
h1{
text-size: _px/em/%;
<more styles here>
}
}
So when the screen is less than 300px, it'll style the h1 to whatever you put in there.
It's not disappearing, it's just covered by the navbar. You need to add more margin for when the navbar elements stack up and expand the navbar. For example
<div class="container body-content" style="margin-top: 300px;">
will make it appear. However you need to actually put it in a media query. With your fixed image widths those queries to add to the styles section would be
#media (max-width: 732px) {
.body-content {
margin-top: 225px !important;
}
}
#media (max-width: 499px) {
.body-content {
margin-top: 325px !important;
}
}
Okay everybody so basically what's going on is I have my site setup so far with a top portion with my logo then in the middle i want three boxes. I can get the one on the left to go to the left underneath the top just where I want it same with the second. But the third when I use float right he wont line up like I told him to. Can someone please me out with this? Would really appreciate it!enter code here
fiddle here
<DOCTYPE! HTML>
<html>
<head>
<meta charset="utf-8" />
<title>Welcome</title>
<link rel="stylesheet" href="css/first.css" />
<link rel="stylesheet" href=css/animations.css />
<link href='http://fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="wrap">
<div class="top_portion">
<div class="logo">
<img src="img/2a685fsaq.png"/>
</div>
</div>
<div class="center">
<div class="cleft_portion">
</div>
<div class="mid_portion">
</div>
<div class="cright_portion">
</div>
</div>
</div>
</body>
</head>
</html>
Your .mid_portion is not floated. should also need to be floated left.
you need to put your right container before your middle one like this :
<div class="center">
<div class="cleft_portion">
</div>
<div class="cright_portion">
</div>
<div class="mid_portion">
</div>
</div>
A better solution would be to avoid floats and use display:table
see demo here
HTML
<div class="center" style="display:table">
<div class="cleft_portion" style="display:table-cell">
</div>
<div class="mid_portion" style="display:table-cell">
</div>
<div class="cright_portion" style="display:table-cell">
</div>
</div>
I have removed the floats and added table display...its better if you are looking for IE8+ browsers!!
try this one
.cleft_portion {
position:relative;
height:400px;
width:400px;
background-color:#3fb9a7;
float:left;
}
.mid_portion {
position:relative;
height:400px;
width:400px;
background-color:#55948b;
float:left;
}
.cright_portion {
position:relative;
height:400px;
width:400px;
background-color:#3fb9a7;
float:right;
}
http://jsfiddle.net/v4YwC/2/