I'm working on my first web dev portfolio and am trying to incorporate the Bootstrap Grid system to the project links. I've searched through Bootstrap's documentation (v4.5), Stack Overflow, and just googling various searches to death. I've tried every solution I've found and am still getting nowhere. The closest I've come to a result is changing all three col-lg-4 to col-lg33. That did create the space, but then the padding looked super weird and it was more space than I needed. Any help would be super appreciated. I'm a but of a noob still.
<section id="projects">
<h2>My Work</h2>
<div class="container">
<div class="row justify-content-around">
<div class="col-lg-4 col-md-6 projects-grid">
<a href="https://briafly27.github.io/TechnicalDocumentAssignment/" target="_blank">
<img class="project-image" src="Images/TechnicalDoc.png" alt="project"/>
<p class="project-title">CSS Technical Document</p>
</a>
</div>
<div class="col-lg-4 col-md-6 projects-grid">
<a href="https://briafly27.github.io/Javascript30DrumKit/" target="_blank">
<img class="project-image" src="Images/JavascriptDrumkit.png" alt="project"/>
<p class="project-title">Javascript Drumkit</p>
</a>
</div>
<div class="col-lg-4 col-md-6 projects-grid">
<a href="https://briafly27.github.io/FirstPersonalSite/" target="_blank">
<img class="project-image" src="Images/FirstPersonalSite.png" alt="project"/>
<p class="project-title">First Personal Site</p>
</a>
</div>
</div>
</div>
</section>
#projects {
background: #3F3F44;
color: #f7f7f7;
font-family: 'Raleway', sans-serif;
height: 100vh;
}
#projects h2 {
text-shadow: 1px 1px #fdcb9e;
text-align: center;
padding: 60px;
}
.projects-grid {
background-color: #fdcb9e;
box-shadow: 5px 8px black;
border-radius: 10px;
padding: 1% 0;
}
.projects-grid:hover {
background-color: #cceabb;
box-shadow: 7px 10px black;
}
.projects-grid a {
text-decoration: none;
color: #3f3f44;
text-shadow: 1px 1px #cceabb;
}
.project-image {
height: 100%;
max-height: 170px;
width: 100%;
max-width: 300px;
border-radius: 10px;
border: 2px solid #cceabb;
display: flex;
margin: 0 auto;
}
.project-image:hover {
border: 2px solid #fdcb9e;
}
.project-title {
font-size: 1.5rem;
font-weight: 700;
padding-top: 8px;
padding-bottom: 4px;
margin: 0;
text-align: center;
}
Bootstrap is adding the column guttering as a 15px padding, by styling the layout there, you are also styling the padding that is the guttering, hence the project grid 'cards' are touching.
For this, to keep the guttering and to ensure nice even columns, I would style a nested div instead.
<div class="col-md-4">
<div class="projects-grid">
<a href="https://briafly27.github.io/TechnicalDocumentAssignment/" target="_blank">
<img class="project-image" src="Images/TechnicalDoc.png" alt="project" />
<p class="project-title">CSS Technical Document</p>
</a>
</div>
</div>
If the guttering is too large, you can change the sass variable (it's set to 30px by default) or you can use .no-gutters to remove all the guttering and add the padding manually to the nested divs.
<div class="row no-gutters">
<div class="col-md-4 p-2">
<div class="projects-grid">
<a href="https://briafly27.github.io/TechnicalDocumentAssignment/" target="_blank">
<img class="project-image" src="Images/TechnicalDoc.png" alt="project" />
<p class="project-title">CSS Technical Document</p>
</a>
</div>
</div>
</div>
I've created this link on Codepen to try understanding better the problem so that we can help you better:
https://codepen.io/maricaldas/pen/ExPKNzM
<section id="projects">
<h2>My Work</h2>
<div class="container">
<div class="row justify-content-around">
<div class="col-lg-3 col-md-6 projects-grid">
<a href="https://briafly27.github.io/TechnicalDocumentAssignment/" target="_blank">
<img class="project-image" src="Images/TechnicalDoc.png" alt="project" />
<p class="project-title">CSS Technical Document</p>
</a>
</div>
<div class="col-lg-3 col-md-6 projects-grid">
<a href="https://briafly27.github.io/Javascript30DrumKit/" target="_blank">
<img class="project-image" src="Images/JavascriptDrumkit.png" alt="project" />
<p class="project-title">Javascript Drumkit</p>
</a>
</div>
<div class="col-lg-3 col-md-6 projects-grid">
<a href="https://briafly27.github.io/FirstPersonalSite/" target="_blank">
<img class="project-image" src="Images/FirstPersonalSite.png" alt="project" />
<p class="project-title">First Personal Site</p>
</a>
</div>
</div>
</div>
</section>
Do you mean you want a space separating the project-grid columns?
If so, the first thing we need to consider is that when we use 3 columns taking 4 spaces each, we're using the full grid, which is 12, and that's why we can't see spaces around those col-lg-4 columns.
Can you please elaborate a little bit more on the result you want to achieve?
Maybe a way to add that space among the columns while using col-lg-4 is to overwrite the bootstrap pre-set width, which is 33.33%.
#media (min-width: 992px) {
.col-lg-4 {
-ms-flex: 0 0 32%;
flex: 0 0 32%;
max-width: 32%;
}
}
Related
I have multiple cards with images inside those cards. I want the images to have rounded corners. The code kind of worked but the rounded corners don't look right.
For the images, I'm just using the Bootstrap class rounded. The images are scaled down but not distorted. This is the CSS for the cards:
.card {
position: relative;
display: flex;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #F5F5F5;
background-clip: border-box;
border: 0.0625rem solid #E5E7EB;
border-radius: 1rem; }
Simplified HTML:
<div class="card border-0 p-3 p-md-3 p-lg-4 mb-3">
<div class="row pb-4 text-left">
<div class="col-1 ps-1">
<h1 class="id-circle">B</h1>
</div>
<div class="col-11">
<span class="description details-text pe-1">Text</span>
</div>
</div>
<div class="row gy-3 mb-1 pb-0">
<div class="col-lg-6 col-md-6 col-sm-6 pb-0">
<div class="row pt-0 pb-0 image-row">
<img class="rounded" src="https://picsum.photos/id/237/300/200">
</div>
</div>
</div>
</div>
Any ideas of what could be happening? Please let me know if more info is needed.
Check below snippet: with your CSS and HTML, in both cases the bootstrap creates a small rounded corner of 4px around the images using .rounded { border-radius: .25rem !important } (Firefox DevTools). In fact, with your HTML (second card), the rounded borders of the image are gone.
Still not showing the unwanted result you are experiencing. Something else in your CSS creates the result.
The odd border radius in the image is not reproducable on Stackoverflow with your code.
I added below CSS to override bootstrap .rounded in my Codepen test and got the same unwanted result. You must have done something similar. However, I still don't see it happening here on SO.
My Codepen: SO74554098
.rounded {
border-radius: 1rem !important;
}
The best option would, indeed, be to create a specific card layout for the images (as OP commented, 'card in a card') and use bootstrap .rounded or a custom class with border-radius set.
.card {
/* added for test */
padding: 1rem; margin: 1rem; outline: 1px solid black;
/**/
position: relative;
display: flex;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #f5f5f5;
background-clip: border-box;
border: 0.0625rem solid #e5e7eb;
border-radius: 1rem;
}
.rounded {
border-radius: 1rem !important;
}
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<h3>only .card > .rounded</h3>
<div class="card">
<img class="rounded" src="https://picsum.photos/id/237/300/200">
</div>
<h3>OP code with full bootstrap CSS (5.0.2)</h3>
<div class="card border-0 p-3 p-md-3 p-lg-4 mb-3">
<div class="row pb-4 text-left">
<div class="col-1 ps-1">
<h1 class="id-circle">B</h1>
</div>
<div class="col-11">
<span class="description details-text pe-1">Text</span>
</div>
</div>
<div class="row gy-3 mb-1 pb-0">
<div class="col-lg-6 col-md-6 col-sm-6 pb-0">
<div class="row pt-0 pb-0 image-row">
<img class="rounded" src="https://picsum.photos/id/237/300/200">
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.3/js/bootstrap.min.js"></script>
</body>
</html>
Try doing
border-radius: 25px;
sometimes rem doesn't work for border radius
I'm looping through some images in my rails app"
<% #attachments.each do |attachment| %>
<div class="img-thumbnail" style="display:inline-block; margin:auto; text-align: center; padding-top: 15px; width: 120px;">
<%=image_tag attachment.images_url(:thumb).to_s %>
<div class="desc">
<%= link_to "Remove", remove_image_path(attachment), data: { confirm: "Are you sure you want to delete this image?" }, :method => :delete, :style => "text-decoration: none !important" %>
</div>
</div>
<% end %>
The images appear inline and they start from the left side which is exactly what I wanted. Now I'm wondering if there is a way I can make the image take up the 100% width only when the screen is smaller?
I created a dummy snippet for help.
.form-border {
padding-bottom: 20px;
padding-top: 20px;
border: 1px solid lightgrey;
border-radius: 8px;
background-color: white;
}
div.desc {
padding: 15px;
text-align: center;
}
<div class="container">
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="container form-border">
<div class="img-thumbnail" style="display:inline-block; margin:auto; text-align: center; padding-top: 15px; width: 120px;">
<img src="pic_trulli.jpg" alt="Italian Trulli">
<div class="desc">Remove</div>
<img src="pic_trulli.jpg" alt="Italian Trulli">
<div class="desc">Remove</div
</div>
</div>
</div>
</div>
</div>
Update A
I followed #agustin answer by doing the doing:
<div class="img-thumbnail" style="display:inline-block; margin:auto; text-align: center; padding-top: 15px; width: 120px;">
<div class="img-fluid">
<%=image_tag attachment.images_url(:thumb).to_s %>
</div>
</div
or
<div class="img-thumbnail" style="display:inline-block; margin:auto; text-align: center; padding-top: 15px; max-width: 100%;;">
<div class="img-fluid">
<%=image_tag attachment.images_url(:thumb).to_s %>
</div>
</div
but I still get the same result:
You have errors in your layout.
Remember that you shouldn't create another .container element inside a col or row element. The correct way is .container > .row> .col, and if you want columns inside a column, then you have to create another .row with .cols inside, but not another container.
The img-fluid class has to be applied to the img element. You will probably want to define the width of the image though.
Check the following snippet. I created two columns with the class col-md-6, which means that, on medium screens (≥768px), those columns will take 50% of the width of the row each. As I didn't define any class with col-sm or col-xs, those columns will take 100% of the width of the row on small screens.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="row">
<div class="col-md-6">
<div class="img-thumbnail">
<img src="https://placehold.it/400x300/" class="img-fluid" alt="Italian Trulli">
<div class="desc">Remove</div>
</div>
</div>
<div class="col-md-6">
<div class="img-thumbnail">
<img src="https://placehold.it/400x300/" class="img-fluid" alt="Italian Trulli">
<div class="desc">Remove</div>
</div>
</div>
</div>
</div>
</div>
</div>
I've different background colors for the different divs. Why does #background only apply, if my screen is xs-sized? On all bigger screens it has #suggestion's color, although #background is a extra defined child of #suggestions.
#suggestion {
background-color: #d9d9d9;
}
div div div.suggestions_button {
width: 100%;
height: 60px;
margin-top: 2%;
margin-bottom: 0.5%;
text-align: left;
background-color: white;
box-shadow: 8px -8px 20px #404040;
}
#background {
background-color: green;
}
<div class="row">
<div class="col-xs-1"></div>
<div id="suggestion" class="col-xs-10">
<div class="suggestions_button" data-toggle="collapse" data-target="#demo1">
<p>Suggestion 1</p>
</div>
<div id="background">
<div id="demo1" class="collapse">
<div id="YouTubeVideo" class="col-sm-12 col-md-6">
<div class="embed-responsive embed-responsive-16by9">
<iframe id="iFrame" src="youtube.com"></iframe>
</div>
</div>
<div id="text" class="col-sm-12 col-md-6">
<p> Wort 1 </p>
</div>
</div>
</div>
</div>
<div class="col-xs-1"></div>
</div>
Your question is not clear to me but all I found out is about the background color in different device sizes.
It works in all breakpoints but there are some points I would like to mention:
1- What ever "cols" you are defining for "xs" will apply to the larger size unless if you define an extra "col" for the other sizes.For example if you define:
<div class="col-xs-1"></div>
this means "col-xs-1 col-sm-1 col-md-1 col-lg-1" unless if you define new cols for them separately.
2- You can use different media queries for defining different properties in different device sizes. what ever that goes outside these queries will apply to mobile "xs".
It is a good link to start with : http://www.w3schools.com/css/css_rwd_mediaqueries.asp
3- I strongly recommend you to use Less or Sass for styling.
4- for defining a class you do not need to write "div div .suggestions_button" you can easily define the class and use it in every "div" you would like to use.
#suggestion {
background-color: yellow;
}
.suggestions_button {
width: 100%;
height: 60px;
margin-top: 2%;
margin-bottom: 0.5%;
text-align: left;
background-color:blue;
box-shadow: 8px -8px 20px #404040;
}
#background {
background-color: green;
}
<div class="row">
<div class="col-xs-1">Hello World </div>
<div id="suggestion" class="col-xs-10">
<div class="suggestions_button"
data-toggle="collapse"
data-target="#demo1">
<p>Suggestion 1</p>
</div>
<div id="background" class="col-xs-12">
<div id="demo1" class="collapse">
<div id="YouTubeVideo" class="col-sm-12 col-md-6">
<div class="embed-responsive embed-responsive-16by9">
<iframe src="http://www.who.com.au/"></iframe>
</div>
</div>
</div>
<div class="col-xs-1">Wort 1</div>
</div>
</div>
</div>
I have a thumbnail gallery and each of the <a> elements have an outline around them, when I click on one of the links, the outline is noticeably shorter (only by a pixel or two but enough to be annoying) than the surrounding elements
link to codepen - http://codepen.io/Davez01d/pen/NxMzYy?editors=1100
here's the html -
<div class="row vert-space-30"><!--row-->
<div id="padding-helper"><!--padding-helper-->
<div class="col-sm-3 col-xs-6 port-tile text-center">
<a class="thumbnail" href="http://codepen.io/Davez01d/full/obyBbz/" target="_blank">
<img src="http://i1155.photobucket.com/albums/p558/Davez01d/Portfolio%20site-Codepen/f043ed05-0df8-42b9-a7b3-57ad6cab5f3b_zpsq2074gko.png" alt="Pomodoro thumbnail"/>
<div class="caption">
<h4>Pomodoro Timer</h4>
<p class="tech-used">JavaScript, jQuery, HTML, Css</p>
</div>
</a>
</div>
<div class="col-sm-3 col-xs-6 port-tile text-center">
<a class="thumbnail" href="http://codepen.io/Davez01d/full/JGvdxX/" target="_blank">
<img src="http://i1155.photobucket.com/albums/p558/Davez01d/Portfolio%20site-Codepen/726c239e-157c-4e4d-8931-77f3a4c9de9c_zpslofzlecy.png" alt="Calculator thumbnail"/>
<div class="caption">
<h4>JavaScript Calculator</h4>
<p class="tech-used">JavaScript, jQuery, HTML, Css</p>
</div>
</a>
</div>
<div class="col-sm-3 col-xs-6 port-tile text-center">
<a class="thumbnail" href="http://codepen.io/Davez01d/full/gPegpd/" target="_blank">
<img src="http://i1155.photobucket.com/albums/p558/Davez01d/Portfolio%20site-Codepen/e9b19619-ed3c-4149-ab15-0a039c59f5a7_zps7vmaslo8.png" alt="Quote generator thumbnail"/>
<div class="caption">
<h4>Random Quote Generator</h4>
<p class="tech-used">jQuery, twitter API</p>
</div>
</a>
</div>
<div class="col-sm-3 col-xs-6 port-tile text-center">
<a class="thumbnail" href="http://codepen.io/Davez01d/full/KVQzwr/" target="_blank">
<img src="http://i1155.photobucket.com/albums/p558/Davez01d/Portfolio%20site-Codepen/cc4d40ed-a085-43d6-9dde-90c59161b023_zps0ppintnt.png" alt="Web sketchpad thumbnail"/>
<div class="caption">
<h4>Web Sketchpad</h4>
<p class="tech-used">jQuery, HTML, CSS</p>
</div>
</a>
</div>
</div><!--padding-helper-->
</div><!--row-->
and the css-
.port-tile a {
z-index: 0;
position: relative;
border-radius: 0;
border: none;
padding: 0;
outline: 3px solid #d63c20;
transition: all .12s ease;
}
.port-tile a:hover {
z-index: 10;
outline: 3px solid #d63c20;
transform: scale(1.12, 1.12);
}
.port-tile a:active, a:focus {
outline: 3px solid #d63c20;
}
Also side-note, I'm finding it hard to find a list of all the bootstrap effects on links, buttons, etc, is there a good resource for this? it would help me out a lot.
It's the a:focus { outline-offset: -2px; } that I believe you're referring to, which causes this:
You could override that with your own style, just set
a:focus {
outline-offset: 0;
}
if you don't have a need for this rule at all. Or, target the specific elements where you wish to remove it.
I need to make divs look like table data, I have used display: table-cell and display: table properties but i didn't get expected layout. I need each row to have same height.
please check below code
.publishers {
margin: 45px 0;
margin-right: 60px;
}
.publishers .col-xs-6:nth-child(odd) .publisher {
margin-right: -10px;
}
.publishers .col-xs-6:nth-child(even) .publisher {
margin-left: -10px;
}
.publishers .publisher {
background-color: #f1efef;
margin-bottom: 10px;
}
.publishers .publisher .media {
padding: 10px;
}
.publishers .publisher .media .media-left img {
width: 128px;
height: 128px;
}
.publishers .publisher .media .media-body h3 {
font-size: 30px;
font-weight: 400;
}
/***** my try *****/
.publishers{
display:table;
}
.publishers .publisher{
display: table-cell;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<section class="publishers">
<div class="row">
<div class="col-xs-6">
<div class="publisher">
<div class="media">
<div class="media-left">
<a style=" height: 131px; display: block;" href="http://www.cengage.com
">
<img style=" height: auto;" src="Publishers/7726f4a3-b23d-4af1-879d-57da2a567bd1.jpg" alt="...">
</a>
</div>
<div class="media-body">
<a href="http://www.cengage.com
"><h3>Cengage</h3></a>
<p class="description">A company that delivers highly..
</p>
</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="publisher">
<div class="media">
<div class="media-left">
<a style=" height: 131px; display: block;" href="http://www.elsevier.com
">
<img style=" height: auto;" src="Publishers/b3723614-ea79-4b24-a9fb-ae0c1da9a3c4.png" alt="...">
</a>
</div>
<div class="media-body">
<a href="http://www.elsevier.com
"><h3>Elsevier </h3></a>
<p class="description">A world’s leading publisher of science and health information serves more than 30 million scientists, students and health and information professionals worldwide
</p>
</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="publisher">
<div class="media">
<div class="media-left">
<a style=" height: 131px; display: block;" href="http://eu.wiley.com/WileyCDA/Section/index.html
">
<img style=" height: auto;" src="Publishers/ff9e4261-36a1-4cd3-bf9c-c169ff8661eb.png" alt="...">
</a>
</div>
<div class="media-body">
<a href="http://eu.wiley.com/WileyCDA/Section/index.html
"><h3>WILEY</h3></a>
<p class="description">Wiley is a global publisher of print and electronic products, textbooks, and other educational materials, for students both undergraduate and postgraduate, specializing in scientific, technical, and medical books and journals; professional and consumer books and subscription services. Wiley has approximately 22,700 active titles and 400 journals, and publishes 2000 new titles in a variety of print and electronic formats each year
</p>
</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="publisher">
<div class="media">
<div class="media-left">
<a style=" height: 131px; display: block;" href="https://www.pearson.com/
">
<img style=" height: auto;" src="Publishers/d18fbae5-1587-4b06-a0e4-8b0b1ec4ab13.jpg" alt="...">
</a>
</div>
<div class="media-body">
<a href="https://www.pearson.com/
"><h3>Pearson</h3></a>
<p class="description">Global leader in educational publishing offers comprehensive range of educational programs, in all subjects, for every age and level of student, from preK-12 through higher education and on into professional life.
</p>
</div>
</div>
</div>
</div>
</div>
</section>
.publishers .row {
display: flex;
}
If you don't need IE9 and below support you can use flex this by default uses align-items: stretch which makes all the children full height
If content is static then u can take height of longest div and assign to all.
If content is dynamic then:
$(document).ready(function() {
var maxHeight = -1;
$('.features').each(function() {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$('.features').each(function() {
$(this).height(maxHeight);
});
});
You could loop through each of the .features, find the max then apply that height to all blocks of the same class.
$(document).ready(function() {
var blockHeights;
blockHeights = [];
$('.features').each(function() {
blockHeights.push($(this).height());
});
$('.features').height(Math.max.apply(Math, blockHeights));
});
If you load your content through ajax or some other method after document ready simply move this into a function and call that when ready.
Probably worth setting a height (or height:auto) on the block as a style incase java script is off or doesn't load correctly, just to ensure the content is always visible.
You were almost there. display:table works. The problem is that your bootstrap is adding float to your divs, which break the table. Add in your css float:none; and it will work. Jsfiddle for example : http://jsfiddle.net/42dy9aLm/