CSS - change height to up by content - css

i have 3 boxes and i need change height by content but height must change to up (Lower margin aligned). Here is image how it should look:
<style>
.wrapper{
width: 100%;
height: 30px;
}
.wrapper .point{
width: 12px;
height: 12px;
background: #979797;
-moz-border-radius: 70px;
-webkit-border-radius: 70px;
border-radius: 70px;
float: left;
margin-top: 3px;
}
.wrapper .text{
width: 130px;
float: left;
border-bottom: 2px solid #979797;
color: #979797;
font-size: 11px;
min-height: 20px;
text-align: center;
padding-bottom: 20px;
margin-top: -12px;
}
</style>
<div class="wrapper">
<div class="point"></div>
<div class="text">Short</div>
<div class="point"></div>
<div class="text">Short</div>
<div class="point"></div>
<div class="text">Very long text. Lorem ipsum dolor sit amet</div>
<div class="point"></div>
</div>
How to do it? Thanks

try
height:auto,
width:100%
in your css

It's impossible with float:left (unless you know the exact height in advance and can set the margin-top according to it). But floats never were meant to do this type of layout anyways.
However, it can be easyly done with Flexbox:
.wrapper{
display: flex;
flex-flow: row wrap;
align-items: flex-end;
}
.wrapper .point{
width: 12px;
height: 12px;
background: #979797;
border-radius: 70px;
display: inline-block;
margin-top: 3px;
}
.wrapper .text{
width: 90px;
border-bottom: 2px solid #979797;
color: #979797;
font-size: 11px;
text-align: center;
padding: 20px;
background: #eee;
}
<div class="wrapper">
<div class="point"></div>
<div class="text">Short</div>
<div class="point"></div>
<div class="text">Short</div>
<div class="point"></div>
<div class="text">Very long text. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet</div>
<div class="point"></div>
</div>
Also, this can be done with inline-blocks, by setting vertical-align:bottom to their container. You can add this as a fallback to Flexbox solution (all you need for this is setting vertical-align:bottom to .wrapper and display:inline-block to points and texts). I'd not recommend to rely on inline-blocks only because they weren't meant to do the layout, like floats, and will need some sort of hacks to adjust the spaces between items, because they treat whitespace characters between tags as whitespace text characters. But as a fallback for non-Flexbox-supporting browsers (like IE10-) they would provide a decent experience (much better than nothing).

Related

"Button:active" moves all buttons instead of only clicked button

I know that it has something to do with margin's colliding or the layout but I can't figure it exactly out. My goal is to move a clicked (div) button by 5 pixels. The current way I do this is by setting the :active margin-top to 5.
I also can't figure out how to make all buttons take up the whole screen space. Using 100% or 100vh creates too much space.
CSS:
body{
margin: 0;
padding: 0;
font-family: Sans-Serif;
-webkit-animation: bgcolor 20s infinite;
animation: bgcolor 10s infinite;
-webkit-animation-direction: alternate;
animation-direction: alternate;
}
header{
background-color: rgba(0, 0, 0, 0.5);
color: white;
text-align: center;
font-size: 25px;
}
.container{
padding: 10px;
margin: 0 auto;
text-align: center;
}
.question{
font-size: 35px;
margin: 10px;
font-weight: bold;
color: white;
}
.buttons-container{
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 10px;
height: 100%;
}
.button{
padding: 25px;
background-color: green;
color: white;
font-size: 25px;
box-shadow: 0px 5px 0px #504f4f;
}
.button:active{
box-shadow: none;
margin-top: 5px;
}
#keyframes bgcolor {
0% {
background-color: #45a3e5
}
30% {
background-color: #66bf39
}
60% {
background-color: #eb670f
}
90% {
background-color: #f35
}
100% {
background-color: #864cbf
}
}
HTML
<?php
include 'header.php';
?>
<div class="wrapper">
<header>
Quiz
</header>
<div class="container">
<div class="question">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
<div class="buttons-container">
<div class="button">
Opt 1
</div>
<div class="button">
Opt 2
</div>
<div class="button">
Opt 3
</div>
<div class="button">
Opt 4
</div>
</div>
</div>
</div>
</body>
</html>
A little further explanation from my comment: when you use margins, you are actually going to influence the document flow and that is causing the entire page to reflow and relayout.
If you want to preserve document flow but nudge the button around, you should consider using relative positioning, i.e. position: relative; top: -5px;.
ps: The default is position: static.

Paragraph wont wrap around an image

Ok so there seems to be a problem with this..I tried so many things, but I'm a noob at this so it's probably something so obvious I'm just missing it...
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
#about {
min-height: 500px;
color: white;
padding: 40px 100px;
}
#about h1, p {
float: left;
}
#about img {
float: right;
}
<section id="about">
<div class="container">
<h1>About</h1>
<p>Lorem ipsum dolor sit amet</p>
<img src="https://picsum.photos/250/250">
</div>
</section>
Only inline elements flow around floated elements, but both the h1 and p tags are block elements. You can change both of their displays to inline-block however a better solution would probably be just to put the img inside the p tag with the text itself (since text has inline styling by default and will naturally flow around your floated image).
.container {
width: 80%;
margin: auto;
}
#about {
min-height: 500px;
padding: 40px 100px;
}
#about img {
float: right;
}
<section id="about">
<div class="container">
<h1>About</h1>
<p><img src="https://picsum.photos/250/250">Lorem ipsum dolor sit amet</p>
</div>
</section>
I had the same problem. I was using Bootstrap 4 along with a local style.css file.
Try removing float: left; for "#about h1, p" selector, and see if it works. I didn't set the "display: inline-block;" declaration for h1 and p elements and it still worked.
here is my code:
.about p {
font-size: 25px;
min-width: 300px;
text-align: justify;
text-indent: 15px;
font-weight: bold;
}
.me {
height: 400px;
margin: 0 30px 10px 0;
box-shadow: 2px 5px 10px 0 hsla(240, 100%, 35%, 1);
}
<head>
<!-- link to Bootstrap CDN -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<section class="container bg-primary text-white about" id="about">
<img src="./images/me.JPG" alt="my picture" class="me rounded float-left"/>
<h1 class="font-weight-bold display-4">About Me...</h1>
<p>Hi there! My name is Mohsen, and I'm from Shiraz. I love to learn new things, and though I had just begun to learn about front-end web-development, I'm very
passionate about it.</p>
</section>
</body>

Could browser like tabs made with flex box or css only?

Need tabs to shrink while the main container doesn't fit all items by width.
Here is expected behavior:
http://adamschwartz.co/chrome-tabs/
But could it be done on pure css, flexbox may be?
Solution was pretty simple. Just display: flex; for container, and overflow: hidden; for tab items.
Don't know why my question was downvoted. :(
html {
font-family: sans-serif;
}
.container {
display: flex;
border: 1px solid silver;
padding: 10px 10px 0;
width: 400px;
margin: 0 auto 10px;
}
.tab {
overflow: hidden;
text-overflow: ellipsis;
height: 20px;
border: 1px solid silver;
border-top-right-radius: 8px;
border-top-left-radius: 8px;
padding: 10px;
margin-right: 8px;
border-bottom: none;
}
.tab:last-child {
margin-right: 0;
}
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
</div>
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
<div class="tab">Chrome</div>
<div class="tab">Flexbox</div>
</div>
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
<div class="tab">Chrome</div>
<div class="tab">Flexbox</div>
<div class="tab">Stackoverflow</div>
</div>

Chrome/Firefox difference with negative margin bottom percentage

I have a difference of box sizing interpretation between webkit and Firefox using height 100% on a parent.
HTML:
<header>
Lorem ipsum dolor amet
</header>
<div class="wrapper">
<div class="content">
My background depends on my ancestor sibling
</div>
</div>
<div class="red">
<p class="white">
Amet ipsum dolor
</p>
</div>
CSS:
header {
height: 150px;
background: #fff;
}
.red {
background: red;
padding: 6em 0;
}
.content {
background: rgba(28,28,28, .3);
margin-bottom: -100%;
}
.wrapper {
position: relative;
height: 100%;
}
p.white {
background: #fff;
width: 70%;
margin: 0 auto;
}
JS fiddle here https://jsfiddle.net/m1fobvwv/
Result on Chrome (expected):
Wrong result on FF:
A colleague of mine found a workaround:
Add position: absolute; width: 100%; to .content
Updated fiddle https://jsfiddle.net/m1fobvwv/3/

How do I center two divs within a larger div?

I am trying to center two divs (#about and #testimonial-snippets) within the larger black div. How can I do this?
JS Fiddle: http://jsfiddle.net/DgtqM/
HTML
<footer>
<div id="footer-section">
<section id="about">
<img class="profile-photo" src="http://dummyimage.com/42x42/000/fff" alt="profile" height="44" width="44">
<p>Lorem ipsum dolor sit amet. Find him on Twitter and Instagram. <a id="slide-toggle" href="#">Contact</a> | Archive</p>
</section>
<section id="testimonial-snippets">
<img class="profile-photo" src="http://dummyimage.com/42x42/000/fff" alt="profile" height="44" width="44">
<div class="snippet">
<p>This is a testimonial.</p>
<a class="read-testimonial" href="/testimonials">read more</a>
</div>
</section>
</div>
</footer>
CSS
footer {
background: #222;
clear: both;
color: #f4f3f1;
float: left;
padding: 50px 0;
width: 100%;
}
#footer-section {
margin: 0 auto;
overflow: hidden;
position: relative;
width: 940px;
}
footer section {
float: left;
width: 300px;
}
#about {
margin-right: 20px;
}
footer a {
border-bottom: 1px dotted #f4f3f1;
color: #f4f3f1;
}
.profile-photo {
border: 1px solid #f4f3f1;
float: left;
margin: 4px 10px 10px 0;
}
p {
margin: 0 0 1em;
}
I allowed myself to reduce that problem to a minimum of markup. Everything else is not relevant to the question and only makes it harder to understand.
<footer>
<section id="about">About</section>
<section id="testimonial-snippets">Testimonial</section>
</footer>
One solution would be to make these sections inline-block elements and have them centered in the footer:
footer {
background: #222;
padding: 50px 0;
width: 100%;
text-align: center;
}
footer section {
width: 300px;
height: 50px;
display: inline-block;
text-align: left;
}
/* Just coloring the different divs */
#about { background: red; }
#testimonial-snippets { background: green; }
http://jsfiddle.net/DgtqM/6/
Wrap the elements within a new div. Then give the new div a fixed width and use margin: 0px auto for styling.
HTML
<div id="footer-section">
<div class="wrap">
<section id="about">
<!--Content -->
</section>
<section id="testimonial-snippets">
<!--Content-->
</section>
</div>
</div>
CSS
.wrap{
width: 620px;
margin: 0px auto;
overflow: auto;
}
Example http://jsfiddle.net/DgtqM/5/

Resources