I have the following HTML structure.
<div class="fieldset">
<p>Normal Input<i class="icon-question tooltip-top" title="Text Goes Here"></i></p>
<div>
<span><i class="icon-cart"></i></span>
<input name="">
<span><i class="icon-cart"></i></span>
<i class="icon-question tooltip-top" title="Text Goes Here"></i>
</div>
</div>
I am trying to change the settings of the border-radius according to where the <input>
is positioned.
For example, if the <input>
has a <span>
just before it, its border-radius will be zero from top and bottom left.
I did this by using:
.fieldset > div > span + input {
border-radius: 0 4px 4px 0;
}
But, when there is a <span>
after the <input>
the input border radius should be zero from only the right top and bottom side. Obviously I can't use the +
selector for this one.
How can I achieve the desired results for when the <span>
is after the <input>
without using JavaScript and altering the HTML?
UPDATE:
Following the answers below and especially BoltClock♦ methods - it seems that the problem is nearly solved! The image below demonstrate all the different scenarios and the code used to apply them.
The only scenario that is not yet working, is when there is only one span before the input.
The current CSS is:
/*Fieldsets*/
.fieldset {
width: 100%;
display: table;
position: relative;
white-space: nowrap;
margin-bottom: 15px;
}
.fieldset:last-of-type {
margin-bottom: 0;
}
/*Fieldsets > Labels*/
.fieldset > p {
width: 1%;
margin-bottom: 3px;
}
/*Fieldsets > Input Container*/
.fieldset > div {
display: table-row;
position: relative;
}
.fieldset > div > * {
display: table-cell;
white-space: nowrap;
vertical-align: middle;
position: relative;
}
/*Fieldsets > Input + Icon*/
.fieldset > div > span {
border: 1px solid #B0C2CE;
padding: 5px 15px;
font-weight: bold;
width: 1%;
}
/*Fieldsets > Input + Icon Senarios*/
.fieldset > div > span:first-of-type {
border-right: 0;
border-radius: 4px 0 0 4px;
}
.fieldset > div > span:last-of-type {
border-left: 0;
border-radius: 0 4px 4px 0;
}
.fieldset > div > span:not(:only-of-type) + input {
border-radius: 0;
}
.fieldset > div > span + input,
.fieldset > div > span + textarea,
.fieldset > div > span + select,
.fieldset > div > span + .select-dropdown-single .select-dropdown-input,
.fieldset > div > span + .select-dropdown-multi .select-input {
border-radius: 0 4px 4px 0;
}
/*Fieldsets > Input + Help toolTip icon*/
.fieldset > div [class^="tooltip-"],
.fieldset > div [class*=" tooltip-"] {
text-align: center;
width: 30px;
}
The HTML:
<div class="fieldset">
<p>Normal Input</i></p>
<div>
<input name="">
</div>
</div>
<div class="fieldset">
<p>Normal Input</p>
<div>
<span><i class="icon-cart"></i></span>
<input name="">
</div>
</div>
<div class="fieldset">
<p>Normal Input</p>
<div>
<span><i class="icon-cart"></i></span>
<input name="">
<span><i class="icon-cart"></i></span>
</div>
</div>
<div class="fieldset">
<p>Normal Input</p>
<div>
<span><i class="icon-cart"></i></span>
<input name="">
<span><i class="icon-cart"></i></span>
<i class="icon-question tooltip-top" title="Text Goes Here"></i>
</div>
</div>