How can create css3 button? - css

How can I create a button like the picture by css3 ?
I've tried the following code.
<style type="text/css">
.left,
.right{
float:left;
border-style:solid;
width:0px;
height:0px;
}
.left{
border-color: red green red green;
border-width:15px 0px 15px 75px;
}
.right{
border-color: green green green red;
border-width:15px 20px 15px 35px;
}
</style>
<div>
<div class="left"></div>
<div class="right"></div>
</div>
but got like this output:
Whats the exact way to create curved border of buttons and thin curve between two buttons ?
-Thanks.
EDIT: according to your answers I've made this :
<style type="text/css">
.left,
.middle,
.right{
height:30px;
display:block;
float:left;
text-decoration:none;
position: relative;
text-align:center;
color:black;
}
.left,
.right{
padding:0px 10px;
line-height: 30px;
}
.left{
background-color:red;
width:60px;
border-bottom-left-radius: 17px;
border-top-left-radius: 17px;
}
.middle{
background-color:#ddd;
width:2px;
}
.right{
background-color:green;
width:40px;
border-bottom-right-radius: 17px;
border-top-right-radius: 17px;
}
.middle::before{
content: "";
position: absolute;
top: 5px;
margin-top: -5px;
border-width: 15px;
border-style: solid;
border-color: #ddd transparent #ddd transparent;
left: -15px;
}
.right::before{
content: "";
position: absolute;
top: 5px;
margin-top: -5px;
border-width: 15px;
border-style: solid;
border-color: green transparent green transparent;
left: -15px;
}
.left:hover{
background-color:blue;
}
.right:hover{
background-color:orange;
}
.right:hover::before{
border-color: orange transparent orange transparent;
}
</style>
play
pause
output:
is it ok for standard website ?

Here you go:-
<style type="text/css">
.left,.right,a{
float:left;
border-style:solid;
width:0px;
height:0px;
border-radius: 3px;
}
.left{
border-color: 0A0D6A;
border-width:10px 0px 10px 30px;
}
.right{
border-color: 6568B9 6568B9 6568B9 0A0D6A;
border-width:10px 30px 10px 8px;
margin-left:-3px;
}
</style>
<div>
<div class="left"></div>
<div class="right"></div>
</div>
Creating the white boundary between the blues with pure css is tricky. Same goes for the "speaker" and "play" icons but i'm sure in future, CSS4 will make this one easier for all of us :). In the mean time, simple images will work fine.
EDIT:- Here's 2 ways of getting the "color change on hover" effect you requested:
Method #1, harnessing the css "hover selector" of the parent div
<style type="text/css">
.left,.right,a{
float:left;
border-style:solid;
width:0px;
height:0px;
border-radius: 3px;
}
.left{
border-color:#0A0D6A;
border-width:10px 0px 10px 30px;
}
.right{
border-color:#6568B9 #6568B9 #6568B9 #0A0D6A;
border-width:10px 30px 10px 8px;
margin-left:-3px;
}
#top:hover .left{ border-color:#00FF55;cursor:pointer; }
#top:hover .right{ border-color:#6568B9 #6568B9 #6568B9 #00FF55; }
</style>
<div id=top>
<div class="left"></div>
<div class="right"></div>
</div>
Method #2 harnessing the css "next sibling selector" of the .left classed div
<style type="text/css">
.left,.right,a{
float:left;
border-style:solid;
width:0px;
height:0px;
border-radius: 3px;
}
.left{
border-color:#0A0D6A;
border-width:10px 0px 10px 30px;
}
.right{
border-color:#6568B9 #6568B9 #6568B9 #0A0D6A;
border-width:10px 30px 10px 8px;
margin-left:-3px;
}
.left:hover { border-color:#00FF55;cursor:pointer; }
.left:hover +div{ border-color:#6568B9 #6568B9 #6568B9 #00FF55; }
</style>
<div>
<div class="left"></div>
<div class="right"></div>
</div>
Check whether they both work on iexplore < 9

Actually the best solution to this is that.......... the button is three images... if you want to use the two parts of buttons separately.
1st - The left side button
2nd - The junction where you see the transition
3rd - The right side part.
You can also use color and image.
1st - The left side button color
2nd - The junction where you see the transition image
3rd - The right side button color.
This is the way most of the webpages do..

Related

Divide one CSS column in 2 rows

http://jsfiddle.net/9877/6E2pQ/2/
What I want do is have columncontent1 on the left and columncontent2 and columncontent3 stacked on the right side. see the jsfiddle. How do I fix the css? I am running out of ideas. Is the error in the css or the way the div placed in the body:
<style type="text/css">
/*<![CDATA[*/
.columncontainer1{
width:1001px;
position:relative;
border:0px;
background-color:#fffffa;
overflow:hidden;
}
.columncontainer2{
float:left;
position:relative;
right:300px;
border-right:1px solid #0a0a0a;
background-color:#f5f5f5;
}
.columncontainer3{
float:left;
position:relative;
bottom: 10px
border-right:1px solid #0a0a0a;
background-color:#f5f5f5;
}
.columncontent1{
float:left;
width:680px;
position:relative;
background-color:#933;
border: 1px;
left:300px;
padding:10px;
overflow:hidden;
}
.columncontent2{
float:left;
width:280px;
position:relative;
background-color:#FFF;
border: 2px;
left:301px;
padding:10px;
overflow:hidden;
}
.columncontent3{
float:left;
width:280px;
position:relative;
left:301px;
border: 4px;
background-color:#CC6;
padding:10px;
overflow:hidden;
}
/*]]>*/
</style>
There's a lot going on there, I've simplified the HTML and CSS:
CSS:
.leftCol {
float: left;
width: 50%;
background-color: #ccc;
height: 60px;
}
.rightColContainer {
float: left;
width: 50%;
}
.rightCol1 {
background-color: #333;
height: 30px;
}
.rightCol2 {
background-color: #777;
height: 30px;
}
HTML:
<body>
<div class="leftCol">columncontent1</div>
<div class="rightColContainer">
<div class="rightCol1">columncontent2</div>
<div class="rightCol2">columncontent3</div>
</div>
</body>
You only need to 'contain' the right hand column to stop the 'stacked column' flowing incorrectly.
CSS3 actually allows you to make several columns automatically without having to have all those classes. Check out this generator: http://www.generatecss.com/css3/multi-column/
This is however only if you are trying to make your content have multiple columns like a newspaper.

Div tag, aligning in straight line

I have 3 div tags. I have to place it in straight line. in my code it is 2,3,4. 2 and 3 are in straight line but 4 comes downward dono why. I am beginner to html and css. accurately my project is to make a room in perspective view in html. and draw the contents using html canvas.But struck in beginning itself. Experts please help me a way out. I attache my whole project in Jsfiddle and scenario i need solution is written below.
http://jsfiddle.net/kGpdM/855/
Html:
<div id="wall">
<div id="sidewall1" align="left">2</div>
<div id="center" align="center">3</div>
<div id="sidewall2" align="right">4</div>
</div>
css:
#sidewall1 {
float:left;
width:250px;
height:500px;
}
#sidewall2 {
float:right;
width:250px;
height:500px;
}
You didn't mentioned the property of ID 'center' so that div itself took a default width.
Div 4 comes down because total width (width of id 'row' here 1000px) - width of div 3 = less than 250 px.
Also if you are styling through css then try to avoid inline styling use css only.
Here is the modified code.
HTML
<div id="container">
<div id="roof">1</div>
<div id="wall">
<div id="sidewall1">2</div>
<div id="center" >3</div>
<div id="sidewall2">4</div>
</div>
<div id="floor">5</div>
</div>
CSS
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#roof {
padding: 0px;
height: 250px;
width: 1000px;
margin-right: 0px;
margin-left: 0px;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
}
#wall {
padding: 0px;
height: 500px;
width: 1000px;
margin-right: 0px;
margin-left: 0px;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
}
#floor {
padding: 0px;
height: 250px;
width: 1000px;
margin-right: 0px;
margin-left: 0px;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
}
#sidewall1 {
float:left;
width:250px;
height:500px;
}
#sidewall2 {
float:left;
width:250px;
height: 500px;
}
#center {
float:left;
width:250px;
height: 500px;
}
The style attribute display:inline; adding to all class or iid's u have for the divs 2,3,4 will do.
The width of a computer screen only takes so many pixels. It gets complicated by the fact that there are many different screen widths. For example, you have mobile phones, tablets, laptops, and desktops. But even those can have different widths. So instead of using width: 250px; , it is better to make all those divs in percentages. See below.
#sidewall1 {
float:left;
width:25%;
height:500px;
}
#center {
float: left;
width: 49%;
}
#sidewall2 {
float:left; // Change this to float left
width:25%;
height:500px;
}
adjust the percentages according to how you want it.
Changing the divs to inline may mess up other style. Instead, you should change your CSS, so that the center div is included last. I have added background colors to your CSS to demonstrate:
jsFiddle
HTML
<div id="wall">
<div id="sidewall1">2</div>
<div id="sidewall2">4</div>
<div id="center">3</div>
</div>
CSS
#sidewall1 {
float:left;
width:250px;
height:500px;
background-color: yellow;
}
#center {
display: block;
background-color: green;
}
#sidewall2 {
float:right;
width:250px;
height:500px;
background-color: red;
}

CSS relative absolute position

I just have a container div-element that contains two div-elements that should appear at the same level on both sides of the container-div. The following solution does not work:
<div id="result" >
<div class="right">Update</div>
<div class="left">delete</div>
</div>
stylesheet follows:
div.left{
position:absolute;
left: 5px;
top:0px;
color: green;
border-style:solid;
border-color: green;
}
div.right{
position:absolute;
right: 2px;
top:0px;
color: red;
border-style:solid;
border-color: red;
}
#result{
position:relative;
width:100%;
border-style:solid;
border-color: blue;
}
The blue margin from the container-div does not contains the the other two divs and appears on top of the other two containers.
What am I missing? Thanks!
Ideally the .left and .right divs would be floated:
div.left{
float: left;
margin: 5px;
color: green;
border-style:solid;
border-color: green;
}
div.right{
float: right;
margin: 5px;
color: red;
border-style:solid;
border-color: red;
}
you have put position which is not needed basically.
see below answer
html here
<div id="result" >
<div class="right">Update</div>
<div class="left">delete</div>
</div>
css here
div.left{
left: 5px;
top:0px;
color: green;
border-style:solid;
border-color: green;
float:left;
}
div.right{
right: 2px;
top:0px;
color: red;
border-style:solid;
border-color: red;
float:right;
}
#result{
width:100%;
border-style:solid;
border-color: blue;
float:left;
}
live example here.
http://codepen.io/anon/pen/waKrH
please mark as answer if this helped you.
What you could try is float:left to both of the elements your trying to put side by side, that should push-force them, see if it works and let me know.
Are you trying to achieve this fiddle?
Better way is to change the apsolute into relative,with floating.
And if you use floating, dont forget to add overflow:hidden; to the parent container.

CSS horizontal centered line

How can I achieve this view with CSS:
------------------TITLE
or
TITLE------------------
I have
<div id="titleBlock">
<div id="title">Some text</div>
<div id="titleLine"></div>
</div>
And my styles are:
#titleLine {
border-top: 1px solid black;
width: 84%;
clear: both;
height: 20px;
}
#title {
height: 10px;
float: right;
}
My approach is here: jsFiddle
However the line width is defined with percents and I need it adjust automatically with CSS.
This may be what you are after: http://jsfiddle.net/XpSWX/1/
Hope this helps
<div id="titleBlock">
<div id="title">Some text</div>
<div id="titleLine"></div>
</div>​
#titleLine {
border-top: 1px solid black;
width: 84%;
float:left;
height: 20px;
margin-top:8px;
}
#title {
height: 10px;
float: right;
}​
http://jsfiddle.net/sY2SV/1
<div id="titleBlock">
<div id="title">Some text</div>
<div id="titleLine"></div>
</div>​
#titleLine {
border-top: 1px solid black;
width: 84%;
float:right;
height: 20px;
margin-top:8px;
}
#title {
height: 10px;
float: left;
}​
http://jsfiddle.net/sY2SV/2
Here is a solution:
#titleBlock {
width:100%;
}
#titleLine {
background:black;
position:absolute;
z-index:1;
left:0px;
top:14px;
width:100%;
height: 1px;
}
#title {
display:inline-block;
padding:4px;
background:white;
position:relative;
z-index:2;
/* Only variable to change... Just say left and it woulb be title------- */
float:right;
}​​​​
DEMO
Hey now you can used this
HTML
<div class="hello"><span>Hello i m sony</span></div>
Css
.hello{
background:green;
text-align:left;
position:relative;
}
.hello span{
padding-right:10px;
background:green;
display:inline-block;
position:relative;
z-index:1
}
.hello:after{
content:'';
border-top:solid 5px red;
position:absolute;
right:0;
left:0;
top:7px
}
Live demo
http://tinkerbin.com/1guJzKcI
Check my answer in Horizontal Line in Background using Css3
You can do it with a 1% gradient like this
.datedAside {
background: linear-gradient(0deg, transparent 49%, #000 50%, transparent 51%);
}
.datedAside span{
background: #FFF;
padding: 0 0.5rem;
}
You'll nedd the extra span to be the same background color as the background of the component to make it look like it has "deleted" the line going behind the text.
For text, it's best to use text-align

CSS two column full width

So I have a website which has a header, a footer and two main content columns inbetween.
The left column is for navigation. The right one is a map. I want both to fill the width of the browser. I seem to be facing problems with different resolutions and different browsers. The map always displaces to below the footer or it leaves a white space on the right.
My link: http://www.trashvigil.com/nsdf/www/index1.php
This is my code:
#map{
float:left;
height:572px;
width:79.88%;
border-right: 2px solid #000;
border-bottom: 3px solid #000;
}
#leftnav
{
float:left;
width:250px;
height: 572px;
border-right: 3px solid #000;
border-bottom: 3px solid #000;
}
#map is the map container. #Leftnav is navigation.
Thank you,
Kaushik
You need something like this:
#map {
margin-left:250px;
height:572px;
}
#leftnav {
float:left;
width:250px;
height: 572px;
}
The idea is to float the leftnav and then set a left margin for the map that is equal to the width of the leftnav.
You can see it live here: http://dabblet.com/gist/2767788
#nav {
position:absolute;
left:0px; width:250px;
height:375px; top:50px; /* height of your top bar*/
}
#map{
margin-left:250px;
height:572px;
}
Something like this should be what you need.
<style>
#main
{
width: 900px;
overflow: hidden;
}
#leftnav
{
float: left;
}
#map
{
float: right;
}
</style>
<div id="header">
</div>
<div id="main">
<div id="leftnav">
</div>
<div id="map">
</div>
</div>
<div id="footer">
</div>
Write like this:
#map{
overflow:hidden;
height:572px;
border-right: 2px solid #000;
border-bottom: 3px solid #000;
}
#leftnav{
float:left;
width:250px;
height: 572px;
border-right: 3px solid #000;
border-bottom: 3px solid #000;
}

Resources