I am trying to get two cards beside each other but no matter what I do they end up underneath each other. I have them in the same row, in the same container but it still won't work.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home page</title>
<meta charset="utf-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="search-bar.css" rel="stylesheet">
</head>
<body>
<div class ="container-fluid">
<div class="row">
<div class ="col-2" style="width: 170px;">
<div class="card">
<img src="http://placehold.jp/150x150.png" alt="Avatar" style="height: 150px; width: 150px;">
<div class="container">
<h6><b>John Doe</b></h6>
</div>
</div>
</div>
<div>
<div class="card">
<img src="http://placehold.jp/150x150.png" alt="Avatar" style="height: 150px; width: 150px;">
<div class="container">
<h6><b>John Doe</b></h6>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home page</title>
<meta charset="utf-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="search-bar.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-2" style="width: 170px;">
<div class="card">
<img src="http://placehold.jp/150x150.png" alt="Avatar" style="height: 150px; width: 150px;">
<div class="container">
<h6><b>John Doe</b></h6>
</div>
</div>
</div>
<div>
<div class="card">
<img src="http://placehold.jp/150x150.png" alt="Avatar" style="height: 150px; width: 150px;">
<div class="container">
<h6><b>John Doe</b></h6>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</body>
</html>
Try this,
Some containers removed. Your cards are now in a column each and both columns are inside a row.
col-6 will make the columns 50% width each, you can make them thinner or wider using col-1 to col-12. The cards will also fill that width as long as you do not dictate any card sizes in your CSS!!
Adding class="img-fluid" to the images and removing the styled size you entered will make the images stay at the column width no matter the screen size.
<div class="container-fluid">
<div class="row">
<div class="col-6">
<div class="card">
<img src="http://placehold.jp/150x150.png" class="img-fluid" alt="Avatar">
<h6><b>John Doe</b></h6>
</div>
</div>
<div class="col-6">
<div class="card">
<img src="http://placehold.jp/150x150.png" class="img-fluid" alt="Avatar">
<h6><b>John Doe</b></h6>
</div>
</div>
</div>
</div>
You have two syntax errors:
An extra div closer </div>
and extra body closer </body>
I added class="col" to the second card div
Note by using the forced width on the first column, on small screens you may not see all of that image in columns 1 and 2 set by col-2 you have.
I removed some style= and made classes instead (always try to style wit CSS and classes
We have NO idea what your CSS file does and now this may impact answers negatively. This is the main reason I left some of the markup I would normally NOT do such as the containers around the text on the cards.
.first-column {
width: 170px;
}
.card-image {
height: 150px;
width: 150px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Home page</title>
<meta charset="utf-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="search-bar.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-2">
<div class="card first-column">
<img src="http://placehold.jp/150x150.png" alt="Avatar" class="card-image">
<div class="container">
<h6><b>John Doe</b></h6>
</div>
</div>
</div>
<div class="col">
<div class="card">
<img src="http://placehold.jp/150x150.png" alt="Avatar" class="card-image">
<div class="container">
<h6><b>John Doe</b></h6>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Second example with standard card use
.card-image.card-img-top {
width: 100%;
height: 150px;
}
.card-img-top {
width: 100%;
}
.card-title {
font-weight: bold;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<body>
<div class="container-fluid">
<div class="d-flex">
<div class="card">
<img src="http://placehold.jp/150x150.png" alt="Avatar" class="card-image card-img-top">
<div class="card-body text-center">
<h6 class="card-title">John Doe</h6>
</div>
</div>
<div class="card">
<img src="http://placehold.jp/150x150.png" alt="Avatar" class="card-image card-img-top">
<div class="card-body text-center">
<h6 class="card-title">John Doe</h6>
</div>
</div>
</div>
</div>
</body>
Related
I want to put small images on bootstrap card. Half image will be outside of the card and half image will be inside of the card.
How can fix this?
Here is my code:-
<div class="row">
<div class="col-md-4">
<div class="img">
<img src="assets/images/images/brush.svg">
</div>
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5>Graphic Desiger</h5>
</div>
</div>
</div>
</div>
You can simply have some custom CSS to achieve this. Set your img to position absolute. And some margins to your main div
Demo
img {
margin-top: -50px;
width: 50%;
}
.col-md-4 {
margin-top: 50px;
}
.img {
position: absolute;
margin-left: 10em;
z-index: 999999;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-md-4">
<div class="img">
<img src="https://via.placeholder.com/150">
</div>
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5>Graphic Desiger</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="img">
<img src="https://via.placeholder.com/150">
</div>
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5>Developer</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="img">
<img src="https://via.placeholder.com/150">
</div>
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5>Front End</h5>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="laptop">
<img src="images/laptop.png" alt="" style="width: 16em;">
<p class="laptop-para">Météo Ravageurs Pytosanitaire</p>
</div>
</div>
<div class="col-md-4">
<div class="laptop">
<img src="images/laptop.png" alt="" style="width: 16em;">
<p class="laptop-para">Collecte et transmission de données</p>
</div>
</div>
<div class="col-md-4">
<div class="laptop">
<img src="images/laptop.png" alt="" style="width: 16em;">
<p class="laptop-para">Systèmes Electriques de commande</p>
</div>
</div>
</div>
I have 3 laptop images and paragraphs. I want to center the text inside each images is there any easy way to do that like positioning?
Just use the Laptop image as background of your divs:
background-image: url('./background-image.png');
You are able to adjust its position through the
background-position-x
background-position-y
properties.
You center the text inside the divs via
text-align: center;
Try This:
.laptop {
position: relative;
text-align: center;
}
p {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
color: #000;
text-align: center;
color: #FFF;
background-color: rgba(0,0,0,0.5);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row">
<div class="col-md-4">
<div class="laptop">
<img src="https://www.thinkingtech.in/wp-content/uploads/2017/06/razer-blade-hero-laptop-v2-1.png" alt="" style="width: 16em;">
<p class="laptop-para">Météo Ravageurs Pytosanitaire</p>
</div>
</div>
<div class="col-md-4">
<div class="laptop">
<img src="https://images-na.ssl-images-amazon.com/images/I/81p8pWMLI5L._SX425_.jpg" alt="" style="width: 16em;">
<p class="laptop-para">Collecte et transmission de données</p>
</div>
</div>
<div class="col-md-4">
<div class="laptop">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRxoLOxqQJVbNVeY3w07pF8pK56mJFAgE6Xi_C0GkLuYRtsXE2t" alt="" style="width: 16em;">
<p class="laptop-para">Systèmes Electriques de commande</p>
</div>
</div>
</div>
here is the code for you :
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="utf-8">
<meta name="author" content="Vojtěch Matras">
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
</head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container-fluid img-fluid">
<div class="row">
<div class="col-4"></div>
<div class="col-4" style="max-width: 100%; height: auto;"><img src="5.jpg"></div>
<div class="col-4"></div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-4"><center>you text goes here</center></div>
<div class="col-4"></div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-4" style="max-width: 100%; height: auto;"><img src="5.jpg"></div>
<div class="col-4"></div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-4"><center>you text goes here</center></div>
<div class="col-4"></div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-4" style="max-width: 100%; height: auto;"><img src="5.jpg"></div>
<div class="col-4"></div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-4"><center>you text goes here</center></div>
<div class="col-4"></div>
</div>
</div>
</body>
</html>
you can checkjsut resize the window:https://jsfiddle.net/k3tt2qa4/
I've been trying to make an album images group, But there is a Big gap in the right side and won't be fit without using Padding, But when i use Padding it only fit for my PC resolution and becomes a bigger gap in other resolutions, Also if there is a picture bigger in resolution than the other images it wont resize itself of the main size, I've tried many ways but i just don't understand what should i change the height and width.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</head>
<body>
<div class="cards-deck">
<div class="row">
<div class="col">
<div class="card">
<div class="card-block">
<img src="http://www.publicdomainpictures.net/pictures/90000/t2/csx-train.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-block">
<img src="http://www.publicdomainpictures.net/pictures/90000/t2/csx-train.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-block">
<img src="http://www.publicdomainpictures.net/pictures/90000/t2/csx-train.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-block">
<img src="http://www.publicdomainpictures.net/pictures/90000/t2/csx-train.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-block">
<img src="http://www.publicdomainpictures.net/pictures/90000/t2/csx-train.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-block">
<img src="http://www.publicdomainpictures.net/pictures/90000/t2/csx-train.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-block">
<img src="http://www.publicdomainpictures.net/pictures/90000/t2/csx-train.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-block">
<img src="http://www.publicdomainpictures.net/pictures/90000/t2/csx-train.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
<style>
.card-block {
display: flex;
align-items: center;
padding: 16px;
}
.card {
background-color: transparent;
border-width: 0px;
}
.row {
float: left;
}
</style>
</body>
</html>
Other devices LOOK
https://i.imgur.com/U2LtbFN.jpg
View Code: http://codepen.io/cbgraphics/pen/GrMYKQ
Looking at your code it appears that you are using Bootstrap. There are some built in tags that you didn't take advantage of.
I rebuilt a similar layout using lots of little tweaks to your code.
First - You need to wrap your content in the container class:
<div class="container">
Second - It is better if you put each card in a column div. These will automatically fill in your columns (assuming that the size of your images are all the same. <div class="col-md-3">
Third - I changed the padding to keep the grid spacing consistent.
You do not need to create a new row for each image. The current way you are using Bootstrap is trying to override the default functions and CSS that make it awesome.
More about the Bootstrap grid system: http://getbootstrap.com/css/#grid
I've written a basic code like this for experimental purposes:
<!doctype html>
<html lang='en'>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="./css/bootstrap-theme.min.css">
<style type="text/css">
.pos {
position: relative;
}
.well1, .well2 {
position: relative;
height: 380px;
}
</style>
</head>
<body>
<div class="container pos">
<div class="col-sm-12">
<div class="well"></div>
</div>
<div class="col-sm-6">
<div class="well well1"></div>
</div>
<div class="col-sm-6">
<div class="well well2"></div>
</div>
<div class="col-sm-12">
<div class="well"></div>
</div>
</div>
</body>
</html>
This is the output:
But the same layout doesn't appear in mobile screens.
How can I fix it?
In Bootstrap,the col-xx-x classes are relative to specifics media queries. So here, you'll have to had the class col-xs-6 if you want your 50% column to stay 50% when you are below 767px. Your markup should look like this :
<body>
<div class="container pos">
<div class="col-sm-12">
<div class="well"></div>
</div>
<div class="col-sm-6 col-xs-6">
<div class="well well1"></div>
</div>
<div class="col-sm-6 col-xs-6">
<div class="well well2"></div>
</div>
<div class="col-sm-12">
<div class="well"></div>
</div>
</div>
</body>
I would like to align images in my code to the right, so that I have to boxes, in two rows both aligned to their sides, left and right With text and links under them, I tried alot of Things amongs others, float, but it never worked without some problem
this is my code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,intial-scale=1">
<title>Marko's portfolio</title>
<link href='http://fonts.googleapis.com/css?family=Fredericka+the+Great' rel='stylesheet'>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/jquery-2.1.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<img src="http://placehold.it/100x100" class="img-responsive logo" alt="Responsive image">
</div>
<div class="col-md-6 text-right text-uppercase">
<h1>Name</h1>
<h3>Front-end Ninja</h3>
</div>
</div>
<div class="row">
<div class="col-md-12">
<hr class="line">
</div>
</div>
<div class="row">
<div class="col-md-12">
<img class="img-responsive picture" alt="Responsive image" src="images/ideja.jpg">
</div>
</div>
<div class="row text-center">
<div class="col-md-12">
<h2>Featured Work</h2>
</div>
</div>
<div class="row text-thin text-center">
<div class="col-md-6">
<img src="http://placehold.it/555x300" class="img-responsive" alt="Responsive image" data-toggle="modal" data-target="#project1">
<h3>Appify</h3>
<p>Link to project</p>
</div>
<div class="col-md-6">
<img src="http://placehold.it/555x300" class="img-responsive" alt="Responsive image">
<h3>Appify</h3>
<p>Link to project</p>
</div>
</div>
<div class="row text-thin text-center">
<div class="col-md-6">
<img src="http://placehold.it/555x300" class="img-responsive center-block" alt="Responsive image">
<h3>Appify</h3>
<p>Link to project</p>
</div>
<div class="col-md-6">
<img src="http://placehold.it/555x300" class="img-responsive center-block" alt="Responsive image">
<h3>Appify</h3>
<p>Link to project</p>
</div>
</div>
</div>
and this is css
body { font-family: 'Fredericka the Great', cursive;
}
.display {}
.text-thin{font-size: 14px;
}
.line {border-top-width:0px;height:2px;background-color:rgb(42,35,35);
}
.logo { margin-top:20px;
}
.picture { width:1440px; height:500px;}
Thank you!
you can use margin-left with % like so :
.logo {
margin-top:20px;
margin-left: 40%;
}
for the other images :
.col-md-6 img {
margin-left: 10%;
}
edit regard to your comment you want the image to fit the hole size of the container , so you do like follow :
.col-md-6 img {
width: 100%;
height: 100%;
}
Live demo
I think you should apply a clearfix or just precise overflow of box and set img float right and text in an container float left like:
<div class="col-md-6 clearfix project">
<img src="http://placehold.it/555x300" alt="Responsive image">
<div class="description">
<h3>Appify</h3>
<p>Link to project</p>
</div>
</div>
And css:
.project {
overflow: hidden;
}
.project .description {
float: left;
}
.description {
float: left;
}