CSS styling not symmetrical in different size window - html

So I made a simple page that looks like below:
It looks fine but if I change it to a smaller window or changing the zoom %, this is what it looks like:
As you can see, it's not right as the button is way off but the <p> and <h> tag seems to be align but not the button.
Here is my relevant part of the code:
function Pitch() {
return (
<div className="section">
<div className="descriptionpitch">
<h1>See what's next.</h1>
<p>WATCH ANYWHERE. CANCEL ANYTIME.</p>
</div>
<div className="joinbutton">
<button>JOIN FREE FOR A MONTH</button>
</div>
</div>
);
}
scss:
.section {
color: white;
margin: 0 3%;
position: absolute;
top: 35%;
font-size: 1.8vw;
//text-align: center;
#media (max-width: 1000px) {
top: 55%;
font-size: 1.9vw;
}
#media (max-width: 800px) {
top: 60%;
font-size: 3.2vw;
margin: 0 4em;
text-align: center;
}
h1 {
font-size: 3em;
margin: 0 0 0.2em;
font-weight: 700;
}
p {
margin: 0 3.5em 0 0;
font-weight: 700;
}
button {
font-size: 14px;
letter-spacing: 1.9px;
font-weight: 100;
margin: 1.2em 24.5em 0 0;
padding: 12px 2em;
color: white;
background-color: #e50914;
cursor: pointer;
text-decoration: none;
//vertical-align: middle;
font-family: Arial, sans-serif;
border-radius: 2px;
user-select: none;
// text-align: center;
border: 0;
&:hover {
background-color: #e53935;
}
}
}
Is there a way i could fix this?

Try this code..add this in same div.. if u want more space at the top of the button. add margin-top for this button
function Pitch() {
return (
<div className="section">
<div className="descriptionpitch">
<h1>See what's next.</h1>
<p>WATCH ANYWHERE. CANCEL ANYTIME.</p>
<button>JOIN FREE FOR A MONTH</button>
</div>
</div>
);
}
And modify this css code too..
css
#media (max-width: 800px) {
.section {
text-align: left;
}
}

In your CSS code, make on change, remove text-align: center; from this block
...
#media (max-width: 800px) {
top: 60%;
font-size: 3.2vw;
margin: 0 4em;
/* text-align: center; */
}
...
working demo on stackblitz here

Remove the margin-right from the button in your 800px media query.

Related

How to make a div the same size as the div above in a Boostrap grid column?

this is my first question here, be gentle, I just started learning those things :)
I'm working on building a practice page using only HTML, Sass and bootstrap-grid.css (so basically using only rows and columns, card classes are not included in the file, I styled them separately) and I encountered a probably very simple problem that keeps me awake at night.
I need to make all .card-text divs (the white background ones) the same witdh "visually" as the img above them, but simply resizing the .card-text divs or making them absolutely positioned doesn't seem as the right solution due do creating another problems, and I want to keep the .col- because of easy RWD outcomes. The .card-text and .card-img divs inherit the given width of the .col-, the images in have to keep the right proportion and because of the grey background of .card-img is the same as the whole section's background the problem lies only in .card-text (at least visually).
The column structure in a .row looks like this:
<div class="col-md-4">
<div class="card">
<div class="card-img">
<img src="images/r1i1.jpg" alt="image">
</div>
<div class="card-text">
<h6>Ebony & Ivory</h6>
<h5>Branding</h5>
</div>
</div>
</div>
And so on (six columns) and the sccs for this section looks like this:
.portfolio {
background-color: $color-background;
.card {
background-color: $color-background;
padding: 20px;
.card-img {
height: 300px;
margin: 0 44px;
overflow: hidden;
img {
vertical-align: bottom;
height: 100%;
}
}
.card-text {
background-color: $color-body;
padding-top: 29px;
padding-bottom: 27px;
}
h5 {
margin: 2px 0 0 0;
font-weight: lighter;
font-family: $font-decor;
color: #737373;
font-size: 14px;
}
h6 {
font-family: $font-text;
font-weight: bold;
font-size: 18px;
margin: 0;
color: #333333;
}
}
.col {
padding-top: 45px;
}
}
Screenshots with inspection of the divs:
.card
.card-text
EDIT:
The scss styles that finally worked:
.portfolio {
background-color: $color-background;
.card {
background-color: $color-background;
margin: 0 44px 50px 44px;
.card-img {
overflow: hidden;
img {
vertical-align: bottom;
width: 100%;
}
}
.card-text {
background-color: $color-body;
padding-top: 29px;
padding-bottom: 27px;
h5 {
margin: 2px 0 0 0;
font-weight: lighter;
font-family: $font-decor;
color: #737373;
font-size: 14px;
}
h6 {
font-family: $font-text;
font-weight: bold;
font-size: 18px;
margin: 0;
color: #333333;
}
}
}
.col {
padding-top: 45px;
}
}
So the problem was, of course, that I made a deadly sin by setting constant height to .card-img.
Just add the same margin: 0 44px that you have added for the .card-img to your .card-text element and then add width: 100% to both the elements so that they occupy the full width of their parent div and you should get the equal width for both elements as you wanted.
Check and run the following Code Snippet for a practical example of the above approach:
html, body {margin: 0px; padding: 0; width: 100%; height: 100%;}
.portfolio {
background-color: #222;
}
.portfolio .card {
background-color: #222;
padding: 20px;
}
.portfolio .card .card-img {
height: 300px;
margin: 0 44px;
overflow: hidden;
}
.portfolio .card .card-img img {
vertical-align: bottom;
height: 100%;
width: 100%;
}
.portfolio .card .card-text {
background-color: #333;
padding-top: 29px;
padding-bottom: 27px;
width: 100%;
margin: 0 44px;
}
.portfolio .card h5 {
margin: 2px 0 0 0;
font-weight: lighter;
color: #737373;
font-size: 14px;
}
.portfolio .card h6 {
font-weight: bold;
font-size: 18px;
margin: 0;
color: #333333;
}
.portfolio .col {
padding-top: 45px;
}
<script src="https://code.jquery.com/jquery-3.4.1.slim.js"></script><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css" /><script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<section class="portfolio">
<div class="col-md-4">
<div class="card">
<div class="card-img">
<img src="https://picsum.photos/240/360" alt="image">
</div>
<div class="card-text">
<h6>Ebony & Ivory</h6>
<h5>Branding</h5>
</div>
</div>
</div>
</section>
Set your img width to 100% rather than height.
Remove padding from .card
Remove margin from .card-img
Hope that works:)
Add certain width to card-img and then move .card-text div inside card-img and change the css styles for card-img.
I have modified your code and added it to the snippet.
Have a look once.
.card {
background-color: #fff;
padding: 20px;
}
.card-img {
width: 150px;
margin: 0 44px;
overflow: hidden;
}
img {
width: 100%;
}
.card-text {
position: relative;
text-align:center;
top: -4px;
background-color: aliceblue;
padding-top: 29px;
padding-bottom: 27px;
}
h5 {
margin: 2px 0 0 0;
font-weight: lighter;
color: #737373;
font-size: 14px;
}
h6 {
font-weight: bold;
font-size: 18px;
margin: 0;
color: #333333;
}
.col {
padding-top: 45px;
}
<div class="col-md-4">
<div class="card">
<div class="card-img">
<img src="https://p1.pxfuel.com/preview/844/972/952/suit-model-businessman-corporate-royalty-free-thumbnail.jpg" alt="image">
<div class="card-text">
<h6>Ebony & Ivory</h6>
<h5>Branding</h5>
</div>
</div>
</div>
</div>
Image Source: Google
Hope this helps!!

All new HTML appears behind an image?

I have been working on a responsive web design, after adding CSS to make a link stay centered on a an image the webpage now displays any new html behind the image. I want to be able to add more things on my webpage but any new html I write disappears.
Link to JSFIDDLEhttps://jsfiddle.net/R4bbit2k17/7yuL4y1p/1/#&togetherjs=MEzytpw3kf`
Because your .banner-inner is using position: absolute in conjunction with taking up 100% of the width and height, you'll need to set a position other than static for your text element(s), along with giving them a z-index greater than the default of 0:
p {
background: red; /* Purely to highlight the text */
position: relative;
z-index: 1;
}
This causes your text to appear on top of your image, and can be seen in the following:
body {
font-family: helvetica;
font-size: 15px;
line-height: 1.5;
padding: 0;
margin: 0;
background-color: #f4f4f4;
}
header {
background: black;
color: white;
padding-top: 20px;
min-height: 45px;
}
header a {
color: white;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header ul {
margin: 0;
padding: 0;
}
header li {
float: left;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
float: right;
margin-top: 5px;
}
#media only screen and (max-width:1000px) {
.centered {
font-size: 12pt!important;
}
}
#media only screen and (max-width:800px) {
.centered {
font-size: 11pt!important;
}
}
#media only screen and (max-width:600px) {
.centered {
font-size: 10pt!important;
}
}
#media only screen and (max-width:400px) {
.centered {
font-size: 9pt!important;
}
}
#media only screen and (max-width:200px) {
.centered {
font-size: 8pt!important;
}
}
.banner-inner {
width: 100%;
height: 100%;
position: absolute;
text-align: center;
color: white;
}
.centered {
position: absolute;
margin-left: auto;
margin-right: auto;
width: 100%;
height: auto;
margin-top: 20%;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
font-size: 12pt;
}
.img {
width: 100%;
height: auto;
float: left;
}
p {
background: red;
position: relative;
z-index: 1;
}
<body>
<header>
<div id="header-inner">
<nav>
<ul>
<li>Home</li>
<li>Courses</li>
<li>About</li>
</ul>
</nav>
</div>
</header>
<section class="section-1">
<div class="banner-inner">
<img class="img" alt="" src="https://d2mt0dng9y3p4j.cloudfront.net/newandimproved/wp-content/uploads/2016/12/shop-with-a-sheriff-mockup.jpg">
<div class="centered">Start Learning</div>
</div>
</section>
<p>ANY HTML ADDED APPEARS BEHIND THE IMAGE AND I CANNOT FIGURE OUT HOW TO CHANGE IT TO APPEAR BENEATH THE IMAGE AS IT WOULD WITH A FRESH HTML PAGE</p>
</body>
Hope this helps!

How can I add flexbox on my Wordpress Site

Hey guys I am trying to apply flexbox on my wordpress site.
Based on what I know Flexbox is a shorthand of "Flexible Box Layout Module", which is a CSS3 module, standardized by the World Wide Web Consortium.
So I don't have to install anything, compliant browsers support it natively but for some reason it won't work on my site: http://americanbitcoinacademy.com/course-list/
Currently I am using flex on my codes:
<div class="flex">
<div class="col-1-3">
<img src="http://americanbitcoinacademy.com/wp-content/uploads/2017/01/The-Bitcoin-Transaction-Landscape.jpg" />
<h3 style="text-align: center;">BC 101 - The Bitcoin Transaction COURSE</h3>
<p>This course covers the basics of what Bitcoin is and how the Blockchain works, how to use a Bitcoin Wallet and why Bitcoin is important.</p>
<button class="btn btn-block btn-primary">PURCHASE COURSE →</button>
</div>
</div>
.col-1-3 {
padding: 10px;
width: 28%;
float: left;
margin: 2.5%;
border: 1px solid #dedede;
-webkit-border-radius: 7px;
-moz-border-radius: 7px;
border-radius: 7px;
padding-bottom: 0px;
font-family: 'Lato', Verdana;
}
.col-1-3 img {
width: 100%;
}
.col-1-3 img {
width: 100%;
}
a {
margin: 0;
}
h3 {
margin: 15px auto;
font-size: 16px;
font-weight: bold;
text-transform: uppercase;
}
p{
line-height: 16px;
margin: 10px auto;
}
h4 {
margin: 0 0 20px 0;
}
}
.btn-block {
display: block;
width: 100%;
margin-top: 22px;
background: #DD374D;
}
button.btn-block{
background: #DD374D;
font-family: 'Roboto';
margin-bottom: 10px;
font-weight: bold;
}
}
#media only screen and (max-width: 767px) {
.col-1-3 {
width: 44%;
}
}
#media only screen and (max-width: 590px) {
.col-1-3 {
width: 94%;
}
}
.flex {
display: flex;
flex-wrap: wrap;
}
Which will do the trick to have equal size of the boxes NO MATTER HOW LONG IS THE CONTENT on that page by default.
Any idea why does the flexbox doesnt work?
Thank you in advance.
Your code works. You are probably not testing in a flex box capable browser:
http://caniuse.com/#search=flexbox
To align buttons to bottom:
.col-1-3 {
position: relative;
padding-bottom: 40px; /* offset height of button */
}
button.btn-block{
position: absolute;
bottom: 0px;
width: calc(100% - 20px);
}

Responsive fixed-width image showcase without JS

I'd like to create simple responsive website containing a showcase of pictures. By myself, but if there's a template, no problem. But I want to learn it anyway.
Requirements:
images with one width no matter the browser width
images always in the middle of the page (0 auto)
number of columns - images changing with the browser width
no height limitation of the image. only fixed width (+ keep aspect ratio).
perfect example: www.kristianhammerstad.com - try to resize the window, I'd like to achieve exactly this. Works also on mobile browser (shows image after image)
I'd prefer without JS, only media queries - possible?
Here's what I have so far:
* { margin: 0; padding: 0; -webkit-font-smoothing: antialiased; font-smoothing: antialiased; }
body { font: normal 14px Helvetica, Arial, sans-serif; line-height: 30px; color: #333; }
.left { float: left; }
.right { float: right; }
.clearfix:before,
.clearfix:after { content: " "; /* 1 */ display: table; /* 2 */ }
.clearfix:after { clear: both; }
hr {
margin: 0;
border: 0;
width: auto;
border-top: 1px solid #aaaaaa;
opacity: .25;
margin: 0 auto;
}
h1 {
letter-spacing: 2px;
font-weight: 300;
text-align: center;
font-size: 2em;
line-height: 1.3em;
color: #333;
}
h2 {
letter-spacing: 1px;
font-weight: 300;
text-align: center;
font-size: 1em;
margin-bottom: 60px;
color: #666;
text-transform: uppercase;
}
/* ---------------------------------------------------------- */
.wrapper {
width: 950px; margin: 0 auto;
}
#name {
margin-top: 50px;
}
/* ---------------------------------------------------------- */
#works {
margin-top: 50px;
}
#works h2 {
font-family: Helvetica, Arial, sans-serif;
letter-spacing: 1px;
font-weight: 300;
text-align: left;
font-size: 1.3em;
margin-bottom: 10px;
color: #666;
text-transform: none;
}
#work-one {
display: block;
width: 460px;
height: 500px;
margin-right: 30px;
margin-bottom: 30px;
}
#work-two {
display: block;
width: 460px;
height: 300px;
}
#work-three {
display: block;
width: 460px;
height: 700px;
margin-bottom: 30px;
}
#work-four {
display: block;
width: 460px;
height: 200px;
}
/* ---------------------------------------------------------- */
#media (min-width: 768px) and (max-width: 1024px) {
/* I am not sure about break points */
}
#media only screen and (min-width: 320px) and (max-width: 767px) {
/* I am not sure about content here */
}
<div class="wrapper">
<div id="name">
<h1>IMAGES</h1>
<h2>showcase</h2>
</div>
<div id="works">
<div class="left">
<a id="work-one" href="#"><img src="http://placehold.it/460x500?text=Placeholder" ></a>
<a id="work-two" href="#"><img src="http://placehold.it/460x300?text=Placeholder" ></a>
</div>
<div class="right">
<a id="work-three" href="#"><img src="http://placehold.it/460x700?text=Placeholder" ></a>
<a id="work-four" href="#"><img src="http://placehold.it/460x200?text=Placeholder" ></a>
</div>
</div><div class="clearfix"></div>
</div>
First of all it would recommend using a grid system. One common known and used would be bootstrap.
With it you can easily set your wanted layout.
Second, to achieve this "repositioning" effect, you would need a JS library called masonry. It hooks itself in the resize event as well as initially on initialization of the dom.
There it calculates the width of the container wrapping all images and the width of the images, calculates the new positions using complex algorithms, and reposition them using the animation effect you see.
Maybe this tutorial (with source) will help you further: http://creative-punch.net/2014/01/full-screen-image-gallery-using-css-masonry/

CSS Background-Image not displaying?

I've all of a sudden got a problem trying to display a background-image in CSS.
The image is invisible!
I'm trying to use this background image specifically for a certain location on the page, before scrolling down further to another image or background.
Can anyone shed some light on this situation and possibly provide the correct code/explain why I was wrong?
Thanks in advance!
HTML:
<!doctype html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Oswald:400,700' rel='stylesheet' type='text/css'>
<link rel='stylesheet' href='style.css'/>
</head>
<body>
<div class="main">
<div class="container">
<h1>Move</h1>
<p> Form healthy habits to take your fitness to the next level. </p>
Start Now
</div>
</div>
<div class="supporting">
<div class="container">
<div class="col">
<h2>Move</h2>
<p>Become more active by tracking your runs, rides, and walks.</p>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="feature">
<div class="container">
</div>
</div>
</body>
</html>
CSS:
html, body {
margin: 0;
}
h1, h2, a {
font-family: 'Oswald', sans-serif;
}
p {
font-family: Helvetica, Arial, sans-serif;
}
.container {
width: 940px;
margin: 0 auto;
}
/* Main */
.main {
background-image: url ("https://yt3.ggpht.com/-QkqvzArFkYs/AAAAAAAAAAI/AAAAAAAAAAA/qw97foQDUbQ/s900-c-k-no/photo.jpg");
height: 600px;
}
.main h1 {
font-size: 150px;
color: white;
text-align: center;
}
.main p {
font-size: 18px;
}
/* Supporting */
.supporting {
text-align: center;
padding: 50px 0 80px;
}
.supporting .col {
float: left;
width: 28%;
padding: 10px;
}
.supporting h1,
.supporting h2 {
color: #ffa800;
font-size: 20px;
margin-bottom: 10px;
}
.clearfix {
clear: both;
}
.supporting p {
color: #efefef;
margin-bottom: 20px;
line-height: 20px;
font-size: 12px;
}
.supporting .btn {
background-color: #eee;
color: #1c1c1c;
font-size: 18px;
padding: 8px 30px;
text-decoration: none;
display: inline-block;
}
/* Feature */
.feature {
height: 600px;
}
.feature h1,
.feature h2 {
color: #fff;
font-size: 40px;
margin: 0;
padding:50px 0 0;
}
/* Footer */
.footer {
height: 600px;
}
.footer h1,
.footer h2 {
color: #fff;
font-size: 40px;
margin: 0 0 20px 0;
padding:50px 0 0;
}
.footer p {
color: #fff;
margin: 0 0 20px 0;
font-size: 18px;
}
#media (min-width:600px) {
.main h1 {
font-size: 200px;
}
.supporting .col {
width: 30%;
}
.supporting h2 {
font-size: 40px;
}
.supporting p {
font-size: 14px;
}
.feature h2 {
font-size: 60px;
}
}
Remove space between url and ( in your CSS.
Copy paste URL in Browser if u can see it then may be add Id to div and hard code inside div, try to modify image size and style using view element in any one of the popular browsers.
Then create css for id and try it again .. Even I m new to Css but it always works ..
Or replace HTTP instead of HTTP.. if u dont have certificate then may be it will not show up ..
Maybe just remove the space in the CSS?
background-image: url("https://yt3.ggpht.com/-QkqvzArFkYs/AAAAAAAAAAI/AAAAAAAAAAA/qw97foQDUbQ/s900-c-k-no/photo.jpg");