How to override width without setting to 100%? - css

How do I override the width of #mydiv in the media query so it is basically 100%? If I explicitly set it to 100% that will push padding outside of the div, creating horizontally scrolling on a smaller screen.
In Safari Developer Tools style pane, I can uncheck width:800px and everything looks fine at the smaller screen. How do I translate that into code? What is the uncheck/toggle doing to width in code?
#mydiv {
width:800px;
margin: 0 auto;
}
#media screen and (max-width:450px){
padding:10px;
}

As requested, publishing:
Simply apply box-sizing:border-box; to your CSS for the item, and it will fit width:100%; just fine.
As a side note, you should consider applying it to everything at the top of your CSS:
* {
-moz-box-sizing:border-box; /* Firefox */
-webkit-box-sizing:border-box; /* iOS4, < Android 3.0 */
box-sizing:border-box;
}
There is a great article here about the many advantages (for one, it works all the way back to IE8). I personally use it on all my projects, never fails me.

You could use box-sizing, however, you could also use any of the following as well:
#mydiv {
width:800px;
margin: 0 auto;
}
#media screen and (max-width:450px){
padding:10px;
width:auto; /* this will put the width back */
}
or
#mydiv {
max-width:800px; /* this will constrain the width to a maximum of 800, but will have a different effect for widths between 800px and 450px */
margin: 0 auto;
}
#media screen and (max-width:450px){
padding:10px;
}

Related

Fluid Typography—Different text sizes when setting div width

I am trying to utilize fluid typography and so far it's been going good but I am having an issue with one of my breakpoints. When I test on iphone 11 (landscape mode), text in divs that are set to greater than 50% of the viewport expand the "p" text within that div and also any "p" text outside the div. It is like it sets a new minimum/maximum. I am trying to have a set p size, no matter the width of the div. Any help appreciated!
Here is an example page that demonstrates this issue: https://sandbox.kikawebdesign.com/sample-page/
Screenshot of example page
Update 08/22/2022:
I apologize for not putting in all the information here originally. I thought it would be easier to read the text on the provided URL. But here is what my testing hows shown:
After testing, it seems that anytime I set div width larger than 50 (%, vw, rem, em, etc), the “p” text size for that div increases greatly. In addition, it increases any/all “p” text size that is not within a set div width. My goal is to have the “p” text inside a div to be the same size as the regular “p” text regardless of the width of the div.
Desktop, iPad (both portrait and landscape), and iPhone (portrait) display fine but on the iPhone (landscape), I am getting this issue (tested in both Safari and Edge browsers). For testing purposes, I have an iPhone 11.
Here is the code
html {
font-size:1.25vw;
margin:0!important;
padding:0!important;
}
body {
font-size: calc(14px + (18 - 14) * ((100vw - 768px) / (1920 - 768)));
color:var(--text);
font-family:var(--bodyfont);
margin:0;
padding:0;
}
#divtest {
float:left;
width:100vw;
padding:0;
margin:0;
}
.testing1 {
width: 45vw;
float: left;
}
.testing2 {
width: 50vw;
float: left;
margin-left:5vw;
}
#divtest2 {
float:left;
width:100vw;
padding:0;
margin:0;
}
.testing3 {
width: 40vw;
float: left;
}
.testing4 {
width: 55vw;
float: left;
margin-left:5vw;
}
It took almost two days of research but I found this answer from an older thread, tested it, and it seems to be working.
The solution: I added the code below with a media query that targeted screens under the iPad portrait mode and above the iPhone portrait mode.
#media(max-width: 767px) and (min-width:667px){
html {
-webkit-text-size-adjust: 100%; /* Prevent font scaling in landscape */
}
/* html, body, div, p {
font-size:14px!important;
}*/
}
I wanted to post in case anyone else had this issue.

Forcing video to take 100% width of div

Currently developing a portfolio theme for a friend and trying to create a video background in the hero area.
Currently, it appears the video is only taking its natural width, is there any way to force this to stretch to fill 100% of the div? I'm not worried about quality, it's blurred anyways.
I'm using videoBG to embed the video content, and the following styles are applied to the containing div:
#hero {
min-width: 100%;
display: block;
height: 400px;
margin: 0 auto;
}
It was actually the 100% height that I was applying to the video that was throwing it off in the first place. Changing this to auto let the video stretch while setting overflow to hidden.
Try to use that:
#hero { /* div filled by video */
position:relative;
/* other properties ... */
}
#video { /* video div */
display:block;
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
}

Responsive Designs a basic understanding

since the hype is Responsive Web Design, and I already know how to write it, I am just here to clarify a few questions of my own before I keep doing something wrong if I am.
If we set a divs style like so:
div {
width:200px;
height:200px;
background: #000;
margin: 10px 5px;
}
Now to be responsive the way we want would we do-
div {
background:#000
}
#media screen and(max-width:1200px) {
div {
width:300px;
height:300px;
margin: 20px 5px;//Question is here
}
}
#media screen and(max-width:720px) {
div {
width:300px;
height:300px;
margin: 20px 5px;//question is here
}
}
#media screen and(max-width:360px) {
div {
width:200px;
height:200px;
margin: 10px 5px;
}
}
The question is in face if we set the margin or any style that is going to be the same for an for greater width or minimum width do we keep assigning it do can we leave it at that? So if we set the margin at 20px 5px will that stay with it until 1200px? And the same goes for reverse will it stay the same until it gets to 360px and then change?
It's just a question that has been bothering me.
The max-width:1200px media query will apply to all sizes below, meaning that you won't need to re-apply the same values again in the 720px one.
In comparison:
#media screen and (max-width:1200px) {
/* applies to all viewports below 1201px */
}
#media screen (min-width:721px) and (max-width:1200px) {
/* only applies to viewports above 720px and below 1201px */
}
In conclusion, seeing as the values in your second (720px) media query rule is the same as the bigger one, they are applied twice (not necessary).
i think use percentage value to margin and width. You can avoid the resizing problem

Collapsing divs to 100% of iphone layout

I truly wouldn't be posting a question if I hadn't already spent hours digging through files and researching. I must really not know what I'm looking for :-|
I want to know how and why divs in a container (or the container itself) can change to 100% width when a responsive design is scaled to iphone dimensions - like the below:
http://demo2.woothemes.com/whitelight/about/
the sidebar sits underneath the main content, then the divs inside stretch to 100%
It's driving me absolutely mad! Any help / direction must appreciated :)
Basic Media query responsive layout example:
Demo: http://jsbin.com/ayojan/1/edit
Resize browser to see effect.
div {
outline:solid black;
}
.content {
width:80%;
float:left;
}
.sidebar {
width:20%;
float:left;
}
#media only screen and (max-width: 767px) {
.sidebar {
width:100%;
float:none;
}
.content {
width:100%;
float:none;
}
}
Key points: inside the media query you unfloat the elements (float:none) and set them to width: 100%;

Responsive design template

I am new to responsive design, I want to make responsive menus, images, blocks and every thing in the website templates.
I ready that all width should be in percentage, I make this example
http://jsfiddle.net/hQBR6/
How can I make the form with it's input respond to different screen size without going below the ul??
Problem is, that you are mixing margin set in PX and widths set in %. When screen is resized below certain dimensions, there isn't enough space left for elements with margin that big and input falls below.
You should set your margins in % - if you are working on repsonsive design.
Here is how I modified your code to make it work:
ul#menu{
border:1px solid black;
display: inline-block;
float:left;
max-width:50%;
margin-left:5%; /* changed to percentage */
margin-top:36px; /* should be percentage as well*/
list-style-type:none;
}
ul#menu li{
display: inline-block;
float:left;
margin-right:36px; /* should be percentage as well*/
width: auto;
}
#header form {
display: inline-block;
margin-right:1%; /* changed to percentage */
float:right;
width:10%;
}
#header form input{
margin-top:28px;
background-color: #e0e0e0;
border-radius:4px;
border:none;
height: 26px;
color:#a6a6a6;
}
note: I played only with left/right margins and real dimensions are up to you.
Hope this helps
For your quick start please go through below link you will find nice examples to start responsive design.
http://twitter.github.com/bootstrap/

Resources