I am reading HTML and CSS by Jon Duckett, and have been introduced to the border-radius property.
I am trying to create a circle using the code below, but the circle is not perfect. I am using the radius of 50px but it isn't perfect.
p {
border: 5px solid #ee3e80;
padding: 10px;
width: 100px;
height: 100px;
display: inline-block;
margin: 20px;
}
p.three {
padding: 0px;
border-radius: 50px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
}
<p class="three"></p>
What am I doing wrong?
padding and the width of the border is calculated additionally to the width and height of your element.
You have different options to solve this:
add box-sizing: border-box to your element which defines what should include in the size calculation
use border-radius: 50%
add your border-width and padding to your border-radius.
Here the solution just with box-sizing
p {
display: inline-block;
margin: 20px;
width: 100px;
height: 100px;
/* these values get added to your 100px by default */
border: 5px solid #ee3e80;
padding: 10px;
}
p.three {
padding: 0px;
border-radius: 50px;
/* now width and height determine how big your
element is as a whole */
box-sizing: border-box;
}
<p class="three"></p>
For a more detailed explanation about the CSS box model look at this article from MDN.
It should be 50%, not 50px. 50% will always draw a circle regardless of the size of the element. Setting a pixel value will only draw a circle if the element is sufficiently small.
See below.
p {
border: 5px solid #ee3e80;
padding: 10px;
width: 100px;
height: 100px;
display: inline-block;
margin: 20px;
}
p.three {
padding: 0px;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
}
<p class="three"></p>
It's because you didn't take into account the width coming from the border width, which is 5px on each end. So the total width is 110px, so your border radius will need to be 55px. An easier way for a perfect circle is to just set border-radius to 50%.
p {
border: 5px solid #ee3e80;
padding: 10px;
width: 100px;
height: 100px;
display: inline-block;
margin: 20px;
}
p.three {
padding: 0px;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
}
<p class="three"></p>
You just need to add 50% to the border-radius property. Below is a snippet and you will find it is a perfect circle.
p {
border: 5px solid #ee3e80;
padding: 10px;
width: 100px;
height: 100px;
display: inline-block;
margin: 20px;
}
p.three {
padding: 0px;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
}
<p class="three"></p>
Yet another option is to set your element's box-sizing property to border-box (as I do for nearly all elements).
p {
border: 5px solid #ee3e80;
padding: 10px;
width: 100px;
height: 100px;
display: inline-block;
margin: 20px;
box-sizing: border-box; /* < -------------------- here */
}
p.three {
padding: 0px;
border-radius: 50px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
}
<p class="three"></p>
Border-box takes into consideration border when doing math, and generally simplifies layout and styling when applied across the board. Libraries like Bootstrap do this for you.
Related
I have a small "floating_Note_DIV" which I want to display on top of a textarea, as shown in the pictures. As well, I want to show a yellow_DIV below the textarea, flushed with the bottom edge of the textarea. If I do not display the floating_Note_DIV, the textarea is flushed with yellow_DIV (seen below in Image_1).
However, if I display the floating_Note_DIV, a gap appears between the textarea and the yellow_DIV ; i.e., I was thinking that if I put position: relative, and top and left/right I would get the f_N_DIV to fly over the textarea. It does seem to work however it looks like a gap is left where the "footprint" of the f_N_Div is left behind, at it's "supposed-to-be" position between tomato_DIV and yellow_DIV (see below Image_2).
If I use position "Absolute" it gets positioned w.r.t to the whole page, I am expecting the tomato_DIV to move around and so the f_N_DIV will have to be positioned w.r.t the textarea or tomato_DIV.
Any workaround? Thanks, all help appreciated ! !
the HTML is:
<div id='tomato_DIV' >
<textarea id="textarea_main" cols="40" rows="3" maxlength="300"></textarea>
<div id="floating_Note_DIV">Your Thoughts!!</div>
<div id="yellow_DIV"></div>
</div>
the relavant CSS is:
#tomato_DIV
{ background-color: tomato;
padding: 0px 0px 5px 0px;
width: 310px;
border-radius: 5px; }
#textarea_main
{ box-sizing: border-box;
margin: 5px 5px 0px 5px; padding: 2px; /* note: bottom margin is 0 to make flush with yellow div */
width: calc(100% - 10px);
height: 75px;
resize: none; outline: none;
border: 1px solid #737d96; border-radius: 3px; }
#floating_Note_DIV
{ margin: 0px 0px 0px 0px;
padding: 0px 2px 0px 0px;
position: relative; /* how to do this bit? */
right: -232px;
top: -14px;
width: 70px;
height: 11px;
font-size: 8px; font-style: normal; font-weight: bold; color: black;
text-align: right; border: 1px solid #737d96; }
#yellow_DIV
{ margin: 0px 5px 5px 5px; /* note: top margin is 0 to make flush with textarea */
border: 1px solid grey;
border-radius: 3px;
width: calc(100% -10px);
height: 30px; background-color: #fdffb6; }
Is this what you are trying to achieve?
HTML : Put the #floating_Note_DIV element inside #yellow_DIV. You could leave it where it is, but setting top CSS property would have been difficult.
CSS :
Change position property of #floating_Note_DIV from relative to absolute.
Set position property of #yellow_DIV to relative.
Set right to 0.
Set bottom to 100%.
I modified the margin-bottom to 5px to align it perfectly.
#tomato_DIV {
background-color: tomato;
padding: 0px 0px 5px 0px;
width: 310px;
border-radius: 5px;
}
#textarea_main {
box-sizing: border-box;
margin: 5px 5px 0px 5px;
padding: 2px;
/* note: bottom margin is 0 to make flush with yellow div */
width: calc(100% - 10px);
height: 75px;
resize: none;
outline: none;
border: 1px solid #737d96;
border-radius: 3px;
}
#floating_Note_DIV {
margin: 0px 0px 5px 0px;
padding: 0px 2px 0px 0px;
position: relative;
position: absolute;
right: 0;
bottom: 100%;
width: 70px;
height: 11px;
font-size: 8px;
font-style: normal;
font-weight: bold;
color: black;
text-align: right;
border: 1px solid #737d96;
}
#yellow_DIV {
margin: 0px 5px 5px 5px;
/* note: top margin is 0 to make flush with textarea */
border: 1px solid grey;
position: relative;
border-radius: 3px;
width: calc(100% -10px);
height: 30px;
background-color: #fdffb6;
}
<div id='tomato_DIV'>
<textarea id="textarea_main" cols="40" rows="3" maxlength="300">
</textarea>
<div id="yellow_DIV">
<div id="floating_Note_DIV">Your Thoughts!!</div>
</div>
</div>
Is there any way to create the border on the left with css ?
Here is a way to do it using CSS; you are just layering a Parallelogram and a Rectangle:
.espanolIcon
{
width: 300px;
height: 100px;
padding-left: 30px;
}
.rectangle {
position: absolute;
top: 0px;
left: 200px;
width: 200px;
height: 100px;
background-color: green;
border-radius: 0px 0px 30px 40px;
}
.arrow-left {
position: absolute;
top: 0px;
width: 300px;
height: 100px;
background-color: green;
-webkit-transform: skew(22deg);
transform: skew(22deg);
border-radius: 0px 0px 30px 40px;
}
h1 {
color: white;
}
<div class="espanolIcon">
<div class="rectangle"><h1>Espanol</h1></div>
<div class="arrow-left"></div>
</div>
Use a zero-dimension :before with thick, partial borders
By adjusting the top/bottom and left/right values of border-width on the :before pseudo-element, you can effectively change the skew of the triangle. The left position can then be changed to properly align the pseudo-element.
a {
display: inline-block;
position: relative;
margin-left: 14px; /* Should counter `left` value of `a:before` */
padding: .5em 1em;
color: #fff;
font: bold 1em/1 sans-serif;
text-decoration: none;
text-transform: uppercase;
border-radius: 0 0 10px 10px;
background: #75bf41;
}
a:before {
content: '\200B'; /* zero-width non-breaking space */
display: block;
position: absolute;
top: 0;
left: -14px; /* Adjust to align */
width: 0;
height: 0;
border-width: 14px 8px; /* Adjust top/bottom and left/right to skew */
border-style: solid;
border-color: #75bf41 #75bf41 transparent transparent; /* Triangle orientation. */
}
Español
Full css could work, but you should use .png as background-image or perhaps you could use .svg as you can animate and/or change every point or pixel. You might be able to use just CSSbut it would take a lot of leveling and positioning and alot of layers of absolute and relative positioning. As Css would only change the full width of the element, and it can only be used to change the width of elements. What you can do is use .svg, you could map every pixel which could be animated.
I accomplished it using borders and pseudo elements.
<ul>
<li class="lang-item lang-item-6 lang-item-es">
::before
<a>Español</a>
</li>
</ul>
ul {
position:relative;
}
.lang-item {
text-align: right;
position: relative;
}
.lang-item a {
background: #76c53f;
padding: 15px;
color: #fff;
text-transform: uppercase;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 14px;
}
.lang-item::before {
position: absolute;
right: 101px;
top: -15px;
content: "";
display: inline-block;
border-top: 40px solid #76C541;
border-left: 40px solid transparent;
}
jsfiddle
I hope someone can help, I can't figure this out. I am creating a wordpress theme using the _s template and I am having trouble with my right column.
If I put just a bunch of line breaks in, the flow is correct. However, as soon as I insert any text, img, or anything else, that data falls below the center column.
I know it is something simple that I am just not seeing.
Here is a link to the page. http://juststin.com/test/help.html
And here is the css
.content-area {
float: left;
}
.site-content {
margin: 0 20%;
width: 60%;
-moz-border-radius: 25px 25px;
border-radius: 25px 25px;
border-width: 5px;
border-style: solid;
border-color: #333333;
background: #ffffff;
}
.pictures {
margin: 0 81%;
width: 20%;
-moz-border-radius: 25px 25px;
border-radius: 25px 25px;
border-width: 2px;
border-style: solid;
border-color: #ffffff;
background: #ffffff;
}
.site-main .widget-area {
float: left;
margin: 0 0 0 -100%;
width: 20%;
background: #2E9AFE;
background: #333333;
}
.site-footer {
clear: both;
width: 100%;
background: #ffffff;
-moz-border-radius: 25px 25px;
border-radius: 25px 25px;
border-width: 5px;
border-style: solid;
border-color: #333333;
}
.site-header {
clear: both;
width: 100%;
background: #ffffff;
-moz-border-radius: 25px 25px;
border-radius: 25px 25px;
border-width: 5px;
border-style: solid;
border-color: #333333;
}
.menu-div {
border-width: 2px;
border-style: solid;
border-color: #ffffff;
background-color: #ffffff;
-moz-border-radius: 25px 25px;
border-radius: 25px 25px;
overflow: visible;
}
#page {
width: 90%;
margin: 0 auto;
}
the problem is your weird column layout. giving margin-left -100% to your .widget-area rather than just rendering it before your #primary column. Your #pictures column isn't floated so its flowing AFTER the #primary container who's width is 100%.
Option 1) put the column where it should go and don't use negative margins.
Option 2) assign a fixed width to #primary (looks like around 60%) and float #pictures left as well
You really need some changes on your column layout markup. I edited your markup and css a little bit to make it work(I won't recommend you to use it.). Take a look at http://pastebin.com/raw.php?i=hqi0MLTc
Off-topic:
Personally I prefer to use fixed width for sidebars/right left columns and fluid width for content area only.
Hope this helps you.
The problem ended up being that I had to decrease the size of the right side bar. I am guessing that adding borders was increasing the sizes to over 100%.
So in both portrait and landscape the right 30% or so of the screen is just white, only on iPhone and maybe other small screens, as if the width were less than 100%.
Here is my HTML:
<div id="loading">
<div id="loading-message">
<p>Please enable Javascript to view this site.</p>
<p class="tar">-Thanks</p>
</div>
<div id="loadingBar">
<div id="loadingBarInner"></div>
</div>
</div>
And relevant CSS:
#loading {
background: gray;
width: 100%;
position: absolute;
height: 1800px;
box-shadow: inset 0px 0px 500px black;
}
#loading-message {
margin: auto;
border-radius: 30px;
padding: 100px;
box-shadow: 0px 0px 50px 10px black;
width: 300px;
margin-top: 200px;
font-size: 30px;
font-weight: bold;
}
#loadingBar {
margin: auto;
width: 350px;
height: 30px;
margin-top: 300px;
border-radius: 5px;
border: 2px solid black;
padding: 2px;
}
#loadingBarInner {
background: #6d0019; /* Old browsers */
height: 30px;
width: 0px;
border-radius: 5px;
}
instead of using fixed padding in #loading-message use padding
with percentage also use max-width and min-width properties instead of
fixed width in #loadingBar and #loading-message. your iphone has about 400px width and you defined 100px
padding and width of 350px. on big screens it's no problem but in your
iphone it will always load with blank space on right side.
#loading {
background: gray;
width: 100%;
position: absolute;
height: 1800px;
box-shadow: inset 0px 0px 500px black;
}
#loading-message {
margin: 0 auto;
border-radius: 30px;
padding: 10%;
max-width:300px;
min-width:50px;
box-shadow: 0px 0px 50px 10px black;
margin-top: 200px;
font-size: 30px;
font-weight: bold;
}
#loadingBar {
margin: auto;
max-width:300px;
min-width:50px;
height: 30px;
margin-top: 300px;
border-radius: 5px;
border: 2px solid black;
}
#loadingBarInner {
background: #6d0019; /* Old browsers */
height: 30px;
width: 0px;
border-radius: 5px;
}
also u can use media queries... media queries
What iPhone do you have?
Try to play with the widths.
I have a parent div #modal_share that contains a floating div modal_big_hline and a unfloated div modal_big_button_container (with clear: both).
modal_big_button_container's CSS is created to allow it to be the width of the parent div minus 25px on its left and right sides.
Problem: Changing the margin-top of modal_big_button_container does not cause it to shift up/down, instead it remains in the same position, although its margin can be seen to be changing using Chrome's developer tools.
Why is this happening, and how can I solve this? Thanks!
CSS
#modal_share {
width: 565px;
height: 400px;
position: relative;
background: whiteSmoke;
padding-top: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 0px 3px 16px #222;
-moz-box-shadow: 0px 3px 16px #222;
box-shadow: 0px 3px 16px #222;
display: none;
}
.modal_big_hline {
width: 100%;
height: 1px;
margin-top: 25px;
border-top: 1px solid #CCC;
float: left;
}
#modal_big_button_container {
height: 14px;
width: auto;
margin: 10px 25px 0px 25px;
clear: both;
}
HTML Structure
<div id="#modal_share">
<div class="modal_big_hline"></div>
<div id="modal_big_button_container"></div>
</div>
JSFiddle: http://jsfiddle.net/5LG2w/
try
modal_big_button_container{
position: relative;
top: 20px;
}
here is the fiddle - http://jsfiddle.net/5LG2w/2/.
or you can take the float out of .modal_big_hline. then your margin-top will work - http://jsfiddle.net/5LG2w/3/.
#modal_big_button_container {
height: 14px;
width: auto;
margin: 10px 25px 0px 25px;
clear: both;
background: red;
}
Looks like margin collapsing. Check these pages:
http://reference.sitepoint.com/css/collapsingmargins
http://www.howtocreate.co.uk/tutorials/css/margincollapsing