How to align divs based on responsive design - html

I have some HTML and CSS code as shown below:
https://codepen.io/aspnetgal/pen/vaoNPz
*{
margin:0;
padding:0;
box-sizing:border-box;
}
.adv-signup {position: relative;
background-image: linear-gradient( #fff, #eff1f1);
width: 100%; height: 400px; }
.contents {position: absolute; width: 1000px;
height: 200px; background-color:#2183c2;
}
.contents .bg{
background: #ffffff url("https://s6.postimg.cc/ugw1p1pcx/sprite.png ") no-repeat left top;
margin:0;
}
.text{
font-family: "Ubuntu";
font-weight: light;
color:white;
}
.text h3{
font-weight: bold;
}
.controls
{
}
.btn
{
background: #0c5382;
color:white;
}
h3,h1{
padding: 0px;
margin: 0px !important;
}
/* Extra small devices (phones, 600px and down) */
#media only screen and (max-width: 600px) {
.adv-signup {background: red;}
}
/* Small devices (portrait tablets and large phones, 600px and up) */
#media only screen and (min-width: 600px) {
.contents {background: green;}
}
/* Medium devices (landscape tablets, 768px and up) */
#media only screen and (min-width: 768px) {
.contents {background: blue;}
}
/* Large devices (laptops/desktops, 992px and up) */
#media only screen and (min-width: 992px) {
.contents {background: orange;}
}
/* Extra large devices (large laptops and desktops, 1200px and up) */
#media only screen and (min-width: 1200px) {
.contents {background: pink;}
}
<div class="adv-signup">
<div class="contents">
<div class="bg">
<h1>test</h1>
</div>
<div class="text">
<h3>Sign up for E-News</h3>
<p>Leave your email and we’ll send you regular updates on programs, events and news.</p>
</div>
<div class="controls">
<input name="adv-sign-up-email-field" id="adv-sign-up-email-field" type="text" maxlength="255" value="Enter your email" />
>
</div>
</div>
<div>
For desktop, I want the div content which has text (heading and paragraph) and controls to be displayed in single line.
For tablet, I want the div content which has text (heading/paragragh vertically aligned) and controls to be displayed in a single line.
I want for a mobile the div content which has text heading, paragraph, and controls to be displayed in a vertical line.

backing Anji Response, you should write all your CSS under media queries. Below is the list of queries that you should minimum follow.
Min-width: 320px (smaller phone viewpoints)
Min-width: 480px (small devices and most phones)
Min-width: 768px (most tablets)
Min-width: 992px (smaller desktop viewpoints)
Min-width: 1200px (large devices and wide screens)
Note:- Setting with JS is anyway a costly JOB!!!

Updated js fiddle. https://codepen.io/anon/pen/BPXbjx
you need to add the below code.
.contents{
display:flex;
}
#media (max-width:767px){
.contents{
display:block;
}
}
I hope you can do the remaining styles.

Related

Make text responsive according to how tall the tab is

How would I go about having my text be bigger, so my text goes to the bottom of the tab (without a scrollbar showing up or anthing) and when the tab gets smaller, make the font smaller.
h1 {
font-size: ?;
}
div {
length: according to browser;
}
You can use height: 100vh; to set height according to screen height, and for font-size you can use #media queries to set font size for different screen.
body {
margin: 0px;
padding: 0px;
}
div.box {
height: 100vh;
background-color: #666;
}
h1 {
font-size: 50px;
color: #ffffff;
margin: 0px;
padding: 30px;
}
/* Extra small devices (phones, 600px and down) */
#media only screen and (max-width: 600px) {
h1 {
font-size: 25px;
}
}
/* Small devices (portrait tablets and large phones, 600px and up) */
#media only screen and (min-width: 600px) {
h1 {
font-size: 35px;
}
}
/* Medium devices (landscape tablets, 768px and up) */
#media only screen and (min-width: 768px) {
h1 {
font-size: 45px;
}
}
/* Large devices (laptops/desktops, 992px and up) */
#media only screen and (min-width: 992px) {
h1 {
font-size: 55px;
}
}
/* Extra large devices (large laptops and desktops, 1200px and up) */
#media only screen and (min-width: 1200px) {
h1 {
font-size: 65px;
}
}
<div class="box">
<h1>Karar Barcha</h1>
</div>
You can use vw for font-size if you want to be changed size by resizing of browser:
However, using vw for elements such as text means you may want to use media-queries for mobile devices to avoid very small text, such as the <p> element.
h1 {
font-size: 4vw;
}
<body>
<h1>arman ebrahimi</h1>
</body>

responsive bootstrap 4 cols for all devices

I'm working on a responsive profile page for all devices so I used the bootstrap 4 grid system to divide the page for my needs I wanted the page to look like this:- in desktops and like this:-
so what I have tried is col-sm to work responsibly with small screens
code snippet
/* Profile Main Page Cards , holders...etc */
.holderTitle{
font-family: hana;
font-size: 34px !important;
color:black !important;
text-align: center !important;
}
/* Profile Image Thubmail */
.ProfileAvatar{
border: 1px solid #ddd; /* Gray border */
border-radius: 4px; /* Rounded border */
padding: 5px; /* Some padding */
width: 150px; /* Set a small width */
}
/* Add a hover effect (blue shadow) */
.ProfileAvatar:hover {
box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
}
.holderText{
color:black !important;
}
.messagebtn{
text-align: center !important;
font-family: hana !important;
}
.fontawsomeBIO{
font-family: hana !important;
}
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops ( large Mointer )
*/
#media (min-width: 1281px) {
/* Profiler Card and Container (Profile Holder) on large Screen */
.profileholder{
width:45%;
height: auto;
}
/* ProfileHolder Ends Here */
/* Profile Content Card And Container */
.ProfileContent{
width: 100%;
height: auto;
}
}
/*
##Device = Laptops, Desktops
##Screen = B/w 1025px to 1280px
*/
#media (min-width: 1025px) and (max-width: 1280px) {
.profileholder{
width:70%;
height: auto;
}
/* ProfileHolder Ends Here */
/* Profile Content Card And Container */
.ProfileContent{
width: 100%;
height: auto;
}
}
/*
##Device = Tablets, Ipads (portrait)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) {
.profileholder{
width:95%;
height: auto;
}
/* ProfileHolder Ends Here */
/* Profile Content Card And Container */
.ProfileContent{
width: 100%;
height: auto;
}
}
/*
##Device = Tablets, Ipads (landscape)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
.profileholder{
width:75%;
height: auto;
}
/* ProfileHolder Ends Here */
/* Profile Content Card And Container */
.ProfileContent{
width: 100%;
height: auto;
}
}
/*
##Device = Low Resolution Tablets, Mobiles (Landscape)
##Screen = B/w 481px to 767px
*/
#media (min-width: 481px) and (max-width: 767px) {
.profileholder{
width:85%;
height: auto;
}
/* ProfileHolder Ends Here */
/* Profile Content Card And Container */
.ProfileContent{
width: 90%;
height: auto;
}
}
/*
##Device = Most of the Smartphones Mobiles (Portrait)
##Screen = B/w 320px to 479px
*/
#media (min-width: 320px) and (max-width: 480px) {
.profileholder{
width:100%;
height: auto;
}
/* ProfileHolder Ends Here */
/* Profile Content Card And Container */
.ProfileContent{
width: 100%;
height: auto;
}
}
<html>
<head>
<title>Responsive Profile</title>
<link rel="stylesheet" type="text/css" href="..\Styles\profile.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><!-- Bootstrap CDN Font-awesome -->
</head>
<body>
<!-- Bootstrap Jquery JavaScripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script><!-- Bootstrap Jquery JavaScripts -->
<div class="row">
<div class="col-sm-6">
<div class="container">
<br>
<div class="card profileholder">
<img class="card-img-top ProfileAvatar" src="..\upload\tmp\img.jpg" alt="alt"></img>
<div class="card-body">
<h4 class="card-title holderTitle">الإسم</h4><br><br>
<a name="PMbutton" id="private" class="btn btn-danger btn-block messagebtn" href="#" role="button">رسالة</a>
<a name="d" id="ds" class="btn btn-dark btn-block messagebtn" href="#" role="button">متابعة</a>
<i class="fas fa-map-marker-alt fas-3x" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
<div class="col-sm-auto">
<br>
<div class="card ProfileContent">
<div class="card-body">
Content Here tab panel....etc
</div>
</div>
</div>
</div>
</body>
advise :- show code in full page
at least the most important thing is the right container under the col-sm-auto <--- tag well contains a tab panel the panel will have more than 4 tabs which is a lot to fit all screen width in smartphones so the panel will have an x-scrolling any suggestion to make it responsive.
Bootstrap gives you some built in media queries by which you can define your layout.
Extra small devices (portrait phones, less than 576px) No media query
since this is the default in Bootstrap
Small devices (landscape phones, 576px and up) #media (min-width:
576px) { ... }
Medium devices (tablets, 768px and up) #media (min-width: 768px) {
... }
Large devices (desktops, 992px and up) #media (min-width: 992px) {
... }
Extra large devices (large desktops, 1200px and up) #media
(min-width: 1200px) { ... }
You can use mobile first approach to design your layout. Starting from 0px to 575px will be stated first than as you move higher in the resolution you can use media queries to handle your layout. The class col-sm-6 gives you ability to use 6 cols in a row. If you want that col to shrink at large desktop design to 4, you can add col-lg-4 besides col-sm-6. In this way your design will become responsive.
As far as the tab panel is consider, it depends upon your design. You can also apply nested technique or media list approach to handle your design on different resolution. Please consider bootstrap documentation for complete guidance. You can change col-sm-auto to col-sm-6 as well.

What can i do to make my code look good on 2 different screens

<style>
* {
box-sizing: border-box;
}
/* Create two equal columns that floats next to each other */
.column {
width: 50%;
left: 50%;
margin: 5px auto;
word-break: break-all;
font-family: "Times New Roman", Times, serif;
padding: 15px;
border-radius: 15px;
height: 15%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
.floated {
float:left;
margin-right:5px;
}
hr {
border: none;
height: 1px;
/* Set the hr color */
color: #333; /* old IE */
background-color: #333; /* Modern Browsers */
}
</style>
This is the css code for columns, inside these columns i have some icons and text displayed, it may look perfect on my screen, but look ruined on a laptop screen, what can i do to make it look good on every screen? I'm using % instead of px so it should set the height depending on the size of the screen?
HTML code for a column below;
<div class="row">
<div class="column" style="background-color:#edeeef;">
<body>
<p style="float:left; margin: 0 auto; cursor:pointer; border-radius: 50%;" onclick="location='http://localhost/badges.php?wear=<?php echo $b_id; ?>'"><?php echo $userbadge; ?></p>
<p style="float:left; margin: 15px 20px; font-size:19px; cursor:pointer; color:black" align="center"><?php echo $badgedesc; ?></p><p></p>
</body>
</div>
Use #media screen and (min-width:1000px){} with whatever dimensions suits you best, put alternate css inside the brackets of this query to set the styling for screen sizes that comply with the declaration.
e.g. any style put in this query will only apply to screen wider that 1000px
use developer tools to see at what widths you want to adjust the styling.
edit: You can also change the rule to 'max-width' if that helps, try researching css3 media queries to develop your own understanding fully
You can use media queries
Media queries are a popular technique for delivering a tailored style
sheet to different devices.
// Small devices (landscape phones, 576px and up)
#media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
#media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
#media (min-width: 992px) { ... }
// Extra large devices (large desktops, 1200px and up)
#media (min-width: 1200px) { ... }
or you can use bootstrap grid system and add pre defined classes to your elements
Bootstrap’s grid system uses a series of containers, rows, and columns
to layout and align content. It’s built with flexbox and is fully
responsive.
<div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div>

Larger header text for higher resolution displays

I have header text overlaid on an image. The issue is that on higher resolution desktop screens (e.g., > 1600px) the header only takes up a small section of the image width. I want the header text to take up ~90-100% of the available width regardless of the res.
http://www.dailyspiro.com
<div class="container-fluid">
<div class="col-md-12 landing-container">
<img src="images/pig.jpg" class="main-image" width="70%">
<div class="uvp">
<h1>Spread Compassion & Track Your Impact</h1>
<button class="join-button">Join Now</button>
</div>
</div>
</div>
.uvp {
padding: 5px 5px 5px 14px;
width: 70%;
background: rgba(66,51,51,.77);
margin: -119px auto 0px auto;
display: block;
text-align: left;
}
.uvp h1 {
color: #fff;
font-size: 247%;
margin-top: 12px;;
}
.landing-container {
padding: 0;
margin: -15px auto 0 auto;
text-align: center;
}
.main-image {
z-index: -1;
position: relative;
}
If you want the header take up ~90-100% of the available width space for higher resolution desktop screens (e.g., > 1600px), style the header accordingly using specific Media Queries.
You can use Media Queries, Some media queries for Standard Devices are:
/* Large screens ----------- */
#media only screen
and (min-width : 1600px) {
/* Styles */
/* Set your font-size here */
}
CSS:
/* Large screen above 1400px */
#media only screen and (min-width: 1400px) {
body {
.uvp h1 {
font-size: your larger size here;
margin-top: your larger size here;
}
}
}
Note: you have double (;;) semicolon in your above margin-top marking.
use cssmediaqueries
CSS Media Queries are a feature in CSS3 which allows you to specify
when certain CSS rules should be applied. This allows you to apply a
special CSS for mobile, or adjust a layout for print.
#media only screen and (max-width: 1633px) and (min-width: 1400px) {
.uvp h1 {
color: #fff;
font-size: 247%; //use your desired bigger font size
margin-top: 12px;;
}
}

How to make Facebook Comments have a fluid width of 100%?

http://developers.facebook.com/docs/reference/plugins/comments/
This is how I generate the comments area after including the Facebook javascript SDK on the page:
<div class="fb-comments fb-comments-update" data-href="http://site.com" data-width="600" data-colorscheme="light" data-num-posts="10" data-order-by="social" data-mobile="auto-detect"></div>
As you can see facebook sets the width of the comments area based on this data attribute you give it:
data-width="600"
In this case I am telling facebook I want the area to be 600 pixels. But I am currenly building a responsive site and need the comments section to fit the width of the screen 100%. Doing none of these works:
data-width="100"
data-width="100%"
Is there any way to get a fluid width for facebook comments?
Try this code:
<style>.fb-comments, .fb-comments iframe[style], .fb-like-box, .fb-like-box iframe[style] {width: 100% !important;}
.fb-comments span, .fb-comments iframe span[style], .fb-like-box span, .fb-like-box iframe span[style] {width: 100% !important;}
</style>
First size is for devices smaller then 1200px and bigger then 979px. The only problem is with IE sometimes, but you can use something like that: width: 1200px\9; - IE 8 and above
This sample is from bootstrap, which I'm using very often. To use it you need less win version. But this code works in aby browser (except old IE).
.fb-comments { width: 490px; /* or width: 50%; */ }
/* Large desktop */
#media (min-width: 1200px) {
.fb-comments { width: 600px; /* or width: 50%; */ }
}
/* Portrait tablet to landscape and desktop */
#media (min-width: 768px) and (max-width: 979px) {
.fb-comments { width: 400px; /* or width: 50%; */ }
}
/* Landscape phone to portrait tablet */
#media (max-width: 767px) {
.fb-comments { width: 30px; /* or width: 50%; */ }
}
/* Landscape phones and down */
#media (max-width: 480px) {
.fb-comments { width: 200px; /* or width: 50%; */ }
}
Also try to use percentage, not pixels, even with padding, for example:
.fb-comments { width: 90%; height: auto; padding: 0 5%; }