I have 3 divs, each with width:100%, placed under each other.
Here's how it looks:
My code is:
<div class="welcome">
<h1>Welcome</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>
</div>
<div class="welcome2">
<h1>About</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.<small>
</div>
<div class="welcome3">
<h1>Why choose us?</h1>
<div class="row">
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
</div>
</div>
CSS
.welcome
{
text-align: center;
width: 100%;
background-color: #3BA666;
background-image: linear-gradient(60deg, #4DAC71 50%, #3BA666 50%);
padding: 50px;
}
.welcome2
{
text-align: center;
width: 100%;
background-color: #FF61E7;
background-image: linear-gradient(60deg, #FF61E7 50%, #FF61D0 50%);
padding: 50px;
}
.welcome3
{
text-align: center;
width: 100%;
background-color: #32C8DE;
background-image: linear-gradient(60deg, #32D0DE 50%, #32C8DE 50%);
padding: 50px;
}
.why
{
/** text-align: left; **/
padding: 15px;
}
.why-icon
{
color: #0E495C;
display: block;
}
I want it to be like that - first two are normal height, and the last one always fill the empty white space. Is this possible?
Here is the Fiddle: https://jsfiddle.net/21dydo07/1/
Yes, with CSS3.
Give the design's parents (body, html, ...) a height of 100%. Then set some height to .welcome and .welcome2, e.g. 200px each. After that, set .welcome3 to take the rest, like this:
html, body {height: 100%}
.welcome, .welcome2 {height: 200px}
.welcome3 {height: calc(100% - 400px)}
Another solution would be to set specific height for every element (that would also be CSS2 comapatible), but that wouldn't allow you to always fill 100% of the screen height and have the third div with a variable height.
If you need the first solution, but you also need CSS2 compliance (e.g. for IE8), then you might need a javascript fallback, that will set the height to .welcome3 accordingly at pageload, something like this (needs jQuery):
$(document).ready(function() {
$(".welcome3").css("height",$(window).height()-400);
});
If the sentences in the first two blocks can be wrapped to single-line, use this:
You could use calc().
Make sure that the wrapper for these three has a height style.
For .welcome and .welcome2, set padding and line-height either in px or in em. For example, if the calculated height comes out to be 300px use height: calc(100% - 300px) for .welcome3. Note: The spaces around the operator - are important.
You can do this with Flexbox, set min-height: 100vh; on wrap div and flex: 1; on welcome3 so it will always take free space of viewport
html, body {
margin: 0;
padding: 0;
}
.wrap {
display: flex;
min-height: 100vh;
flex-direction: column;
text-align: center;
}
.welcome {
background: #3CA666;
padding: 20px;
}
.welcome2 {
background: #FF61D0;
padding: 20px;
}
.welcome3 {
background: #32C9DE;
flex: 1;
padding: 20px;
}
<div class="wrap">
<div class="welcome">
<h1>Welcome</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>
</div>
<div class="welcome2">
<h1>About</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>small>
</div>
<div class="welcome3">
<h1>Welcome 3</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua</small>
</div>
</div>
Related
I'm learning React by starting to build a simple webpage (I know, overkill.) but I ran across a weird issue.
So I have three "bubbles" on my homepage each containing an icon, title, and text. I am using flex in their parent container to align them as a row but when I do this I can only select the title and text of the last "bubble".
If I choose flex-direction: column; (or if I don't set a direction) I am able to select the text of all three bubbles. If I choose: flex-direction: row; and flex-wrap: wrap; and then make the window smaller so one of the bubbles goes to the next line, I am able to select the text from 1/2 of the bubbles on line one and the text from the bubble on line two.
Also the :hover is no longer working in that last section of CSS code.
Been at this problem for a couple of days and it makes no sense to me. Thanks in advance for the help. See code below.
.home-services {
padding: 50px;
background-color: bisque;
transform: skewY(-3deg) translateY(-55px);
z-index: -1;
}
.home-bubbles {
display: flex;
flex-direction: row;
flex-wrap: wrap;
transform: skewY(3deg) translateY(50px);
width: 100%;
user-select: all;
z-index: -1;
}
.home-services-bubble {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
margin: 10px;
padding: 10px 30px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 2px 3px #ddd;
width: 29%;
}
.bubble-icon {
display: flex;
justify-content: center;
align-items: center;
background-color: #f64a01;
height: 100px;
width: 100px;
font-size: 3vw;
text-align: center;
border-radius: 100px;
color: #ffffff;
}
.home-services-bubble:hover .bubble-icon {
transform: translateY(-5px);
background-color: black;
box-shadow: 2px 3px #ddd;
transition: 0.5s;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" rel="stylesheet"/>
<div class="home-services">
<div class="home-bubbles">
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-search fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-wind fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-sign fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
</div>
</div>
The user-select property with the value all selects the whole text on a simple click. Just remove it like this:
.home-bubbles {
display: flex;
flex-direction: row;
flex-wrap: wrap;
transform: skewY(3deg) translateY(50px);
width: 100%;
z-index: -1;
}
At the moment I am trying to program the wireframe I have made, but experience some problems with specially the left side of the element:
The problem is that the 200x200px image is going full width in the left column. Therefore I cannot center the image.
I can see it can be changed with overwriting the following CSS, and set the width to none;.
.cms-area img {
width: 100%;
}
But as I see it will break the reponsive on the images?
Can anybody help me in goal here?
See the [Testpage here][2].
The site is still using Bootstrap 3, and I do not have access to change the main CSS. Therefore I need to overwrite CSS if I need that.
Best regards
<style>
#front .row {
padding-bottom: 0px;
}
.row [class*="col-"] {
padding-right: 7.5px;
padding-left: 7.5px;
}
.padding-white-bg {
padding: 15px;
background-color: #fff;
margin-bottom:30px;
border: 1px solid #ebecf0;
}
.padding-twocolumn-bg {
margin-bottom:30px;
}
.padding-grey-bg {
padding: 7.5px;
}
.padding-white-border {
border: 1px solid #ebecf0;
}
.top-pad-d {
padding-top: 15px;
}
.sbp-2-column {
background-color:#fff;
padding-top:15px;
padding-bottom:15px;
border:1px solid #ebecf0;
}
/********************************/
/* Product styling */
/********************************/
/* Make spot image go full width */
.cms-area .result-cols ul.items li.add-item {
width: 100% !important;
}
.cms-area .result-cols ul.items li.add-item .item {
padding: 0px;
}
/* Remove add to basket button */
.cms-area .result-cols ul.items li.add-item a.button-add {
display:none;
}
/* Set height on product description */
.cms-area .result-cols ul.items li.add-item .desc {
height: 0px;
overflow: visible;
}
/* Remove fade on product headline */
.cms-area .result-cols ul.items li.add-item .desc:after {
background: none;
}
.cms-area .result-cols .more-wrap {
padding-bottom: 0px;
}
/* Remove Sub-heading */
.desc2{
display:none;
}
/* Remove product text */
.ext-description {
display:none;
}
/* Remove padding multiple products on row */
.cms-area .result-cols {
padding:0px;
}
/********************************/
/* Custom Buttons */
/********************************/
.btn.btn-lg {padding: 10px 40px;}
.btn.btn-hero,
.btn.btn-hero:hover,
.btn.btn-hero:focus {
color: #f5f5f5;
background-color: #1abc9c;
border-color: #1abc9c;
outline: none;
margin: 20px auto;
}
/********************************/
/* Media Queries */
/********************************/
#media screen and (min-width: 980px){
.hero { width: 980px; }
}
#media screen and (max-width: 640px){
.hero h1 { font-size: 4em; }
}
#media screen and (max-width: 896px){
.top-pad-m {
padding-top: 15px;
}
}
#media only screen and (max-width: 1280px) {
.fade-carousel .slides .slide-1,
.fade-carousel .slides .slide-2,
.fade-carousel .slides .slide-3 {
height: 60vh;
}
}
/********************************/
/* Overall Styling */
/********************************/
#sbp-hr {
margin-top:10px !important;
margin-bottom:10px !important;
}
.sbp-align {
text-align: left;
padding-left:10px;
}
.test {
padding:20px 20px 20px 20px;
}
/* TEST on 2 column */
.classWithPad { margin:8px; padding:10px; background-color: #fff; border:1px solid #ebecf0;}
.cms-area img {
max-width: 100%;
}
</style>
<div class="wrapper">
<!-- Section 7 -->
<div class="section padding-twocolumn-bg">
<div class="row">
<div class="text-center col-md-6">
<div class="classWithPad">
<p style="padding:75px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a><img src="https://placehold.it/200x200" class="img-responsive test"></a>
</div>
</div>
<div class="text-center col-md-6">
<div class="classWithPad">
<div class="row">
<div class="col-sm-12">
<h3 class="sbp-align">Headline</h3>
<hr>
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" style="padding:10px;">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" style="padding:10px;">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
</div>
</div>
</div>
</div>
</div>
</div>
If you make width=200px to the left column the uploaded image will always be at center and there are lots of padding you are using for centering the images, you can use various classes of bootstrap for that!
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<div class="container-fluid">
<!-- Section 7 -->
<div class="section padding-two column-bg">
<div class="row align-items-center">
<div class="text-center col-md-6 col-12">
<div class="classWithPad">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a><img src="https://placehold.it/200x200" width="200px"></a>
</div>
</div>
<div class="text-center col-md-6">
<div class="classWithPad">
<div class="row p-3">
<div class="col-sm-12">
<h3 class="sbp-align">Headline</h3>
<hr>
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" width="100%" class="pb-2">
<h4 class="sbp-align pb-2">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" width="100%" class="pb-2">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I'm brushing up on Responsive Grid CSS on YouTube. Following along with the instructors lesson. I'm having trouble formatting my nave grid. I've included both the html and css code along with pictures of his nav results vs mine. Any help would be appreciated.
I'm trying to get the navigation bar in a 4 column grid. I'm trying to see what I'm missing here.
Instructor Results:
My Results:
/* CSS Variables */
:root {
--primary: #ddd;
--dark: #333;
--light: #fff;
--shadow: 0 1px 5px rgba(104, 104, 104, 0.8);
}
html {
box-sizing: border-box;
font-family: Arial, Helvetica, san-serif;
color: var(--dark);
}
body {
background: #ccc;
margin: 30px 50px;
line-height: 1.4;
}
.btn {
background: var(--dark);
color: var(--light);
padding: 0.6rem 1.3rem;
text-decoration: none;
border: 0;
}
img {
max-width: 100%;
}
.wrapper {
display: grid;
grid-gap: 20px;
}
/* Navigation */
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<div class="wrapper">
<!-- Navigation -->
<nav class="main-nav">
<ul>
<li><a href="#">Home</li>
<li><a href="#">About</li>
<li><a href="#">Services</li>
<li><a href="#">Contact</li>
</ul>
</nav>
<!-- Top Container -->
<section class="top-container">
<header class="showcase">
<h1>Damn That Looks Delicious</h1>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Aliquam sem et tortor consequat id porta.
</p>
Read More
</header>
<div class="top-box top-box-a">
<h4>Membership</h4>
<p class="price">$199/mo</p>
Buy Now
</div>
<div class="top-box top-box-b">
<h4>Pro Membership</h4>
<p class="price">$299/mo</p>
Buy Now
</div>
</section>
<!-- Boxes Section -->
<section class="boxes">
<div class="box">
<i class="fas fa-pizza-slice fa-4x"></i>
<h3>Restaurants</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-utensils fa-4x"></i>
<h3>Chefs</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-hamburger fa-4x"></i>
<h3>Catering</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-ice-cream fa-4x"></i>
<h3>Sweets</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
</section>
<section>
<img src="images/dtld.jpg" alt="">
<div>
<h2> Your Business On DTLD</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Learn More
</div>
</section>
<!-- Portfolio Section -->
<section class="portfolio">
<img src="https:/source.unsplash.com/random/200x200" alt="">
<img src="https:/source.unsplash.com/random/201x200" alt="">
<img src="https:/source.unsplash.com/random/202x200" alt="">
<img src="https:/source.unsplash.com/random/203x200" alt="">
<img src="https:/source.unsplash.com/random/204x200" alt="">
<img src="https:/source.unsplash.com/random/205x200" alt="">
<img src="https:/source.unsplash.com/random/206x200" alt="">
<img src="https:/source.unsplash.com/random/207x200" alt="">
<img src="https:/source.unsplash.com/random/208x200" alt="">
</section>
<!-- Footer -->
<footer>
<p> Damn That Looks Delicious © 2005</p>
</footer>
</div>
<!-- Wrapper Ends -->
Once you add the closing tag to your anchor elements the layout works as you expect.
This is what you have now:
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<nav class="main-nav">
<ul>
<li><a href="#">Home</li>
<li><a href="#">About</li>
<li><a href="#">Services</li>
<li><a href="#">Contact</li>
</ul>
</nav>
Because the anchor elements are left open (creating invalid HTML code), the browser generates four additional grid items. Now the grid container has eight children: 4 li and 4 a.
Since your code allows for only four items per row, a second row is created to accommodate the other four items. In fact, you always had a four-column grid.
Once you close the anchor tags (creating valid HTML code), only four grid items are rendered.
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<nav class="main-nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
Also, you may want to see my answer here for a brief analysis and suggestion regarding unordered lists inside nav elements.
There is missing of closing anchor </a> tag in your code so once you add closing anchor tag in it. Your code will run perfectly.
screenshot of missing anchor tag
unaligned images and text
I have attempted to input suggestions from previous questions but it just seems I have been able to successfully find the correct way to align these images with their text underneath.
<section id="boxes">
<div class="container">
<div class="box">
<img src="./images/dayporter2.jpeg">
<h3>DAYPORT</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
<div class="box">
<img src="./images/floorcare1.jpeg">
<div class="box">
<h3>FLOOR CARE</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="box">
<img src="./images/janitor2.jpeg">
</div>
</section>
/* boxes */
#boxes{
margin-top: 20px;
}
#boxes .box{
float: left;
text-align: center;
width: 30%;
padding: 10px;
}
#boxes .box img{
width: 90px;
}`
You seem to have an unnecessary div tag.
remove the div tag after your 'floorcare1.jpeg' img, here:
<img src="./images/floorcare1.jpeg">
<div class="box"> //remove this
<div class="box">
<img src="./images/floorcare1.jpeg">
<div class="box"> <!-- The probleme is here -->
<h3>FLOOR CARE</h3>
Because the .box element which is direct below the image is float left, it will force the image to be float left, because their sibling .box take 30% of the parent and there are remaining 70% width of their .box parent element. You must remove the .box element and every thing will work like you expecting.
Another problem you must close all you open markup
<section>
<div class="container">
<div class="box">
<!-- First box -->
</div>
<div class="box">
<!-- Second box -->
</div>
<div class="box">
<!-- Third box -->
</div>
</div>
</section>
While developing new website for our client (he delivered design and insisted on using flexbox), we've come to element that looks like this (the "Samochody Peugeot" section with 2 little boxes at right):
Grid starts at text in left box, and ends at end of image in right boxes. The only real solution that we can find is to create the gray background using absolute positioned :before pseudo-element, but it seems pretty hacky.
At bigger widths the gray bg should expand to left, but everything else should stay in grid.
Is there any better way to achieve this kind of layout than using :before?
<section class="boxes">
<div class="container">
<div class="boxes__box">
<h3>Samochody<br/>PEUGEOT</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua.</p>
<a class="btn" href="">Przejdź do strony</a>
</div>
<div class="boxes__box-holder">
<div class="boxes__box boxes__box--small">
<h3>PONAD 20 LAT<br/>DOŚWIADCZENIA</h3>
<a class="btn" href="">O firmie</a>
</div>
<div class="boxes__box boxes__box--small">
<h3>POZNAJ NASZE<br/>USŁUGI</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<a class="btn" href="">Przejdź do strony</a>
</div>
</div>
</div>
</section>
.boxes {
.container {
display: flex;
}
&__box {
width: 68%;
background: orange;
position: relative;
&:first-child:before {
content: '';
height: 100%;
width: 100vw;
background: red;
position: absolute;
right: 100%;
z-index: -1;
top: 0;
}
}
&__box-holder {
width: 32%;
}
}