I am working on a mobile site where the page needs to change based on portrait and landscape mode. I have that part working. When the mobile device is in portrait mode it's suppose to display 4 boxes as such:
[] []
[] []
When in landscape mode, they are to be like this:
[] [] [] []
I have this mostly accomplished, however in both portrait and landscape mode, they are centered left. I have scoured this site and have found similar questions, but when trying to implement the solution, it doesn't seem to work. I would like them to be centered (using percentages instead of fixed width so it shows up correctly on any mobile device). I am not too familiar with CSS, so pardon me, but here is my code below:
/* Landscape mode (default) */
div.my_wrapper{
width: auto;
position:relative;
padding:20px;
}
div.my_innerBox {
width:100%;
float:left;
border: 1px solid green;
}
div.my_left_box{
float: left;
margin-right:10px;
padding: 20px;
/*margin-left:90px;*/
width: 16%;
border: 1px solid gray;
}
div.my_right_box{
float: left;
margin-right:10px;
padding:20px;
width: 16%;
border: 1px solid gray;
}
div.my_header{
padding:10px;
float:left;
width: 100%;
border: 1px solid gray;
margin-bottom:12px;
}
#media only screen and (orientation:portrait){
/* portrait mode */
div.my_wrapper{
width: inherit;
margin-left:auto;
margin-right:auto;
padding:20px;
}
div.my_innerBox {
width: 95%;
display:inline;
}
div.my_left_box{
float: left;
padding: 20px 10px;
/*margin-left:90px;*/
margin: 0 10px 10px 0;
width: 30%;
border: 1px solid gray;
}
div.my_right_box{
float: left;
margin: 0 10px 10px 0;
padding:20px 10px;
width: 30%;
border: 1px solid gray;
}
div.my_header{
padding:10px;
border: 1px solid gray;
margin-bottom:12px;
text-align:left;
float:left;
}
div.my_desc {
text-align:left;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
vertical-align:middle;
position:absolute;
float:left;
width:500px;
}
div.my_header_container {
width:100%;
float:left;
}
}
<div class="my_header_container">
<div class="my_header">Title Will Go here
<div class="my_desc">This is where the description content will go</div>
</div>
</div>
<div class="my_wrapper">
<div class="my_left_box">
Button 1
</div>
<div class="my_right_box">
Button 2
</div>
<div class="my_left_box">
Button 3
</div>
<div class="my_right_box">
Button 4
</div>
</div>
Also, I need where it says "this is where the content description will go" to be to the right of "Title Will Go here", and to be vertically centered.
Any help would be greatly appreciated. I am trying to learn css as I am more of a programmer, not a designer. Thank you, I appreciate any help you can send my way.
You should really consider using a SASS preprocessor and harness the power of numerous Compass extensions.
Here's how your issue is solved with SASS: http://sassbin.com/gist/5785963/
Note how much shorter and easier to read the code is.
#fredsbend said that you can't center something floated. Well, this is not true when SASS automatically sets the widths of all elements precicely to your liking, while you only provide column numbers.
First, you are missing the close bracket for the #media query.
You cannot expect to center something when a float has been applied to it.
I changed the float:left; on the .my_left_box and the .my_right_box to text-align:left; and added display:inline-block;. I then added margin: 0 auto; and text-align:center; to .my_wrapper and changed the width to 90%. I did not make these changes to the (orientation:portrait) section.
Here is the css:
/* Landscape mode (default) */
div.my_wrapper{
width: 90%;
position:relative;
padding:20px;
margin: 0 auto;
text-align:center;
}
div.my_innerBox {
width:100%;
float:left;
border: 1px solid green;
}
div.my_left_box{
margin-right:10px;
padding: 20px;
/*margin-left:90px;*/
display:inline-block;
width: 16%;
border: 1px solid gray;
text-align:left;
}
div.my_right_box{
margin-right:10px;
padding:20px;
display:inline-block;
width: 16%;
border: 1px solid gray;
text-align:left;
}
div.my_header{
padding:10px;
float:left;
width: 100%;
border: 1px solid gray;
margin-bottom:12px;
}
#media only screen and (orientation:portrait){
/* portrait mode */
div.my_wrapper{
width: inherit;
margin-left:auto;
margin-right:auto;
padding:20px;
}
div.my_innerBox {
width: 95%;
display:inline;
}
div.my_left_box{
float: left;
padding: 20px 10px;
/*margin-left:90px;*/
margin: 0 10px 10px 0;
width: 30%;
border: 1px solid gray;
}
div.my_right_box{
float: left;
margin: 0 10px 10px 0;
padding:20px 10px;
width: 30%;
border: 1px solid gray;
}
div.my_header{
padding:10px;
border: 1px solid gray;
margin-bottom:12px;
text-align:left;
float:left;
}
} /* Added here but maybe you want it somewhere else. */
div.my_desc {
text-align:left;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
vertical-align:middle;
position:absolute;
float:left;
width:500px;
}
div.my_header_container {
width:100%;
float:left;
}
Here is the jsfiddle: http://jsfiddle.net/tspT4/10/
I was not able to test this on a mobile but it should work
Related
This question already has answers here:
How can I show only corner borders?
(20 answers)
Closed 7 years ago.
I am trying to figure out how to use CSS to create the below effect.
I've tried to do this by creating 4 divs within a parent div and positioning them on all four sides.
This works, but breaks when I need those 4 divs to be transparent to the background and not a single color.
For example, I want to try to make this work again a picture background and not just a solid background.
If the background is solid I can make the 4 divs the same color as the background, the problem is that if the background is a picture I can't have the 4 divs match the background.
Also, I understand my fundamental approach to the problem might be wrong. I heard someone mentioning using a pseudo :before and :after to accomplish this effect for effectively, but I'm not sure how to do that.
Here I made it as close as I could get with the least code:
.daysleft {
position: relative;
padding: 20px;
width: 100px;
text-align: center;
}
.daysleft span {
display: block;
z-index: 2;
position: relative;
}
.white {
background-color: #fff;
height: 20px;
width: 101%;
position: absolute;
top: 50%;
left: 0;
z-index: 1;
transform: translateY(-50%);
}
.daysleft:before {
height: 100%;
content: "";
position: absolute;
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
width: 20px;
left: 0px;
top: 0;
}
.daysleft:after {
height: 100%;
content: "";
position: absolute;
border-right: 1px solid #ccc;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
width: 20px;
right: 0px;
top: 0;
}
<div class="daysleft"><div class="white"></div><span>37 Days left</span></div>
EDIT:
Found a way to interupt the borders! Awnser updated.
I'm guessing this is the sort of thing you want.
.container {
margin: 0 auto;
position:relative;
display: inline-block;
padding: 15px;
background: #ccc;
}
#content {
margin: 0 auto;
position:relative;
display: inline-block;
padding: 10px;
background: #ccc;
font-size: 38px;
color: #333;
}
#content:before, #content:after, #content>:first-child:before, #content>:first-child:after {
position:absolute;
width:15px;
height: 15px;
border-color:#777;
/* or whatever colour */
border-style:solid;
/* or whatever style */
content:' ';
}
#content:before {
top:0;
left:0;
border-width: 2px 0 0 2px
}
#content:after {
top:0;
right:0;
border-width: 2px 2px 0 0
}
#content>:first-child:before {
bottom:0;
right:0;
border-width: 0 2px 2px 0
}
#content>:first-child:after {
bottom:0;
left:0;
border-width: 0 0 2px 2px
}
<div class="container">
<div id="content">
<p><i>37</i> days left</p>
</div>
</div>
Example:
http://jsfiddle.net/link2twenty/5gjh6jkx/
demo
Try out this... here am using background as image
<div class="parent">
<div class="child">
37 days Left
</div>
</div>
CSS:
.parent{
background-color : #ccc;
padding : 20px;
width : 100%;
margin : 0 auto;
}
.child
{
width: 100%;
padding: 10px;
text-align : center;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
border: 15px solid #ccc;
border-image: url('https://i.stack.imgur.com/1WlsT.png') 34% repeat;
}
Try something like this FIDDLE
DEMO CODE
HTML
<div class="box1">
<div class="box2"></div>
<div class="box3"></div>
</div>
CSS
.box1{
position:relative;
background:#FFF;
width:200px;
height:200px;
border:solid 2px #090;
-webkit-border-radius: 3px;
border-radius: 3px;
margin:0 auto;
}
.box2{
position:absolute;
width:210px;
height:180px;
background-color:#FFF;
top:10px;
left:-5px;
}
.box3{
position:absolute;
width:180px;
height:210px;
background-color:#FFF;
top:-5px;
left:10px;
}
I am trying to make a basic button box with an arrow at the top of it...
http://jsfiddle.net/8K4qB/ --this is what it comes out to.. i can't make it align at the top in the middle of the bottom.
HTML Code
Read More
CSS Code
.button {
font-size: 15px;
color: white;
text-align: center;
padding:10px 30px 10px 30px;
margin:0 auto;
background: #2ecc71;
}
.test:before {
content:'';
position: absolute;
width: 0;
height: 0;
border-bottom: 20px solid #3498db;
border-right:50px solid transparent;
border-left:50px solid transparent;
}
I'd like it to look like the pic
In order to achieve the specific behaviour you're after you need to change your HTML as well as your CSS- otherwise centrally justifying a pseudo element correctly will elude you.. Change the elements in the example as required (e.g. the top level div can be changed to a.button.test)
REVISED FIDDLE
HTML
<div>
<div></div>
<div>text goes here</div>
</div>
CSS
div {
display:inline-block;
text-align:center;
}
div div:first-child {
display:block;
width: 0;
height: 0;
border-bottom: 10px solid darkorange;
border-right:30px solid transparent;
border-left:30px solid transparent;
margin: 0 auto;
}
div div:last-child{
display:block;
font-size: 15px;
color: white;
text-align: center;
padding:10px 30px 10px 30px;
margin:0 auto;
background: darkorange;
position:relative;
text-transform:uppercase;
}
Try this ,display:block so that your arrow still in the middle: DEMO
CSS:
.button {
font-size: 15px;
color: white;
text-align: center;
padding:10px 30px 10px 30px;
margin:0 auto;
background: #2ecc71;
display:block;position:relative;top:20px;
}
.test:before {
content:'';
position: absolute;
top:-20px;
width: 0;
height: 0;
border-bottom: 20px solid #3498db;
border-right:50px solid transparent;
border-left:50px solid transparent;
}
.middle{
padding-left:15px;
}
HTML:
<span class="middle">Read More</span>
Here is the link to my code
http://jsfiddle.net/8B875/
Why exactly is my my Textboxsquare not showing up?
The HTML
<div id="textbox"></div>
<div id="textboxSquare"></div>
The CSS:
* {
margin: 0; padding: 0;
}
#textbox {
border: 1px solid #848484;
-webkit-border-top-left-radius: 30px;
-moz-border-radius-topleft: 30px;
border-top-left-radius: 30px;
-webkit-border-top-right-radius: 30px;
-moz-border-radius-topright: 30px;
border-top-right-radius: 30px;
outline:0;
height:25px;
display: block;
box-sizing: border-box;
width: 300px;
padding-left:20px;
padding-right:20px;
}
#textboxSquare {
display:inline-block;
box-sizing: border-box;
height:25px;
width: 150px;
}
It is there, you just can't see its border. Add
border: 1px solid #848484;
and you will see it.
It is showing up, you just can't see it.
If you add border:1px solid pink; to the CSS you will see it.
Your first box has height and width, the second box doesn't have enough properties to be rendered visible. Add heigh, border properties etc.
I'm doing some HTML and am running into an issue with my left and right column divs not scaling based on the content inside them as well as in proportion to the rest of the page.
Here's my example:
http://i.imgur.com/9vi2EK9.png
And my CSS for each of the divs:
#wrapper{
background:white;
width:1280px;
position:relative;
border: 1px solid black; /* black border */
margin:auto; /* centre this div */
}
#header{
height:90px;
text-align:center;
padding: .5em;
background-color: grey;
border-bottom: 2px solid black;
}
#leftmenu{
width:100px;
float:left;
font-size: 75%;
padding:.5em;
border-right:2px solid black;
border-left:2px solid black,
}
#rightmenu{
width:180px;
float:right;
font-size: 75%;
padding:.5em;
border-left:2px solid black;
border-right:1px solid black;
}
#content{
background-color:white;
margin-left:120px;
font-size: 80%;
}
#footer{
clear:both; /* push footer under other divs */
height: 70px;
background-color:white;
border-top:1px solid black;
border: 1px solid black;
padding-top:40px;
text-align:center;
font-size: 70%;
}
How can I ensure that my divs resize based on the content in my other divs?
Thanks!
Without seeing your HTML, here's a stab at it:
JSFiddle here: http://jsfiddle.net/2hf8q/
CSS
html, body {
height: 100%;
}
#wrapper {
height: calc(100% - 2px); /* for border */
}
#leftmenu, #rightmenu {
height: calc(100% - 234px); /* for header, footer */
}
#wrapper {
background:white;
width:100%;
position:relative;
border: 1px solid black;
/* black border */
margin:auto;
/* centre this div */
}
#header {
height:90px;
text-align:center;
padding: .5em;
background-color: grey;
border-bottom: 2px solid black;
}
#leftmenu {
width:100px;
float:left;
font-size: 75%;
padding:.5em;
border-right:2px solid black;
border-left:2px solid black;
}
#rightmenu {
width:180px;
float:right;
font-size: 75%;
padding:.5em;
border-left:2px solid black;
border-right:1px solid black;
}
#content {
background-color:white;
margin-left:120px;
font-size: 80%;
}
#footer {
clear:both;
/* push footer under other divs */
height: 70px;
background-color:white;
border-top:1px solid black;
border: 1px solid black;
padding-top:40px;
text-align:center;
font-size: 70%;
}
HTML
<div id="wrapper">
<div id="header"></div>
<div id="leftmenu"></div>
<div id="content"></div>
<div id="rightmenu"></div>
<div id="footer"></div>
</div>
You can do it by wrapping #leftmenu, #content and #rightmenu in a div that is displayed as a table. And display the three children as a table-cell:
HTML:
<div id="header">#header</div>
<div id="wrapper">
<div id="leftmenu">#leftmenu</div>
<div id="content">#content</div>
<div id="rightmenu">#rightmenu</div>
</div>
<div id="footer">#footer</div>
CSS (without colors, padding, font sizes and stuff):
html, body {
margin: 0;
padding: 0;
}
#header{
height:90px;
}
#wrapper {
display: table;
table-layout: fixed;
width: 100%;
}
#wrapper > div {
display: table-cell;
}
#leftmenu{
width:100px;
}
#rightmenu{
width:180px;
}
#content{
}
#footer{
height: 70px;
}
And a working demo.
I tried using this guy's tutorial of making a 2 column layout:
http://www.vanseodesign.com/css/2-column-layout-code/
Here's how mine came out : / http://jsfiddle.net/WrpA8/
The CSS:
#container {
width: 800px;
margin: 40px auto;
border: 1px solid black;
}
#header {
border: 1px solid black;
}
#sidebar {
float: left;
width: 200px;
padding: 4px;
border: 1px solid black;
}
#content {
float: left;
width: 600px;
padding: 4px;
border: 1px solid black;
}
#footer {
clear: both;
border: 1px solid black;
}
Border and padding contribute to an element's overall width. Try setting the border and padding to 0 and you'll see that the layout works as expected. If you want a border and padding, you'll have to factor their size in when you size the main element.
Your padding and border actually are eating up your content of 600px. So, try to make it to 580px for example and it will work.
#content {
float: left;
width: 580px;
padding:4px;
border: 1px solid black;
}
or of course you could remove padding and border altogether if you want and stay with 600px size.
Check the demo here