Why is the margin not fitting into the div? - html

My button margin isn't fitting into my div. Here's the relevant HTML and CSS.
.card {
justify-content: flex-start;
box-shadow: 0 4px 8px 0 rgb(0 0 0 / 20%);
margin: 8px;
}
.card {
margin-bottom: 16px;
padding: 0px 8px;
float: left;
}
.button {
border: none;
padding: 8px;
color: white;
background-color: black;
text-align: center;
cursor: pointer;
width: 100%;
}
.button:hover {
background-color: #555;
}
.title {
color: grey;
}
.container {
padding: 0px 16px;
}
.card > img {
width: 100%;
}
<div class="ccard">
<div class="card">
<img src="https://pbs.twimg.com/profile_images/1115280588322295808/N1mHLfHy_400x400.png" alt="Jane">
<div class="container">
<h2>Jane Doe</h2>
<p class="title">CEO & Founder</p>
<p>Jane has had 9 years of experience in the tech industry and knows it like the back of her hand. She's very warm and welcoming towards new customers.</p>
<p>janedoe#cabbagedude.com</p>
<p>
<button class="button">Contact</button>
</p>
</div>
</div>
</div>
It has always worked for me before, but it doesn't work now. I also haven't changed anything, except by adding the class ccard around card.
Here's what it looks like for me.

You need to add box-sizing: border-box; to all relevant elements in order to include borders and paddings (I suppose you mean those, since you don't have any margin on the button) in the given width, otherwise they are added to the width, which causes overflow if the width is 100%.

Related

How to resize a div in html/css

I have a nice looking card, I want to make it a little bit smaller.
:root {
--links: yellow;
}
#header {
text-align: center;
}
#links {
text-align: center;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
border-radius: 5px;
/* 5px rounded corners */
}
img {
border-radius: 5px 5px 0 0;
}
.container {
padding:
<div class="card" button data-autobuy-product="62011137-f68d-4855-6346-08d8082eae6a">
<img src="onetap_master.jpg" alt="Avatar" style="width:100%">
<div class="container">
<h4><b>Onetap Master Config</b></h4>
<p>Receive the config, lifetime updates & premium javascripts</p>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css#latest/dist/dark.min.css">
<script src="https://autobuy.io/js/embed.min.js"></script>
The card is width wise just a bit to long and I'm wondering if it's possible to make it either more narrow or just smaller in general
Handle it with percentages?
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
border-radius: 5px; /* 5px rounded corners */
width: 50%;
}
Like this?
<div class="card" button data-autobuy-product="62011137-f68d-4855-6346-08d8082eae6a">
<img src="onetap_master.jpg"alt="Avatar" style="width:100%">
<div class="container">
<h4><b>Onetap Master Config</b></h4>
<p>Receive the config, lifetime updates & premium javascripts</p>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css#latest/dist/dark.min.css">
<script src="https://autobuy.io/js/embed.min.js"></script>
<style>
:root {
--links: yellow;
}
#header {
text-align: center;
}
#links {
text-align: center;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
border-radius: 5px; /* 5px rounded corners */
width: 40%;
height: 35%;
}
img {
border-radius: 5px 5px 0 0;
}
.container {
padding:
</style>
This is a Bootstrap card. You can resize it using these resize options from Bootstrap:
Card Sizing
Give the card class a width what you want, it will resize the card. And give the image fixed height.
:root {
--links: yellow;
}
#header {
text-align: center;
}
#links {
text-align: center;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
border-radius: 5px; /* 5px rounded corners */
width: 500px;
}
img {
border-radius: 5px 5px 0 0;
}
.container {
padding: 10px;
}
<div class="card" button data-autobuy-product="62011137-f68d-4855-6346-08d8082eae6a">
<img src="https://source.unsplash.com/random" alt="Avatar" style="width:100%; height: 300px;">
<div class="container">
<h4><b>Onetap Master Config</b></h4>
<p>Receive the config, lifetime updates & premium javascripts</p>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css#latest/dist/dark.min.css">
<script src="https://autobuy.io/js/embed.min.js"></script>
Your Q is very "wrong" - This issue not related specifically to this card.
The card is a simple div. div is a block element:
block-level element occupies the entire space of its parent element
(container)
https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
.card {
width: 25%;
}
or
.card {
width: 100px;
}
Now what? (How to add more cards one next to each other? How to make this responsive...)
My advice to you is to follow some basic HTML-CSS course and later learn about CSS layout (Flexbox & CSS grid).
Card Height & Overflow
Fixed height (300px, 30% or 20em) may cause overflow issues("content overflows an element's box") .
Some solutions: Use min-height instead of height -or- define overflow property.
<div style="background:red; height: 60px;">
<p>text overflow issue</p>
<p>text overflow issue</p>
<p>I am out of the card</p>
</div>
You can use the width property in your CSS to resize the height of your div.
.card {
width: [specify width here];
}
width can be specified using px,cm, %, etc, according to your needs. You can read more here.

<div> padding auto increasing when using table-cell

I created two tables using table,table-cell. But when I increase padding on first cell it also increasing padding on second cell also vice versa. What is the reason and how to solve it.
.desc-one{
width: 100%;
margin-bottom: 20px;
display: table;
}
.desc-one-one{
width: 350px;
background-color: #ffffff;
display: table-cell;
padding-right: 10px;
border-radius: 10px;
vertical-align: top;
box-shadow: 0px 2px 1px #888888;
}
.quick-heading{
font-size: 20px;
font-family: opensans-semibold;
color: #2199e8;
padding-left: 10px;
padding-top: 5px;
}
.row-two-one{
max-width: 1200px;
border-radius: 10px;
background-color: #ffffff;
box-shadow: 0px 2px 1px #888888;
}
.desc-one-two{
display: table-cell;
padding-left: 20px;
}
.recent-heading{
color: #2199e8;
font-size: 20px;
font-family: opensans-semibold;
}
<div class="desc-one">
<div class="desc-one-one">
<h1 class="quick-heading">
Quick links
</h1>
</div>
<div class="desc-one-two">
<div class="row-two-one">
<h1 class="recent-heading open-semibold">
Low Stock Distributors
</h1>
</div>
</div>
</div>
In CSS code: If I increase padding-top / padding-bottom of my first table cell heading, the second cell elements also taking the padding mentioned in first cell (vice versa)
I have tried your code and found that only the first heading gets the padding top. Maybe you have another bit of code on your page somewhere that is adding this extra padding.
.desc-one {
width: 100%;
margin-bottom: 20px;
display: table;
}
.desc-one-one {
width: 350px;
background-color: #ffffff;
display: table-cell;
padding-right: 10px;
border-radius: 10px;
vertical-align: top;
box-shadow: 0px 2px 1px #888888;
}
.quick-heading {
font-size: 20px;
font-family: opensans-semibold;
color: #2199e8;
padding-left: 10px;
padding-top: 100px;
}
.row-two-one {
max-width: 1200px;
border-radius: 10px;
background-color: #ffffff;
box-shadow: 0px 2px 1px #888888;
}
.desc-one-two {
display: table-cell;
padding-left: 20px;
}
.recent-heading {
color: #2199e8;
font-size: 20px;
font-family: opensans-semibold;
}
<div class="desc-one">
<div class="desc-one-one">
<h1 class="quick-heading">
Quick links
</h1>
</div>
<div class="desc-one-two">
<div class="row-two-one">
<h1 class="recent-heading open-semibold">
Low Stock Distributors
</h1>
</div>
</div>
</div>
Your code works just fine, as the other answers say..
However, in one comment you remark that it works the way you describe if you remove the vertical-align:top from the style of the first cell.
Then why did you have this property in there in the first place? It confuses the matter to people who want to answer.
The answer is, if you don't specify any vertical-align property, it defaults to 'baseline`. That means that both cells align their contents to one another, on the bottom of the first line of text in each of them. That's simply how table cells behave; they work together.
The solution, therefore, is to put vertical-align:top in, which causes the cells to align their contents to their tops.

Settings a border around several divs

I am trying to make a product summary box for the following page:
I was playing around to set the border on the following divs:
<div style="border:1px solid black;" class="inner">
<div style="padding-bottom: 14px;border:1px solid black;" class="title">
The result looks like the following:
I would like to let it look like that:
Any suggestions how to set the divs properly? Or would it be better to design a backgroud image to fit the box?
I appreciate your replies!
You could use a tableinstead of DIVs whose cell borders you make visible.
Or use display: table , display: table-row and display: table-cell for the DIVs, again defining a border for the cell elements.
This is a 5-minute CSS solution:
* {
box-sizing: border-box;
font-family: sans-serif;
}
.product {
border: 2px solid #999;
border-radius: 2px;
width: 20em;
}
.product--header,
.product--image,
.product--rating {
width: 100%;
border-bottom: 2px solid #999;
}
.product--header h2, .product--header h3 {
text-align: center;
padding: 0.25em 0 0.5em;
margin: 0;
}
.product--image img {
width: 100%;
padding: 0.25em;
z-index: 1;
}
.product--image {
position: relative;
}
.product--pricetag {
position: absolute;
z-index: 2;
left: 0;
top: 1em;
color: white;
background: rgba(0, 0, 0, 0.75);
text-align: center;
width: 40%;
padding: 0.5em;
}
.product--rating p {
text-align: center;
}
.product--links {
width: 100%;
margin: 0.5em;
}
.product--links a.btn {
display: block;
color: white;
background: blue;
text-align: center;
width: 90%;
margin-left: 2.5%;
padding: 0.5em;
margin-bottom: 0.25em;
}
<div class="product">
<div class="product--header">
<h2>Test Product</h2>
<h3>Price Class: $$ | P3 | 14</h3>
</div>
<div class="product--image">
<img src="http://placekitten.com/200/200" alt="cat">
<p class="product--pricetag">
999 $
</p>
</div>
<div class="product--rating">
<p>Rating: 4/5</p>
</div>
<p class="product--links">
<a class="btn">Buy on Amazon</a>
<a class="btn">Other Sizes</a>
</p>
</div>
I wouldn't recommend a background frame image, because it's a pain to work with and loading it is a waste of bandwidth.
Put four borders on the container, then just add border-bottom in each child, except on the last.
.container-bordered {
border: 2px solid red;
}
.container-bordered > div:not(:last-of-type) {
border-bottom: 2px solid red;
}
https://jsfiddle.net/cqjxuype/

Tight fit div around an image

I am working on trying to make a chat app and need chat bubbles to tightly fit around their content. It works alright for text, but when I have an image in the bubble it gets problematic. Here is the HTML that I am using
<div class="fromMe msgBubble">
<img src="{{image.location}}" style="width:50%;">
<br>
<span class="msgDate">2011-01-26 01:52:16</span>
</div>
<div class="clearfix"></div>
However, when I load the image I have a whole bunch of padding off to the side of the image, and the div doesn't tightly wrap around the image. It looks like this:
http://imgur.com/R3j7yO2
UPDATE: I posted a JS Fiddle with the code and CSS.
https://jsfiddle.net/dw9aek2y/
How can I tight fit the chat bubble div around the picture?
Thanks!
Remove width and add max-width and every thing will be fine
#messageBubbleArea {
font: 14px Arial;
margin-top: 20px;
padding: 0 10px;
width: 99%;
}
.fromMe::before {
border-bottom: 9px solid #0b93f6;
border-right: 9px solid rgba(0, 0, 0, 0);
bottom: 0;
content: "";
position: absolute;
right: -8px;
}
*::after, *::before {
box-sizing: border-box;
}
.fromMe {
background-color: #0b93f6;
border-radius: 8px 8px 0;
color: white;
float: right;
margin-left: auto;
text-align: right;
}
.fromThem, .fromMe {
clear: both;
margin-top: 20px;
max-width: 80%;
padding: 5px 9px;
position: relative;
}
<div id="messageBubbleArea">
<div class="fromMe msgBubble">Hey babe<br>
<span class="msgDate">2011-01-26 00:09:30</span>
</div>
<div class="clearfix"></div>
<div class="fromMe msgBubble">
<img style=" max-width:200px;" src="http://images.clipartpanda.com/rainbow-clip-art-rainbow.gif"><br>
<span class="msgDate">2011-01-26 01:52:16</span>
</div>
<div class="clearfix"></div>
</div>

css of social share buttons

I've recently got my website up and running. I'm in a bit of a rush at the moment, could anyone tell me of a way of styling the divs so they are all displayed horizontally. I'v got them all in a div.
#questionTitleDiv { width: 280px; height: 70px; margin: 10px 0px 10px 0px; padding: 10px 0px 10px 10px; border: 1px solid #FFFFFF; background-color: #F3F781; border-radius: 10px;}
#questionTitleDiv h2 { font-size: 18px;}
#shareButtonDiv { display: inline;}
#facebookSharer { display: inline;}
#twittertweet { display: inline;}
#google+Share { display: inline;}
#questionAnswerDiv { width: 250px; margin: 0px 0px 10px 0px; padding: 10px 20px 10px 20px; border: 1px solid #FFFFFF; background-color: #F3F781; border-radius: 10px;}
<div id="questionTitleDiv">
<h2>Question?</h2>
<div id="shareButtonsDiv">
<div id="facebooksharer" class="fb-share-button" data-href="http://www.example.com/examplehtml" data-layout="button_count"></div>
<div id="twittertweet"><a class="twitter-share-button" href="http://www.example.com/example.html" data-related="carpetinfo_com" data-size="medium" data-count="horizontal" data-counturl="http://www.example.com/example.html">Tweet</a></div>
<div id="google+Share" class="g-plus" data-action="share" data-annotation="bubble"></div>
</div>
</div>
<div id="questionAnswerDiv">
<p>answer!!</p>
</div>
when they display, the facebook div is a little lower than the others. I've tried positioning them absolutely, with the containing div positioned relative so it stays in the flow of the page. But they all jumble up. Vertical align doesn't work on them. and margin-top or padding-top doesn't work either, i', kind of stuck and in a rush.
Could a simple float work for you ?
#shareButtonsDiv div{
float:left;
}
http://jsfiddle.net/su3wt0hy/