I have no idea why my image is shifting when my webpage is resized. There is no absolute positioning, the image just floats left, and the parents only give it some padding and margin.
Here is the HTML:
.section-title {
color: black;
font-size: 30px;
font-weight: bold;
text-align: center;
}
.section-title-info {
margin-bottom: 1.5em;
margin-top: 0;
}
.section-words-info {
font-size: 20px;
color: black;
font-weight: 550;
line-height: 30px;
}
.section-info {
background-color: #706D9F;
padding: 2em 1em;
}
.container {
margin: 0 auto;
}
.img-main {
float: left;
height: 12em;
border-radius: 50%;
}
<section class="section-info container">
<h2 class="section-title section-title-info">Information</h2>
<img class="img-main" src="https://ibb.co/g7LnzSc">
<span class="section-words-info">Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span>
</section>
You need to add overflow: auto; to your .section-info By using float it takes that element out of the flow of the document so you need to force the parent to include it by using overflow auto. See here:
.section-title {
color: black;
font-size: 30px;
font-weight: bold;
text-align: center;
}
.section-title-info {
margin-bottom: 1.5em;
margin-top: 0;
}
.section-words-info {
font-size: 20px;
color: black;
font-weight: 550;
line-height: 30px;
}
.section-info {
background-color: #706D9F;
padding: 2em 1em;
overflow: auto;
}
.container {
margin: 0 auto;
}
.img-main {
float: left;
height: 12em;
border-radius: 50%;
}
<section class="section-info container">
<h2 class="section-title section-title-info">Information</h2>
<img class="img-main" src="https://w3schools.com/html/img_girl.jpg" />
<span class="section-words-info">Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span>
</section>
I have a flexbox which should be overflowed by its children to the left and to the right side. Here is my code for this solution. It works in all browsers properly but it doesn't work in IE 11 (children overflow flexbox to the right side only).
I tried to solve this problem with overflow-x:visible for the section and the list, but it doesn't work. The overflow-x property in the body hides the horizontal scroll and it's OK for my task. As you can see, I've already used autoprefixer for my CSS but I didn't find the solution in prefixes. Is this a special behavior of IE flexbox overflow? :)
So my questions are why my solution doesn't work in IE 11 and what can I do to solve this problem?
body{
width: 1400px;
margin: 0 auto;
font-family: "Open Sans", "Arial", sans-serif;
overflow-x: hidden;
font-size: 16px;
line-height: 24px;
color: #999;
}
.visually-hidden{
position: absolute;
clip: rect(0,0,0,0);
width: 1px;
height: 1px;
}
.testimonials{
position: relative;
height: 576px;
background-color: #fafafa;
background-image: url("../img/quotes.png"),
url("../img/quotes-reversed.png"),
url("../img/worldmap.png"),
url("../img/worldmap.png");
background-repeat: no-repeat;
background-position: 115px 60px,
1140px 380px, -290px 205px, 530px -270px;
background-size: auto, auto, auto, auto;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
overflow-x: visible;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
margin-top: 100px;
}
.reviews-catalog{
padding: 0;
list-style: none;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin-top: 160px;
overflow-x: visible;
}
.review{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
position: relative;
min-width: 470px;
height:243px;
background-color: white;
margin-left: 15px;
margin-right: 15px;
-webkit-box-shadow: 0px 3px 18px 0px rgba(0, 153, 255, 0.1);
box-shadow: 0px 3px 18px 0px rgba(0, 153, 255, 0.1);
}
.review:first-of-type{
margin-left: 0px;
}
.review:last-of-type{
margin-right: 0px;
}
.review:first-of-type::before,
.review:last-of-type::before{
content: "";
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
background-color: white;
opacity: 0.6;
}
.review:first-of-type .review-photo,
.review:last-of-type .review-photo{
opacity: 0.6;
}
.review:first-of-type:hover .review-photo,
.review:last-of-type:hover .review-photo{
opacity: 1;
}
.review:first-of-type:hover::before,
.review:last-of-type:hover::before{
opacity: 0;
}
.review-photo{
display: block;
border-radius: 50%;
margin-top: -45px;
-webkit-box-ordinal-group: 0;
-ms-flex-order: -1;
order: -1;
}
.review-author{
margin: 0;
margin-top: 30px;
color: black;
font-size: 16px;
font-weight: 600;
line-height: 24px;
}
.review-content{
margin: 0;
margin-top: 15px;
text-align: center;
max-width: 370px;
color: black;
}
<section class="testimonials">
<h2 class="visually-hidden">Other reviews</h2>
<ul class="reviews-catalog">
<li class="review">
<h3 class="review-author">Kevin Smith,</h3>
<p class="role">Pediatrics student</p>
<p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<img class="review-photo" src="img/kevin.png" alt="kevin's avatar" width="90" height="90"/>
</li>
<li class="review">
<h3 class="review-author">Kevin Smith,</h3>
<p class="role">Pediatrics student</p>
<p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<img class="review-photo" src="img/kevin.png" alt="kevin's avatar" width="90" height="90"/>
</li>
<li class="review">
<h3 class="review-author">Jane Lambert,</h3>
<p class="role">Psychiatry student</p>
<p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<img class="review-photo" src="img/jane.png" alt="jane's avatar" width="90" height="90"/>
</li>
<li class="review">
<h3 class="review-author">Jane Lambert,</h3>
<p class="role">Psychiatry student</p>
<p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<img class="review-photo" src="img/jane.png" alt="jane's avatar" width="90" height="90"/>
</li>
</ul>
</section>
If you remove the flex properties from the .testimonials and add these 3, you will get the same result cross browsers, where the items center and overflow equally to the left/right
display: inline-block;
left: 50%;
transform: translateX(-50%);
This works like that, that the inline-block make it size by content, the left: 50% (together with the already set position: relative) position its left edge in the middle of its parent, in this case the body, and the transform: translateX(-50%) will move it 50% of its own width to left.
Stack snippet
body{
width: 1400px;
margin: 0 auto;
font-family: "Open Sans", "Arial", sans-serif;
overflow-x: hidden;
font-size: 16px;
line-height: 24px;
color: #999;
}
.visually-hidden{
position: absolute;
clip: rect(0,0,0,0);
width: 1px;
height: 1px;
}
.testimonials{
position: relative;
height: 576px;
background-color: #fafafa;
background-image: url("../img/quotes.png"),
url("../img/quotes-reversed.png"),
url("../img/worldmap.png"),
url("../img/worldmap.png");
background-repeat: no-repeat;
background-position: 115px 60px,
1140px 380px, -290px 205px, 530px -270px;
background-size: auto, auto, auto, auto;
/*
display: -webkit-box;
display: -ms-flexbox;
display: flex;
overflow-x: visible;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
margin-top: 100px;
*/
display: inline-block; /* added */
left: 50%; /* added */
transform: translateX(-50%); /* added */
}
.reviews-catalog{
padding: 0;
list-style: none;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin-top: 160px;
overflow-x: visible;
}
.review{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
position: relative;
min-width: 470px;
height:243px;
background-color: white;
margin-left: 15px;
margin-right: 15px;
-webkit-box-shadow: 0px 3px 18px 0px rgba(0, 153, 255, 0.1);
box-shadow: 0px 3px 18px 0px rgba(0, 153, 255, 0.1);
}
.review:first-of-type{
margin-left: 0px;
}
.review:last-of-type{
margin-right: 0px;
}
.review:first-of-type::before,
.review:last-of-type::before{
content: "";
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
background-color: white;
opacity: 0.6;
}
.review:first-of-type .review-photo,
.review:last-of-type .review-photo{
opacity: 0.6;
}
.review:first-of-type:hover .review-photo,
.review:last-of-type:hover .review-photo{
opacity: 1;
}
.review:first-of-type:hover::before,
.review:last-of-type:hover::before{
opacity: 0;
}
.review-photo{
display: block;
border-radius: 50%;
margin-top: -45px;
-webkit-box-ordinal-group: 0;
-ms-flex-order: -1;
order: -1;
}
.review-author{
margin: 0;
margin-top: 30px;
color: black;
font-size: 16px;
font-weight: 600;
line-height: 24px;
}
.review-content{
margin: 0;
margin-top: 15px;
text-align: center;
max-width: 370px;
color: black;
}
<section class="testimonials">
<h2 class="visually-hidden">Other reviews</h2>
<ul class="reviews-catalog">
<li class="review">
<h3 class="review-author">Kevin Smith,</h3>
<p class="role">Pediatrics student</p>
<p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<img class="review-photo" src="img/kevin.png" alt="kevin's avatar" width="90" height="90"/>
</li>
<li class="review">
<h3 class="review-author">Kevin Smith,</h3>
<p class="role">Pediatrics student</p>
<p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<img class="review-photo" src="img/kevin.png" alt="kevin's avatar" width="90" height="90"/>
</li>
<li class="review">
<h3 class="review-author">Jane Lambert,</h3>
<p class="role">Psychiatry student</p>
<p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<img class="review-photo" src="img/jane.png" alt="jane's avatar" width="90" height="90"/>
</li>
<li class="review">
<h3 class="review-author">Jane Lambert,</h3>
<p class="role">Psychiatry student</p>
<p class="review-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<img class="review-photo" src="img/jane.png" alt="jane's avatar" width="90" height="90"/>
</li>
</ul>
</section>
I have been trying to make an image map with HTML and CSS where the user rolls over a certain part of an image and a text caption pops up. I think i am nearly there but i would like the text caption to fade in and fade out instead of just appearing and disappearing. Could any one point me in the right direction please? Here is the code i have so far:
#map {
margin: 0;
padding: 0;
width: 400px;
height: 250px;
background: #000;
font-family: 'Lato', Calibri, Arial, sans-serif;
font-size: 10pt;
font-weight: 700;
line-height: 18px;
}
#map h1 {
margin: 0px;
padding-bottom: 5px;
color: #fff;
font-size: 12pt;
font-weight: 700;
}
#map li {
margin: 0;
padding: 0;
list-style: none;
}
#map li a {
position: absolute;
display: block;
background: url(images/blank.gif);
text-decoration: none;
color: #ed4e6e;
}
#map li a span {
display: none;
}
#map li a:hover span {
position: relative;
display: block;
width: 200px;
left: 20px;
top: 20px;
border: 0px solid #000;
border-radius: 5px;
background: #2c3f52;
padding: 20px;
}
#map a.caption1 {
top: 80px; left: 60px;
width: 10px;
height: 10px;
background: #ff0035;
}
#map a.caption2 {
top: 80px;
left: 190px;
width: 10px;
height: 10px;
background: #ff0035;
}
#map a.caption3 {
top: 180px;
left: 60px;
width: 10px;
height: 10px;
background: #ff0035;
}
#map a.caption4 {
top: 170px;
left: 250px;
width: 10px;
height: 10px;
background: #ff0035;
}
#map a.caption5 {
top: 90px;
left: 365px;
width: 10px;
height: 10px;
background: #ff0035;
}
<ul id="map">
<li><a class="caption1" href="#" title=""><span>
<h1>Caption 1</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span></a></li>
<li><a class="caption2" href="#" title=""><span>
<h1>Caption 2</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span></a></li>
<li><a class="caption3" href="#" title=""><span>
<h1>Caption 3</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span></a></li>
<li><a class="caption4" href="#" title=""><span>
<h1>Caption 4</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span></a></li>
<li><a class="caption5" href="#" title=""><span>
<h1>Caption 5</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span></a></li>
</ul>
You can change your current css into this
#map li a span {
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s linear;
}
#map li a:hover span {
position: relative;
width: 200px;
display: block;
z-index: 10;
visibility: visible;
opacity: 1;
left: 20px;
top: 20px;
border: 0px solid #000;
border-radius: 5px;
background: #2c3f52;
padding: 20px;
}
Fiddle: http://codepen.io/hunzaboy/pen/mOWOqa
Here's the challenge. I have a left-aligned text container (width: 40%;) that changes height with the window. I need my right half of the screen set as an image container (width: 60%) to which the image centers horizontally in the container, and vertically with the center of the text container.
Here is what my current code is doing:
Here is what I would like it to do:
I'm barely savvy in JS, so I'm trying to avoid it pending the need for tweaks. Here is my current code for the section:
.design-portfolio {
position: relative;
.web-img-container {
position: relative;
width: 60%;
margin-left: auto;
.web-img-lg {
img {
max-height: 40em;
}
}
}
.web-img-sm {
#media (min-width:75.063em) {
position: absolute;
visibility: hidden;
}
}
.web-design-box {
#media (min-width:75.063em) {
$font-title: 25px NexaBook;
$font-sub-title: 25px NexaHeavy;
$font-copy-title: 20px NexaHeavy;
$font-copy: 20px NexaBook;
position: relative;
width: 40%;
padding-right: 2em;
.size-fix {
position: relative;
}
.bg-box {
position: absolute;
background-color: $pink;
top: 2em;
bottom: 2em;
left: 0;
right: -2em;
}
.border-box {
position: relative;
border: .3em solid $black;
padding-left: 2em;
padding-right: 2em;
padding-bottom: 2em;
padding-top: 3em;
width: 60%;
margin-left: auto;
.h1 {
font: $font-title;
color: $white;
text-align: right;
}
.h2 {
font: $font-sub-title;
text-align: right;
}
.copy {
font: $font-copy;
color: $white;
text-align: left;
width: 100%;
height: 100%;
.h3 {
font: $font-copy-title;
color: $white;
text-align: left;
}
}
.copy p {
line-height: 1.2;
}
}
}
}
}
<section>
<div class="web-img-container">
<div class="web-img-lg">
<img src="assets/img/website-design.png" alt="web-design">
</div>
</div>
<div class="web-design-box">
<div class="size-fix">
<div class="bg-box"></div>
<div class="border-box">
<div class="h1">
my approach on
</div>
<div class="h2">
website design
</div>
<br>
<div class="copy">
<div class="h3">purpose</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<div class="h3">simplicity</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<div class="h3">mobile first</div>
<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>
</section>
I don't know how to set it up to run, as it's in SASS rather than regular CSS. :/
I'm having trouble trying to get the event-info class text to align to the right of the events calendar as a vertical list. Floating the events-list to the right seems to collapse my text altogether, which I don't want. Here is my HTML and CSS:
.workshop-events {
width: 100%;
background-color: #f2f2f2;
padding: 1px 20px;
/*padding: 20px;*/
}
.calendar {
width: 75px;
display: table-cell;
}
.calendar .month {
text-transform: uppercase;
font-size: 16px;
border: 1px solid #b2b2b2;
padding: 3px 0;
background: #FFF;
}
.calendar .day {
font-size: 30px;
font-weight: 500;
border: 1px solid #b2b2b2;
border-top: none;
padding: 7px 0;
background: #FFF;
}
.calendar .day {
font-size: 30px;
font-weight: 500;
border: 1px solid #b2b2b2;
border-top: none;
padding: 7px 0;
background: #FFF;
}
.events-info {
font-weight: bold;
font-size: 14px;
}
<div class="workshop-events">
<h1 class="section-heading">WORKSHOP & EVENTS</h1>
<!-- EVENT CALENDAR -->
<div class="calendar">
<div class="month text-center">June</div>
<div class="day text-center">30</div>
</div>
<!--EVENTS CALENDAR-->
<div class="events-info">Lorem Ipsum</div>
<div class="events-info">Dolor Sit Amet Sed</div>
<div class="events-info">Libero</div>
<button class="view-all-events">VIEW ALL</button>
</div>
<!-- WORKSHOP AND EVENTS-->
You can simply float the calendar box to the left. For a better result, wrap all events-info + button into a container (to avoid the text to wrap to new lines below the calendar box, see the demo).
HTML updates:
<div class="events-container">
<div class="events-info">Lorem Ipsum</div>
<div class="events-info">Dolor Sit Amet Sed</div>
<div class="events-info">Libero</div>
<button class="view-all-events">VIEW ALL</button>
</div>
CSS updates:
.workshop-events {
overflow: auto; /*fix possible collapses caused by floating*/
}
.calendar {
float: left;
margin-right: 20px;
}
.events-container {
overflow: auto; /*prevent the text to wrap below the calendar*/
}
.workshop-events {
width: 100%;
background-color: #f2f2f2;
padding: 20px;
}
.calendar {
width: 75px;
display: table-cell;
}
.calendar .month {
text-transform: uppercase;
font-size: 16px;
border: 1px solid #b2b2b2;
padding: 3px 0;
background: #FFF;
}
.calendar .day {
font-size: 30px;
font-weight: 500;
border: 1px solid #b2b2b2;
border-top: none;
padding: 7px 0;
background: #FFF;
}
.calendar .day {
font-size: 30px;
font-weight: 500;
border: 1px solid #b2b2b2;
border-top: none;
padding: 7px 0;
background: #FFF;
}
.events-info {
font-weight: bold;
font-size: 14px;
}
/*NEW RULES BELOW*/
.workshop-events {
overflow: auto;
}
.calendar {
float: left;
margin-right: 20px;
}
.events-container {
overflow: auto;
}
<div class="workshop-events">
<h1 class="section-heading">WORKSHOP & EVENTS</h1>
<!-- EVENT CALENDAR -->
<div class="calendar">
<div class="month text-center">June</div>
<div class="day text-center">30</div>
</div>
<!-- EVENTS INFO-->
<div class="events-container">
<div class="events-info">1. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="events-info">2. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="events-info">3. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<button class="view-all-events">VIEW ALL</button>
</div>
</div>
<!-- WORKSHOP AND EVENTS-->