Icons separation and horizontal line behind - css

I search any problem but without results. Have big problem with separation of icons in inline-block after add css spearation ::after and ::before in the middle icon and with rwd of it.here's my code.
HTML:
<div class="icon-box">
<div class="icon_1"></div>
<div class="icon_2"></div>
<div class="icon_3"></div>
</div>
CSS:
.icon_1 {
float: left;
display: inline-block;
height: 66px;
width: 66px;
background-image: url("../img/timing_icon.png");
background-color: #97735e;
background-position: center;
background-repeat: no-repeat;
}
.icon_2 {
float: left;
display: inline-block;
height: 66px;
width: 66px;
background-image: url("../img/presentation_icon.png");
background-color: #97735e;
background-position: center;
background-repeat: no-repeat;
}
.icon_3 {
float: left;
display: inline-block;
height: 66px;
width: 66px;
background-image: url("../img/accurate_icon.png");
background-color: #97735e;
background-position: center;
background-repeat: no-repeat;
}
.icon_2::before,
.icon_2::after {
display: inline-block;
content: "";
height: 10px;
border-bottom: 1px solid #97735e;
width: 100%;
}
.icon_2::before {
right: 100%;
margin-right: 10%;
}
.icon_2::after {
left: 100%;
margin-left: 200%;
}
I think my code is very messy and got to fix.
effect,what I want get enter image description here

first. you have common styles for all the .icon_1,.icon_2,.icon_3 divs except the background-image . so, give a common class icon for example, to all those divs, or, if you can't change the HTML , use .icon_1,.icon_2,.icon_3 instead of .icon in my example below. but don't write the same styles 3 times.
second. either use display:inline-block either use float:left . i chose to use float:left; because inline-block adds additional whitespaces between elements. ( if you want to use inline-block let me know . there are ways to override the whitespaces . )
third. add margin:0 15px to .icon_2 which adds margin-left and margin-right of 15px
fourth. add the pseudo-element ( :before in my example ) to the div that wraps the three icons ,respectively .icon-box . and style it as you want.
i added z-index:-1 so that the line ( :before ) goes under the icons.
added background:red to it so you can see that it goes under the icons.
.icon {
float:left;
height: 66px;
width: 66px;
background-color: #97735e;
background-position: center;
background-repeat: no-repeat;
position:relative;
}
.icon_1 {
background-image: url("../img/timing_icon.png");
}
.icon_2 {
background-image: url("../img/presentation_icon.png");
margin:0 15px;
}
.icon_3 {
background-image: url("../img/accurate_icon.png");
}
.icon-box { position:relative;width:auto;float:left;}
.icon-box:before {
content:"";
position:absolute;
height:1px;
background:red;
top:50%;
width:100%;
left:0;
z-index:-1;
}
<div class="icon-box">
<div class="icon icon_1"></div>
<div class="icon icon_2"></div>
<div class="icon icon_3"></div>
</div>

Related

Rectangle with 1 circle side

.addcircle{
width:15%;
height:30px;
position:relative;
}
.addcircle:hover{
background: #1a1aff;
color:white;
}
.addcircle:hover a{
background: #1a1aff;
color:white;
}
.addcircle:after{
position: absolute;
z-index: 1;
left: 80%;
/* top: 0%; */
width: 30px;
height: 30px;
margin-top: 0px;
border-radius: 50%;
content: "";
}
.addcircle:hover:after{background: #1a1aff;}
<div id="main">
HOOVER LINK BELOW
<div class="addcircle">
some page
</div>
<div class="addcircle" style="width:20%">
some page 2
</div>
</div>
How to do same effect like main(1st link) for responsive width??
As you can see on example, 1st hover look nice but 2nd one not rly... any clue?
Because when i check for bigger or smaller screen my circle move some where.
Not gonna do all the work for you but it looks like you're over thinking it. You're already messing with border-radius which is the key:
a {
color: white;
padding: 5px;
border-radius: 0 1rem 1rem 0 ;
background-color: blue;
}
Some Page
<br/>
<br/>
Some Page 2
Depending on the needs of your application (will all lines fit on one line on all expected viewports?), applying this style on hover could be all you need.
As you can see below, I've used right property on .addcircle:after instead of left and used a fixed value of negative half of the width which is -15px this will lead to a semi-circle effect and the right side of your links, without regarding width of the element.
.addcircle{
width:15%;
height:30px;
position:relative;
}
.addcircle:hover{
background: #1a1aff;
color:white;
}
.addcircle:hover a{
background: #1a1aff;
color:white;
}
.addcircle:after{
position: absolute;
z-index: -1;
right: -15px;
width: 30px;
height: 30px;
margin-top: 0px;
border-radius: 50%;
content: "";
}
.addcircle:hover:after{
background: #1a1aff;
}
<div id="main">
HOOVER LINK BELOW
<div class="addcircle">
some page
</div>
<div class="addcircle" style="width:20%">
some page 2
</div>
</div>
However, there's no need to use a <div class="addcircle"> around your links. It's possible to implement exact same effect with only <a> elements.
a{
width:20%;
display: block;
height: 30px;
position:relative;
}
a:hover{
background: #1a1aff;
color:white;
}
a:after{
position: absolute;
z-index: -1;
right: -15px;
width: 30px;
height: 30px;
margin-top: 0px;
border-radius: 50%;
content: "";
}
a:hover:after{
background: #1a1aff;
}
<div id="main">
<span>HOOVER LINK BELOW</span>
some page
<a style="width: 50%" href="">some page 2</a>
</div>
Just add the display property to your .addcircle div:
.addcircle{
width:15%;
height:30px;
position:relative;
display: flex;
}
and for .addcircle:after change right position instead of left:
.addcircle:after{
position: absolute;
z-index: 1;
right: -12px;
width: 30px;
height: 30px;
margin-top: 0px;
border-radius: 50%;
content: "";
}

Vertically centering <div>s with multiple lines

I know it's been asked a few times, but upon playing around a bit I still couldn't center what I need to. What I'm looking to do it center those buttons vertically on the page. I want to put centered text above it, too.
My (sloppy) code: JsFiddle
HTML:
<div>
</div>
CSS:
div {
text-align: center;
}
a {
text-align: center;
margin: auto;
}
.cbtn {
display:inline-block;
width:60px;
height:60px;
border-radius:50px;
background:transparent;
border: solid gray 1px;
margin: 2px;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
transition:.5s;
}
.cbtn:hover {
text-decoration:none;
background:#F3734F;
}
#mail {
background-image:url(http://data.novicode.com/data/img/mail.png);
background-position:50% 50%;
background-repeat:no-repeat;
}
Here is one way of doing it, assuming you want the buttons centered both horizontally and vertically on the page.
The HTML is:
<div class="wrap">
<div class="button-wrap">
</div>
</div>
and the CSS is:
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.wrap {
height: 100%;
width: 100%;
}
.button-wrap {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
height: 60px;
width: 350px;
margin: auto;
text-align: center;
}
You need to declare the width and height properties of the body and html elements to be 100%, and the same for div.wrap.
The trick is to wrap the links/buttons in div.button-wrap, which is absolutely positioned and given specific width and height values to match the buttons. The height of 60px is based on the height of the .cbtn, and the width of 350px is 5 times (60px + 2x2px + 2x1px + 4x1em) which is about 350px. However, since we can use text-align: center for centering the inline blocks, the exact width is not too critical, just make it wide enough.
The centering works by setting all the position values to 0 (left/right/top/bottom) and then setting margin: auto.
This is all based on CSS 2.1 so it should work in most browsers. The only limitation is the inline-block property, which IE7 does not recognize.
However, since you are using CSS2 animations, inline-block is probably okay.
Fiddle reference: http://jsfiddle.net/audetwebdesign/METYC/
Full page view: http://jsfiddle.net/audetwebdesign/METYC/show
check this :
http://jsfiddle.net/AT8S6/
you can change the width,height and margin property of section for different results .
HTML
<div>
<section>
</section>
</div>
CSS
div {
text-align: center;
height:400px;
width:100%;
border:2px #000 solid;
}
a {
text-align: center;
margin: auto;
}
div section {
width:65%;
height:50%;
margin:20% auto;
}
.cbtn {
display:block;
width:60px;
height:60px;
border-radius:50px;
background:transparent;
border: solid gray 1px;
margin: 2px;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
transition:.5s;
float:left;
}
.cbtn:hover {
text-decoration:none;
background:#F3734F;
}
#mail {
background-image:url(http://data.novicode.com/data/img/mail.png);
background-position:50% 50%;
background-repeat:no-repeat;
}
You could set the following rules on the div:
div {
position: absolute;
left: 50%;
height: 50%;
margin-top: -(height of div);
margin-left: -(width of div);
}
Example link below:
http://jsfiddle.net/AT8S6/1/

CSS Sprite: Setting sprite image for several categories

I am currently working with css sprite images for my site. But I am running into css styling issues. I have 6 categories with each having an image beside. When applying the image sprite I get repeated images of the same object.
How can I get each category with their respective image through css & sprite? If you like to look at the live examples below are the links.(ps sorry for the horrible html structure)
Thank you
How it looks:
Sprite Images: Click Here
Individual Images: Click Here
Desired Outcome:
CSS part related
<style>
#index_categories {
background: #fff;
float: left;
width: 255px;
height: 125px;
margin: 10px 15px 10px 40px;
padding: 5px;
font-size: 97%;
vertical-align: middle;
background: url( http://webprolearner2346.zxq.net/css-test/images/categories.png) no-repeat top left;
}
.index_thumb {
padding: 5px;
}
.index_categories_list {
text-indent: 5px;
padding-left: 10px;
}
.index_cat {
list-style-type: none;
}
#listing {
background: #fff;
width: 95%;
height: 115px;
padding: 10px;
margin-bottom: 10px;
margin-right: 5px;
margin-left: 5px;
margin-top: 5px;
}
.listing_pic {
float: left;
padding: 10px;
}
#whitebox {
background: #fff;
width: 95%;
min-height: 200px;
padding: 10px;
margin-bottom: 10px;
margin-right: 5px;
margin-left: 5px;
margin-top: 5px;
}
.sprite-books{ background-position: 0 0; width: 87px; height: 87px; }
.sprite-tshirt{ background-position: 0 -137px; width: 87px; height: 87px; }
.sprite-stereo{ background-position: 0 -274px; width: 83px; height: 83px; }
.sprite-chair{ background-position: 0 -407px; width: 87px; height: 87px; }
.sprite-key{ background-position: 0 -544px; width: 83px; height: 83px; }
.sprite-cake{ background-position: 0 -677px; width: 87px; height: 87px; }
</style>
HTML snippet
<div class="contentPost" style="height:900px;">
<div id="index_categories" class="sprite-books">
<h3><a class="frontLinks" href="#">Category 1</a></h3>
<ul class="index_cat">
<li>Books</li>
</ul>
</div>
<div id="index_categories " class="sprite-stereo">
<h3><a class="frontLinks" href="#">Category 2</a></h3>
<ul class="index_cat">
<li>Stereo</li>
</ul>
</div>
<div id="index_categories" class="sprite-chair">
<h3><a class="frontLinks" href="#">Category 3</a></h3>
<ul class="index_cat">
<li>Chair</li>
</ul>
</div>
</div>
CSS Sprite (Google) is a big image (most probably .png) consisting out all of your required images(6 in yoyr case), in a grid-like structure. Benefit is that you will need only One HTTP request instead of NHTTP requests (where n is your number of images).
Your problem looks like the CSS Styling. But if you want to use sprites, you need one master image (sprite.png) having transparent background and having width of x*n (where X= width of your one div/category, as you shown in Desired Outcome in your question. N= number of total images, 6 here.) The height of sprite.png should be equal to the tallest of your images.
So, copy all your images stero.png, books.png into a new sprite.png as described above.
Then you could use following HTML:
<div id="wrapper">
<div class="row">
<div id="books" class="cell">
</div><!--//books-->
<div id="stereo" class="cell">
</div><!--//stereo-->
<div id="pen" class="cell">
</div><!--//pen-->
</div><!--//row-->
<div class="row">
<div id="mag" class="cell">
</div><!--//mag-->
<div id="bag" class="cell">
</div><!--//bag-->
<div id="paper" class="cell">
</div><!--//paper-->
</div><!--//row-->
</div><!--//wrapper-->
CSS:
#wrapper{
margin: 5px auto; // to center the div on page
width: 80%;
}
.row{ //stack'em in 3x2 grid
clear:both;
}
.cell{
background-color: #fefefe;
background-url: images/sprite.png; //Set common background UR
float: left; //stack each other to left
height: 15px; //desired height
width: 30px; //desired width
border: 3px solid #c3c3c3; //set border
}
//set specific background-position for each div
//(Remember we are using same image for all these divs?
#books{ background-position: -0px -0px; } //image starts at top:0, left:0px
#stereo{ background-position: -0px -30px; } //image starts at top:0, left:30px
#pen{ background-position: -0px -60px; } //image starts at top:0, left:60px
#mag{ background-position: -0px -90px; }
#bag{ background-position: -0px -120px; }
#paper{ background-position: -0px -150px; }
You could also use your existing 6 images to achieve your desired result. Just set a required height,width of the div. Set background-position:top-left;. If the image is smaller that the div's dimensions, the image will be placed in top-left corner.
EDIT:
Ok, saw your live-page's code. You already are using a sprite file.
From seeing your How It looks & Desired pages, looks like you want to add that extra white-space around the right-bottom side of image. Right?? If yes, you could add the required white-space in the categories.png and use background-position:top-left; in CSS. It will prevent the image to repeat in the horizontal side.

my outer div background extends when using negative margins in the child div

Here is my stylesheet code
#topwrapper {
background: url(images/orangebg.jpg) repeat-x top;
height: 502px;
}
#mainwrapper {
background:url(images/bluebg.jpg) repeat;
}
#maincontent {
margin: 0 auto;
width: 961px;
background-color:#F0EFEF;
position: relative;
margin-top: -312px;
}
I want the maincontent div to move up into the orange div but it is bringing the bluebg.jpg with it (cutting short the orangebg.jpg). When I tried using -top: 312px; instead of the negative margin it added space below the #maincontent.
The code on the page reads
<div id="topwrapper"></div>
<div id="mainwrapper"><div id="maincontent">test test</div></div>
View on jsfiddle
jsfiddle.net/bdh2a - remove the margin-top: -312px; and that is how I need the orange background to look with the grey box on top of it
maybe you can set margin-top: -312px; to mainwrapper div?
Re-arrange your html like this:
<div id="mainwrapper">
<div id="maincontent"><p>text text</p></div>
<div id="topwrapper"></div>
</div>
Then use this CSS setup (adjusting the heights and stuff of course):
#mainwrapper{
height:100%;
background-color:#FF4200;
width:100%;
}
#topwrapper {
background-color:#1B00FF;
height:100px;
min-width:100%;
margin:0 auto;
position:absolute;
top:0;
z-index:0;
}
#maincontent {
margin: 0 auto;
padding:20px;
top:20px;
background-color:#ccc;
position: relative;
color:#000;
z-index:1;
width:80%
}
Check out this jsfiddle:http://jsfiddle.net/imakeitpretty/yqnfk/
There is a lot of greek text in there because you can't see the orange expand without it. "text text" isn't enough to do it.
I Found a solution!!
#topwrapper {
background: url(images/orangebg.jpg) repeat-x top;
height: 502px;
}
#mainwrapper {
background:url(images/bluebg.jpg) repeat;
float: left;
width: 100%;
display: block;
position: relative;
}
#maincontent {
width: 961px;
background-color:#F0EFEF;
position: relative;
margin-top: -312px;
margin-left: -480px;
position: relative;
float: left;
left: 50%;
}
The code on the page stays the same

Centering two divs in a div: one of fixed width and the other of variable width/height

I have a situation where I have one div of fixed width, containing an image pulled from Twitter, and another div of variable width containing user text of variable length. What I want to achieve is something like the following:
I can do this well enough with a single div that has background-image and padding-left. But I want to be able to apply border-radius to the img element, which simply won't be possible with a background-image.
If I do text-align: center on the outer div, it gets me halfway there. Here's a DEMO and a screenshot:
But this obviously isn't fully what I want.
How can I accomplish this?
Ask and you shall receive — a simplified jsFiddle example:
As an added bonus, the text is vertically centered too!
HTML:
<div class="logo">
<div class="logo-container">
<img src="http://img.tweetimag.es/i/appsumo_b.png" />
</div>
<div class="logo-name">
AppSumo is a really really long title that continues down the page
</div>
</div>
CSS:
.logo {
background-color: #eee;
display: table-cell;
height: 100px;
position: relative;
text-align: center;
vertical-align: middle;
width: 600px;
}
.logo-container {
background-color: #fff;
border-radius: 10px;
left: 10px;
position: absolute;
top: 10px;
width: 75px;
}
.logo-name {
font: bold 28px/115% Helvetica, Arial, sans-serif;
padding-left: 85px;
}
Would it be something like this?
http://jsfiddle.net/uPPTM/6/
.logo {
width:80%;
margin:auto;
background-color: red;
}
.logo-container {
border: 1px solid gold;
width:73px;
height: 73px;
display: inline-block;
vertical-align:middle;
}
.logo-name {
display: inline-block;
}
You can float the image container (or image itself without the container) to the left, clearing anything the left... and then float the text to the left, clearing anything to the right.
.logo-container{
float:left;
clear:left;
}
.logo-name{
float:left;
clear:right;
}
You can adjust the distance of the text using margins.
.logo-name{
float:left;
clear:right;
margin-top:10px;
margin-left:5px;
}
Use absolute positioning with a left position to push the title text past the image.
http://jsfiddle.net/uPPTM/9/
.logo { width: 50px; }
.title {
position: absolute;
top: 0;
left: 50px;
font-size: 32px;
text-align: center;
}
img {
border: 1px solid gray;
border-radius: 15px;
}
<div class="logo">
<div class="logo-container">
<img src="http://img.tweetimag.es/i/appsumo_b.png">
</div>
<div class="logo-name">AppSumo</div>
</div>

Resources