I'm practicing HTML and CSS at the moment and making webpage from a PSD-template, it's going good so far, but I'm facing the following problem:
The problem is that border disappears after being clicked on and :focus doesn't seem to handle the issue. I need the border to be present until i click on another element, can it be done with CSS? If yes (and that's probably the answer), then how? If it has a JS solution, I'd be glad if you help me with that.
.icons_and_text {
padding: 0 50px;
display: flex;
justify-content: space-between;
text-align: center;
font-size: 27px;
font-family: Segoe WPN;
color: #727171;
}
.icon {
padding: 26px 52px 52px 52px;
z-index: 2
}
.icon:hover {
cursor: pointer;
}
.icon:active {
border: 3px solid #dedede;
border-bottom: white;
}
.icon:focus {
border: 3px solid #dedede;
border-bottom: white;
}
<div class="icons_and_text">
<div class="icon">
<img src="Images/phone_img.png">
<p>Responsive</p>
<p>Websites</p>
</div>
</div>
div:focus Won't work by default, unless the div has a tabindex attribute.
The tabindex attribute specifies the tab order of an element (when the "tab" button is used for navigating).
From W3Schools.
It also enables focus functionality to the element, so if you want your div to have focusing abilities, just add this attribute: tabindex="0".
.icons_and_text {
padding: 0 50px;
display: flex;
justify-content: space-between;
text-align: center;
font-size: 27px;
font-family: Segoe WPN;
color: #727171;
}
.icon {
padding: 26px 52px 52px 52px;
z-index: 2
}
.icon:hover {
cursor: pointer;
}
.icon:active {
border: 3px solid #dedede;
border-bottom: white;
}
.icon:focus {
border: 3px solid #dedede;
border-bottom: white;
}
<div class="icons_and_text">
<div class="icon" tabindex="0">
<img src="https://via.placeholder.com/150">
<p>Responsive
<p>Websites</p>
</p>
</div>
</div>
It also adds an outline when focused, which you may disable using outline: 0;.
i made with jquery.
$(document).ready(function(){
$('.icons_and_text').click(function(){
$('.icon').toggleClass("new");
})
});
.icons_and_text{
padding: 0 50px;
display: flex;
justify-content: space-between;
text-align: center;
font-size: 27px;
font-family: Segoe WPN;
color: #727171;
}
.icon{
padding: 26px 52px 52px 52px;
z-index: 2
}
.icon:hover{
cursor: pointer;
}
.icon:active{
border: 3px solid #dedede;
border-bottom: white;
}
.icon:focus{
border: 3px solid #dedede;
border-bottom: white;
}
.new{
border: 3px solid #dedede;
border-bottom: white;
}
<div class="icons_and_text">
<div class="icon">
<img src="https://picsum.photos/500/200">
<p>Responsive <p>Websites</p></p>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
Related
I'm struggling with aligning text to div.
I currently have this:
But I want to achieve this (I have just edited a screenshot to show you what I mean):
My code looks as follows:
HTML
<div class="regionHeader">
<div class="regionArrow"></div>
<h2>Some long header that should be aligned to the left next to the div with arrow</h2>
</div>
CSS
.regionHeader {
border-bottom: 1px solid #ffd800;
cursor: pointer;
}
.regionArrow {
border-right: 4px solid #ffd800;
border-bottom: 4px solid #ffd800;
width: 13px;
height: 13px;
transform: rotate(45deg);
float: left;
margin-top: 11px;
margin-right: 13px;
margin-bottom: 0px;
margin-left: 3px;
}
h2 {
font-family: changa-regular;
font-size: 2em;
}
I have already played with display and floats, but it either doesn't work or I'm doing it incorrectly.
You can either simply use a padding-left on your heading:
.regionHeader {
border-bottom: 1px solid #ffd800;
cursor: pointer;
}
.regionArrow {
border-right: 4px solid #ffd800;
border-bottom: 4px solid #ffd800;
width: 12px;
height: 13px;
transform: rotate(45deg);
float: left;
margin-top: 11px 13px 0 3px;
}
h2 {
font-size: 2em;
padding-left: 1.2em; /* <- added */
}
<div class="regionHeader">
<div class="regionArrow"></div>
<h2>Some long header that should be aligned to the left next to the div with arrow</h2>
</div>
Or use a flexbox approach and remove the float.
.regionHeader {
border-bottom: 1px solid #ffd800;
cursor: pointer;
display: flex; /* <- added */
}
.regionArrow {
border-right: 4px solid #ffd800;
border-bottom: 4px solid #ffd800;
width: 16px;
height: 13px;
transform: rotate(45deg);
margin: 30px 15px;
}
h2 {
font-family: changa-regular;
font-size: 2em;
}
<div class="regionHeader">
<div class="regionArrow"></div>
<h2>Some long header that should be aligned to the left next to the div with arrow</h2>
</div>
Browser support for flexbox is pretty good. Don't forget to add proper vendor prefixes.
I'm developing drop down list in polymer. Currently I have problem with CSS.
Here you can find example:
jsfiddle example
<div style="width:200px" class="button initial gray">
<div style="padding-left:12px;padding-right:12px;">
<div class="button-value truncated" style="width:inherit;">
Select value very long label with dots at the end
</div>
<div class="arrow">▼</div>
</div>
</div>
I need to create the following drop down list, but I have problem with arrow visible on the right of button.
Question is, how to achieve this:
gif example
I will be very grateful for your help !!!!
You need to use this
text-overflow: ellipsis;
overflow: hidden;
then you will see the three dots after your list item, but also you need to add width for your span
width: 100px
Code example
<div style="width:200px" class="button initial gray">
<div style="padding-left:12px;padding-right:12px;">
<div class="button-value truncated" style="width:158px; display: inline-block">
Select value very long label with dots at the end
</div>
<div style="display: inline-block;margin-top: 12px;vertical-align: top;"class="arrow">▼</div>
</div>
</div>
div.button.orange {
border: 1px solid #FF6200;
background: inherit;
background-color: #FF6200;
border-radius: 5px;
box-shadow: none;
font-family: 'ING Me';
font-weight: 400;
font-style: normal;
font-size: 12px;
color: white;
cursor: pointer;
height: 36px;
box-sizing: border-box;
box-shadow: 1px 1px 5px lightgray;
}
div.button.gray {
border: 1px solid #767676;
background: inherit;
background-color: white;
border-radius: 5px;
box-shadow: none;
font-family: 'ING Me';
font-weight: 400;
font-style: normal;
font-size: 12px;
color: #FF6200;
cursor: pointer;
height: 36px;
box-sizing: border-box;
box-shadow: 1px 1px 5px lightgray;
position:relative;
}
div.button.gray.initial {
color: #767676;
}
div.button.active {
border-radius: 4px 4px 0px 0px;
border: 1px solid #FF6200;
}
div.button-value {
text-align: center;
line-height: 36px;
width: inherit;
}
ul.options>li {
padding-left: 12px;
padding-right: 12px;
line-height: 36px;
}
.truncated {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
ul.options {
color: black;
list-style-image: none;
list-style: none;
list-style-type: none;
border-radius: 0px 0px 4px 4px;
box-sizing: border-box;
position: absolute;
width: auto;
margin: -1px;
padding: 0;
list-style: none;
border: 1px solid #FF6200;
border-top: none;
background-color: white;
box-shadow: 1px 1px 5px lightgray;
}
ul.options>ul {
list-style-type: none;
padding: 0px;
margin: 0px;
}
ul.options>li:hover {
color: white;
background-color: #FF6200;
text-decoration: underline;
}
.arrow{
position:absolute;
right:4px;
top:0;
line-height:36px;
}
<div style="width:200px" class="button initial gray">
<div style="padding-left:12px;padding-right:18px;">
<div class="button-value truncated" style="width:inherit;">
Select value very long label with dots at the end▼
</div>
<div class="arrow">▼</div>
</div>
</div>
I am making a modal view, using bootstrap framework, as shown in the figure , these are two buttons , I want hover effect when , mouse points on, using CSS but it isn't working,
#yesbut,#nobut {
width: auto;
height: auto;
display: inline-block;
padding: 10px 35px;
text-align: center;
background: #2e6c96;
color: #fff;
font-size: 16px;
text-decoration: none;
border: 1px solid #2e6c96;
outline: none;
text-transform: uppercase;
}
#yesbut :hover{
background: #fff;
border: 1px solid #fff;
}
#nobut :hover{
background: #fff;
color: #2e6c96;
border: 1px solid #fff;
}
<div id="yesbut" >YES</div>
<div id="nobut">NO</div>
enter image description here
#yesbut :hover{ /*Remove the space*/
background: #fff;
border: 1px solid #fff;
}
You got error in selectors corrected is:
#yesbut:hover{
background: #fff;
border: 1px solid #fff;
}
without space between #yesbut/#yesno and :hover.
Space mean you are targeting elements inside that particular element e.g. children of #yesbut.
You need to remove the spaces. If you put a space before the pseudo-class it means that you want to select a child of e.g. #yesbut instead of the element itself.
#yesbut,#nobut {
width: auto;
height: auto;
display: inline-block;
padding: 10px 35px;
text-align: center;
background: #2e6c96;
color: #fff;
font-size: 16px;
text-decoration: none;
border: 1px solid #2e6c96;
outline: none;
text-transform: uppercase;
}
#yesbut:hover{
background: #fff;
border: 1px solid #fff;
}
#nobut:hover{
background: #fff;
color: #2e6c96;
border: 1px solid #fff;
}
<div id="yesbut" >YES</div>
<div id="nobut">NO</div>
I've been having trouble all day with these buttons. First, both buttons were on top of each other looking like this, http://i.imgur.com/wVmntpQ.jpg and now after posting here asking what to do, it looks like this now, http://imgur.com/OmXDQct
I was told to change in my css from this :
CSS:
button {
float:left;
margin-top:250px;
color:white;
display: block;
margin: 30px;
padding: 7px 35px;
font: 300 150% langdon;
background: transparent;
border: 3px solid white;
cursor: pointer;
}
button:hover {
background: black;
border: 1px solid black;
}
button:active {
background: #2e2e2e;
border: 1px solid black;
color: white;
}
I guess you just need to add position:relative to the div which contains the buttons, so make it like this:
HTML
<div style="position: relative;">
GO ROAM</br>
START HERE.
<button>SIGN UP</button>
<button>LOG IN</button>
</div>
Hope this will help you ...
Ok, here is the working code on jsfiddle. I have removed the absolute path from the buttons and added display: inline-block; so now they're one next to the other. I have also added the top: 250px declaration in the wrapper.
button {
color:white;
display: inline-block;
margin: 30px;
padding: 7px 35px;
font: 300 150% langdon;
background: transparent;
border: 3px solid white;
cursor: pointer;
}
button:hover {
background: black;
border: 1px solid black;
}
button:active {
background: #2e2e2e;
border: 1px solid black;
color: white;
}
I'm building a fairly interestingly shaped navigation for a site at the moment. The shape each menu item needs to be is illustrated below:
The final nav will look like an extended version of this:
I thought it would be an interesting experiment to do these shapes in CSS. The CSS and HTML for one of the arrow shapes is here:
.arrowEndOn {
font-size: 10px; line-height: 0%; width: 0px;
border-top: 11px solid #FFFFFF;
border-bottom: 11px solid #FFFFFF;
border-left: 5px solid transparent;
border-right: 5px solid #FFFFFF;
float: left;
cursor: pointer;
}
.arrowBulkOn {
height: 20px;
background: #FFFFFF;
padding: 2px 5px 0px 0px;
float: left;
color: #000000;
line-height: 14pt;
cursor: pointer;
}
.arrowStartOn {
font-size: 0px; line-height: 0%; width: 0px;
border-top: 11px solid transparent;
border-bottom: 11px solid transparent;
border-left: 5px solid #FFFFFF;
border-right: 0px solid transparent;
float: left;
cursor: pointer;
}
<div id="nav" class="navArrow" style="position: relative;">
<div class="arrowEndOn" id="nav"> </div>
<div class="arrowBulkOn" id="nav">NAV</div>
<div class="arrowStartOn" id="nav"> </div>
</div>
Each nav item has a negative offset applied to it (which I've left out of the demo) as it's rendered to get them all flush with each other.
I'm handling the rollovers and on states with Javascript.
My problem is getting the nav to stretch all the way across the width of the page. At the moment I have to set the nav container to a much larger width to accommodate it all.
I've tried setting overflow to hidden but the last item is dropping down a level rather than carrying on and just having the end cut off.
I've set an example up here - http://jsfiddle.net/spacebeers/S7hzu/1/
The red border has overflow: hidden; and the blue doesn't.]
My question is: How can I get the boxes to all float in a line that fills the width of the containing div without them dropping down a level.
Thanks
Add a negative margin to each arrow:
.navArrow {
float: left;
margin-left: -8px;
}
Demo: http://jsfiddle.net/S7hzu/2/
Flexbox
You can use this example
https://codepen.io/WBear/pen/pPYrwo
it works on new browsers, to support old ones some changes needed.
HTML:
<div class="content">
<div class="as1">
NAV
</div>
<div class="as2">
NAV
</div>
<div class="as3">
NAV
</div>
</div>
CSS:
.content {
margin-top: 10px;
width: 100%;
display: inline-flex;
}
.as1, .as2, .as3 {
height: 70px;
min-width: 8%;
max-width: 100%;
background-color: black;
position: relative;
display: inline-flex;
text-align: center;
flex-wrap: wrap;
flex-grow: 1;
}
.as1 a, .as2 a, .as3 a {
text-decoration: none;
display: inline-flex;
color: white;
margin: auto;
font-size: 14pt;
}
.as1:after {
content: "";
position: absolute;
right: 4px;
border-top: 35px solid transparent;
border-left: 25px solid black;
border-bottom: 35px solid transparent;
z-index: 2;
}
.as2 {
background-color: grey;
margin-left: -29px;
}
.as2:after {
content: "";
position: absolute;
right: 4px;
border-top: 35px solid transparent;
border-left: 25px solid grey;
border-bottom: 35px solid transparent;
z-index: 3;
}
.as3 {
background-color: #A9A9A9;
margin-left: -29px;
}