首页 \ 问答 \ CSS在嵌套div上出现border-radius错误(CSS wrong appearance of border-radius on a nested div)

CSS在嵌套div上出现border-radius错误(CSS wrong appearance of border-radius on a nested div)

使用以下HTML我需要:

  • 确保target div (粉红色)的边框与wrapper-target红色边框div相邻。

  • 必须适用于border-radius的任何值。

考虑到:

  • 我正在使用box-sizing: border-box; 但也可以重置为默认值。
  • 我无法更改target div的border-radius属性。

*,
*:after,
*:before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
<div id="wrapper-target" style="position:absolute;top:100px;left:100px;width:250px;height:250px;border-radius:50px;border:25px solid red;">
  <div id="target" style="position:relative;width:100%;height:100%;background-color:plum;border-radius:inherit">
  </div>
</div>

笔记:

  • 我不需要在这个具体的例子中创建一个圆圈:)。

Using the following HTML I need to:

  • Make sure that the border of target div (pink) is adjacent of the wrapper-target red border div.

  • Must work on any value of border-radius.

Considering that:

  • I am using box-sizing: border-box; but can be also reset to a default value.
  • I cannot change the border-radius property of the target div.

*,
*:after,
*:before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
<div id="wrapper-target" style="position:absolute;top:100px;left:100px;width:250px;height:250px;border-radius:50px;border:25px solid red;">
  <div id="target" style="position:relative;width:100%;height:100%;background-color:plum;border-radius:inherit">
  </div>
</div>

NOTES:

  • I do not need to make a circle in this specific example :).

原文:https://stackoverflow.com/questions/35984449
更新时间:2023-12-14 12:12

最满意答案

我也会在这个要求上推荐Fragment ,但是由于你的应用程序已经实现,你可以采用这种方法。

 all the activities that exists before it in the stack should be finished.

Android不提供任何标记来清除以下所有Activities如使用clearTop清除热门Activities 。 这将是简单的,如果我们有clearBottom :)

好。 如果您Android API version from 16定位Android API version from 16 ,则此方法将以优化的方式提供帮助。 对于其他较低版本,您需要分别完成每个Activity

创建一个将所有Activity实例添加到HashMapBaseActivity (类似于将Fragments to back Stack添加Fragments to back Stack )。 但这里只是记住堆栈中的Activities 。 您也可以使用ActivityManager.RunningTaskInfo检查堆栈中的ActivityManager.RunningTaskInfo但我不想让它更复杂。

声明一个静态变量。 我更喜欢在我的Application class做。

 public class MyApp extends Application {
    public static HashMap<String , CommonActivity > mBackStackActivities
                   = new HashMap<String, CommonActivity>();
  }

现在,当一个Activity createdActivity created将其实例添加到HashMap

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MyApp.mBackStackActivities.put(getComponentName().getClassName(), this);
}

并且,在Activity destroy时将其Activity destroy

@Override
protected void onDestroy(){
    MyApp.mBackStackActivities.remove(getComponentName().getClassName());
    super.onDestroy();
}

现在, Override base Activity classstartActivity方法,并在Activity开始时check if the HashMap中check if the exists in Activity . If exists . If exists all the below using finishAffinity完成all the below Activity。

 @Override
public void startActivity(Intent intent) {
    if(MyApp.mBackStackActivities
        .containsKey(intent.getComponent().getClassName())){
        if(android.os.Build.VERSION.SDK_INT >= 16) {
            Activity activity = MyApp.mBackStackActivities.get(intent.getComponent().getClassName());
            // finish the activity as well as all the below Activities.
            activity.finishAffinity(); // supported from API 16
        }else {
            // loop through all the below activity and finish it
        }
    }
    super.startActivity(intent);
}

最后,如果您需要为清单中的所需Activities设置android:taskAffinity ,则默认情况下所有Activities都将具有相同的亲和力名称(包名称)。 如果您希望涵盖所有Activities ,则可以离开此项。

    <activity
        android:name="com.example.app.activities.MainActivity"
        android:label="@string/title_activity_common"
        android:taskAffinity="@string/task_affinity_name">
    </activity>

在字符串xml中

<string name="task_affinity_name">com.example.app.affinity</string>

注意:如上所述的较低版本,您需要单独完成每个Activity

在这里找到完整的源https://gist.github.com/androidbensin/7d9261fd148c15575dd1


I would also recommend Fragment on this requirement , but since your application is already implemented, you can go with this approach.

 all the activities that exists before it in the stack should be finished.

Android doesn't provide any flag to clear all the below Activities like clearing top Activities using clearTop. It would be simple if we had clearBottom :)

Ok. If your targeting Android API version from 16, this approach will help in an optimized way. For the other lower version you need to finish each Activity individually.

Create a BaseActivity which will add all the Activity Instance into a HashMap(similar to adding Fragments to back Stack). But here this is to just remember the Activities in stack. You can also check the Activities in stack using ActivityManager.RunningTaskInfo but I don't want to make it more complex.

Declare a static variable. I prefer to do in my Application class.

 public class MyApp extends Application {
    public static HashMap<String , CommonActivity > mBackStackActivities
                   = new HashMap<String, CommonActivity>();
  }

Now, when an Activity created add its instance to the HashMap

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MyApp.mBackStackActivities.put(getComponentName().getClassName(), this);
}

And,remove it when the Activity destroy

@Override
protected void onDestroy(){
    MyApp.mBackStackActivities.remove(getComponentName().getClassName());
    super.onDestroy();
}

Now, Override the startActivity method in base Activity class and when an Activity is startedcheck if theActivityexists inHashMap. If existsfinishall the belowActivityusingfinishAffinity`.

 @Override
public void startActivity(Intent intent) {
    if(MyApp.mBackStackActivities
        .containsKey(intent.getComponent().getClassName())){
        if(android.os.Build.VERSION.SDK_INT >= 16) {
            Activity activity = MyApp.mBackStackActivities.get(intent.getComponent().getClassName());
            // finish the activity as well as all the below Activities.
            activity.finishAffinity(); // supported from API 16
        }else {
            // loop through all the below activity and finish it
        }
    }
    super.startActivity(intent);
}

Finally, If you need to set android:taskAffinity in manifest for the required Activities, by default all the Activities will have same Affinity name (the package name). You can leave this if you want all your Activities to be covered.

    <activity
        android:name="com.example.app.activities.MainActivity"
        android:label="@string/title_activity_common"
        android:taskAffinity="@string/task_affinity_name">
    </activity>

In string xml

<string name="task_affinity_name">com.example.app.affinity</string>

Note : As said above for lower version , you need to finish each Activity Individually`

Find the complete source here https://gist.github.com/androidbensin/7d9261fd148c15575dd1

相关问答

更多

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)