I want to make a minimal landing page, where a whole screen is divided into 2 with text links to click through to each part of the site.
I figured out this much:
https://jsfiddle.net/m2ne5f3b/
I used 2 halves to create the divide, using a border on one side to create the line in the middle. It's super rudimentary.
.left-half {
position: absolute;
left: 0px;
width: 50%;
border-style: solid;
border-width: 1px;
border-left: none;
border-top: none;
border-bottom: none;
}
.right-half {
position: absolute;
right: 0px;
width: 50%;
}
Now what I want to do is make the whole of each half clickable, instead of the text only. Tried a couple different options to no avail. Any suggestions?
Just make the <a> the block! There is absolutely no need to use JS for this.
<a href="http://www.google.com" class="left-half">
<article>
<p>Google</p>
</article>
</a>
Then just style your <a> as a block because you are setting the height in your .left-half class, <a> elements are inline by default, so to make the height work, you need to make it a block:
.container a {
display: block;
// add any other CSS you want to apply
}
Working Snippet: Your Google looks exactly like the Youtube one in this, excelt that the whole block is now the link:
* {
box-sizing: border-box;
}
body {
font-size: 18px;
font-family: 'Cormorant Garamond', serif;
font-style: italic;
line-height: 150%;
text-decoration: none;
}
a.left-half {
height: 100%;
display: block;
}
section {
color: #000;
text-align: center;
}
div {
height: 100%;
}
article {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
padding: 20px;
}
.container {
display: table;
width: 100%;
}
.left-half {
position: absolute;
left: 0px;
width: 50%;
border-style: solid;
border-width: 1px;
border-left: none;
border-top: none;
border-bottom: none;
}
.right-half {
position: absolute;
right: 0px;
width: 50%;
}
a {
color: inherit;
text-decoration: none;
}
<section class="container">
<a href="http://www.google.com" class="left-half">
<article>
<p>Google</p>
</article>
</a>
<div class="right-half">
<article>
<p>YouTube</p>
</article>
</div>
</section>
If you do not wish to mofify your HTML structure, then you can use a pseudo to fill the entire area to be responding as the link.https://jsfiddle.net/m2ne5f3b/7/
* {
box-sizing: border-box;
}
body {
font-size: 18px;
font-family: 'Cormorant Garamond', serif;
font-style:italic;
line-height: 150%;
text-decoration: none;
}
section {
color: #000;
text-align: center;
}
div {
height: 100%;
}
article {
display:table-cell;
text-align:center;
vertical-align:middle;
}
.container {
}
.left-half {
position: absolute;
display:table;
top:0;
left: 0px;
width: 50%;
border-style: solid;
border-width: 1px;
border-left: none;
border-top: none;
border-bottom: none;
}
.right-half {
position: absolute;
top:0;
right: 0px;
width: 50%;
display:table;
}
a { color: inherit;
text-decoration: none;}
a:before {
content:'';
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
}
<section class="container">
<div class="left-half">
<article>
<p>Google</p>
</article>
</div>
<div class="right-half">
<article>
<p>YouTube</p>
</article>
</div>
</section>
Note: if the page is meant to be 2 links side by side with little styling, then the html can be reduced to 2 links
html {
height: 100%;/* necessary for the table-layout box model demo */
width: 100%;/* necessary for the table-layout box model demo */
display: table;/* necessary for the table-layout box model demo */
table-layout: fixed;/* necessary for the table-layout box model demo */
border-collapse: collapse;
background: tomato;
}
body {
display: table-row;/* necessary for the table-layout box model demo */
}
a {
display: table-cell;/* necessary for the table-layout box model demo */
text-align: center;/* necessary for the table-layout box model demo */
vertical-align: middle;/* necessary for the table-layout box model demo */
box-shadow: 0 0 0 1px;
text-decoration: none;
color: black;
font-size: 40px
}
a:nth-child(odd) {
background: rgba(255, 114, 25, 0.5);
}
Google
YouTube
your common a tags arent going to cut it here. Your best bet is to use Javascript or jquery function calls on the divs.
<div class='left-half' onclick="fakeLink()" >
<!-- some stuff here in the div -->
</div>
then in the script file
function fakeLink() {
window.location = "http://www.yoururl.com/link";
}
* {
box-sizing: border-box;
}
body {
font-size: 18px;
font-family: 'Cormorant Garamond', serif;
font-style:italic;
line-height: 150%;
text-decoration: none;
}
section {
color: #000;
text-align: center;
}
div {
height: 100%;
}
article {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
padding: 20px;
}
.container {
display: table;
width: 100%;
}
.left-half {
position: absolute;
left: 0px;
width: 50%;
border-style: solid;
border-width: 1px;
border-left: none;
border-top: none;
border-bottom: none;
}
.right-half {
position: absolute;
right: 0px;
width: 50%;
}
a { color: inherit;
text-decoration: none;}
<section class="container">
<a href="http://www.google.com">
<div class="left-half">
<article>
<p>Google</p>
</article>
</div>
</a>
<a href="http://www.youtube.com">
<div class="right-half">
<article>
<p>YouTube</p>
</article>
</div>
</a>
</section>
Related
How can I add a circle on top of two vertical div in HTML? I succeed in having 2 vertical boxes:
but I cannot figure out how to have a circle in the middle like the following:
The goal is to have a white circle with a blue line and being able to add a logo in the circle. I have the following code snippet:
http://jsfiddle.net/wL9xoad3/
.html {
height: 100%;
}
*,
*:before,
*:after {
box-sizing: border-box;
}
.body {
background-color: #000;
font-family: "Open Sans", sans-serif;
height: 100%;
}
.vidyard_padding {
height: 100%;
}
.vc {
display: table;
height: 100%;
width: 100%;
}
.vc-inner {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.cta {
background-color: #fff;
height: 360px;
margin: 0 auto;
overflow: hidden;
position: relative;
width: 640px;
}
.cta-full {
height: 100%;
width: 100%;
}
.cta-half {
float: left;
height: 100%;
width: 50%;
}
.cta-block {
display: table;
height: 100%;
width: 100%;
}
.cta-block-inner {
display: table-cell;
padding: 20px;
text-align: center;
vertical-align: middle;
}
.cta-block p {
line-height: 1.4125;
margin: 0;
}
.cta-block p.white {
color: #FFFFFF;
}
.cta-block p+.btn {
margin-top: 10px;
}
.cta-block .btn {
background-color: #414142;
border-radius: 2px;
color: #FFFFFF;
display: inline-block;
font-size: 10px;
letter-spacing: 1px;
padding: 8px 12px;
text-decoration: none;
}
.cta-block .btn:hover {
background-color: #313132;
}
<div class="cta-half">
<div class="cta-block" style="background-color:#FFFFFF;">
<div class="cta-block-inner">
<p class="black">Watch our Quick Start</p>
<a class="btn" href="https://google.com">Quick Start</a> </div>
</div>
</div>
<div class="cta-half">
<div class="cta-block" style="background-color:#47b2ffff;">
<div class="cta-block-inner">
<p class="white">Start in the Cloud</p>
<a class="btn" href="https://google.com">Cloud</a> </div>
</div>
</div>
You can use a ::before or an ::after pseudo element with an empty content and some positioning. You can set the width and height of the new element and add some border-radius to make it a circle. Don't forget to set position: relative on the .cta-half element so you can move the circle relative to this.
You can add the following to your snippet on jsfiddle, it should work:
.cta-half {
position: relative;
}
.cta-half:last-of-type::after {
background-color: #fff;
border-radius: 50%;
border: 2px solid #47b2ff;
content: '';
height: 50px;
left: 0;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
width: 50px;
}
If you want to add a logo in the circle, you can update your content and add a url(). I'd probably grab the svg version of the logo and encode it using this tool. It will convert the image and use it like this:
content: url("data:image/svg+xml,%0A%3Csvg viewBox='0 0 533.5 544.3' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M533.5 278.4c0-18.5-1.5-37.1-4.7-55.3H272.1v104.8h147c-6.1 33.8-25.7 63.7-54.4 82.7v68h87.7c51.5-47.4 81.1-117.4 81.1-200.2z' fill='%234285f4'/%3E%3Cpath d='M272.1 544.3c73.4 0 135.3-24.1 180.4-65.7l-87.7-68c-24.4 16.6-55.9 26-92.6 26-71 0-131.2-47.9-152.8-112.3H28.9v70.1c46.2 91.9 140.3 149.9 243.2 149.9z' fill='%2334a853'/%3E%3Cpath d='M119.3 324.3c-11.4-33.8-11.4-70.4 0-104.2V150H28.9c-38.6 76.9-38.6 167.5 0 244.4l90.4-70.1z' fill='%23fbbc04'/%3E%3Cpath d='M272.1 107.7c38.8-.6 76.3 14 104.4 40.8l77.7-77.7C405 24.6 339.7-.8 272.1 0 169.2 0 75.1 58 28.9 150l90.4 70.1c21.5-64.5 81.8-112.4 152.8-112.4z' fill='%23ea4335'/%3E%3C/svg%3E");
You can also add some padding to make the logo smaller.
Result:
I'm working on a sidebar menu and want it to be partially collapsing, which means I have to show text on hover and hide the text when not hovering. I know another question has been asked about changing another element's property on hover, but I'm having trouble changing itself and another property.
General HTML layout:
.sidebar {
position: fixed;
top: 0;
left: 0;
background-color: #1d326b;
height: 100%;
width: 60px;
transition: 0.3s;
border-radius: 0 5px 5px 0;
font-family: 'Open Sans', sans-serif;
overflow: hidden;
}
.sidebar:hover > .text {
display: block; /*Supposed to display text*/
width: 150px; /*Expands the sidebar*/
}
<div class="sidebar">
<!--more containers...-->
<!--text below is deeply nested-->
<p class="text">Displayed Text</p>
</div>
Is there a pure css solution to this problem? Any help would be appreciated!
I think what you are trying to achieve is the animation for the width, if that's what you want just remove > .text from the hover selector:
.sidebar {
position: fixed;
top: 0;
left: 0;
background-color: #1d326b;
height: 100%;
width: 60px;
transition: 0.3s;
border-radius: 0 5px 5px 0;
font-family: 'Open Sans', sans-serif;
overflow: hidden;
color: #FFF;
}
.sidebar:hover {
display: block; /*Supposed to display text*/
width: 150px; /*Expands the sidebar*/
}
.text {
width: 150px;
display: none;
}
.sidebar:hover .text {
display: block;
}
<div class="sidebar">
<!--more containers...-->
<!--text below is deeply nested-->
<p class="text">Displayed Text</p>
</div>
Would doing something like this be what you're looking for?
.text{
display: none;
}
.sidebar:hover > .text {
display: block; /*Supposed to display text*/
width: 150px; /*Expands the sidebar*/
}
.sidebar .text {
visibility: hidden;
}
.text:hover {
display: block;
width: 150px;
}
I am trying to add a small triangle border in the panel corners of the panel headings.
I was able to add one using this example :
Featured filled corner css
I had to make minor changes to bring it to the left. But it only "kinda" works. It wont stick on changed resolutions though.
On changed resolutions it looks like this:
My Code for the Panel:
<div class="col-lg-6">
<div class="panel">
<div class="ribbon-wrapper-featured">
<div class="featured fa"></div>
</div>
<div class="panel-heading">
<h3 class="panel-title">Select Activity Stream</h3>
</div>
<div class="panel-body">
</div>
</div>
</div>
CSS:
<style>
/*corner ribbon*/
.ribbon-wrapper-featured {
position: absolute;
top: -50px;
right: 0px;
}
.featured.fa {
width: 100px;
height: 100px;
display: block;
position: absolute;
top: 50px;
right: 10px;
}
.featured.fa::before {
position: absolute;
right: 0%;
top: 0;
margin: .25em;
color: gold;
z-index: 2;
}
.featured::after {
content: '';
position: absolute;
/* width: 0; */
/* height: 0; */
/* top: 0; */
left: -38.4em;
border-width: 20px;
border-style: solid;
border-color: #03a9f4 transparent transparent #03a9f4;
/* outline: auto; */
z-index: 1;
}
.panel-title {
background-color: #232323;
text-transform: uppercase;
font-family: 'Open Sans Condensed', sans-serif;
color: #03a9f4;
font-size: 1.5em;
padding: 0 20px 0 60px;
}
</style>
Thanks!
I haven't been able to check against different resolutions, and there might be improvements possible on the triangle:
.wrapper {
background-color: #ddd;
height: 30px;
}
.panel-heading {
height: 0;
width: 0;
border-bottom: 30px solid transparent;
border-left: 30px solid blue;
float: left;
}
h3 {
line-height: 30px;
}
<div class="wrapper">
<div class="panel-heading"></div>
<h3 class="panel-title">Select Activity Stream</h3>
</div>
Source for making triangles: https://css-tricks.com/snippets/css/css-triangle/
I have been trying to solve this problem where I want the text "Sample" and then I want texts "bla1" and "bla2" to the right of text "Sample". I also want them to stay together when someone scales up and down their browser. So 100% and 200% zoom on any browser should not change the relative positioning of the texts. Any help is much appreciated! If javascript can solve the problem, I'll use javascript.
This photo explains what I want
See the code here: https://codepen.io/anon/pen/KZBzmY#anon-login
HTML:
<div id="tophead">
<a href="index.html">
<h1 class="webHeader">Sample</h1>
<h1 class="webHeader2">bla1</h1>
<h1 class="webHeader3">bla2</h1>
</a>
</div>
CSS:
#tophead {
margin: 0px;
padding: 0px;
border: 2px solid black;
position: absolute;
left: 40%;
font-family: Arial;
color: #00284d;
}
#tophead h1 {
margin: -2px;
}
#tophead a:link {
text-decoration: none;
color: #00284d;
}
.webHeader {
top: -50%;
left: -20%;
font-size: 180%;
position: relative;
}
.webHeader2 {
text-align: right;
font-size: 100%;
position: relative;
}
.webHeader3 {
text-align: right;
font-size: 90%;
position: relative;
}
I will suggest you to wrap the bla1 and bla2 text in <h2> and then use display: inline-block. No need to use position: absolute
Updated Codepen
#tophead {
margin: 0px;
padding: 0px;
font-family: Arial;
color: #00284d;
text-align: center;
}
#tophead h1 {
margin: 0;
display: inline-block;
vertical-align: middle;
}
#tophead a:link {
text-decoration: none;
color: #00284d;
display: inline-block;
border: 2px solid #000;
}
.webHeader2 {
display: inline-block;
margin: 0;
vertical-align: middle;
margin-left: 20px;
}
.webHeader2 span {
display: block;
}
.small {
font-size: 90%;
}
<div id="tophead">
<a href="index.html">
<h1 class="webHeader">Sample</h1>
<h2 class="webHeader2">
<span>bla1</span>
<span class="small">bla2</span>
</h2>
</a>
</div>
I'm trying to show a relevant submenu when the user hovers over an item in the main menu. The problem I am having is that I need to have a common parent for the hover selector to do its magic, but then that seems to screw up my styling. Any suggestions that forgo javascript/jquery would be appreciated as I use that as a crutch too much for things that I should probably be solving with css alone.
HTML
<div id="header">
<div id="header_headline">
Heading
</div>
<div id="menu">
<div id="menu_inset">
HOME
PROFILE<div class="sub_menu_arrow"></div>
PROJECTS<div class="sub_menu_arrow"></div>
NEWS
CONTACT
</div>
</div>
<div id="sub_menu">
<div class="sub_menu_inset" id="sub_menu_profile">
1
2
3
</div>
<div class="sub_menu_inset" id="sub_menu_projects">
1
2
3
4
</div>
</div>
</div>
CSS:
html, body {
width: 100%;
height: 100%;
border: 0;
padding: 0;
margin: 0;
font-family: 'Pathway Gothic One', sans-serif;
color: #212121;
}
a {
text-decoration: none;
color: #212121;
}
#header {
width: 100%;
}
#header_headline {
margin: 1em 1em 1em 1em;
font-size: 2em;
text-transform: uppercase;
}
#menu {
margin-top: 1em;
width: 100%;
text-align: center;
white-space: nowrap;
}
#menu_inset {
display: inline-block;
word-spacing: 5em;
}
.menu_item {
position: relative;
}
.menu_item:hover .sub_menu_arrow {
display: inline-block;
}
#menu_item_profile:hover ~ #sub_menu_profile {
display: inline-block;
}
#menu_item_people:hover ~ #sub_menu_people {
display: inline-block;
}
.sub_menu_arrow {
position: absolute;
display: none;
left: 0;
width: 100%;
bottom: -1.05em;
}
.sub_menu_arrow:after {
content: '';
margin: 0 auto;
border-width: 0 .5em .5em;
border-style: solid;
border-color: #CCCCCC transparent;
display: block;
width: 0;
}
#sub_menu {
margin-top: 1em;
background-color: #CCCCCC;
width: 100%;
text-align: center;
white-space: nowrap;
position: relative;
height: 2em;
}
.sub_menu_inset {
display: none;
top: 0.5em;
position: absolute;
left: 0;
width: 100%;
background-color: #CCCCCC;
word-spacing: 5em;
}
http://jsfiddle.net/u9v0mcvo/
You don't necessarily have to use <ul> and <li> elements. Although, you should avoid nesting <a> tags in <a> tags. I think this is what you might be trying to accomplish (hover over project):
http://jsfiddle.net/u9v0mcvo/1/
When making CSS-only drop downs, tooltips, or whatever, it helps to nest the initially hidden item in the element that is in charge of opening it.
Your menu's should be <ul> and the submenu should be <ul> inside the <li>s.
The sub ul should then be positioned absolutely and display: none. the top level <li>s should have a :hover that changes the inner <ul>s to disbplay block.